Jeff Kreeftmeijer

Testing your Machinist blueprints

2010-05-10

At 80beans we had an old Rails project still on fixtures, so we decided to start switching it over to blueprints using Machinist. Nothing extreme, except that the project had over 60 models and a couple of fixtures were broken, fixed, broken and fixed again.

As I started writing blueprints, I realized that it would be nice to have some specs to make sure the bare minimum (Model.make without any arguments) kept working at all times and we didn’t have to dive in to realize that the problem was one of the new blueprints, not the application.

So I whipped up — and Gistedmachinist_spec.rb that goes through your app/models directory, runs .make for everything it finds and expects it to work. Simple.

Also, our application used a mailer — in the models directory — which, of course, didn’t need any blueprints. I’ve excluded it from the spec by extracting it from the array on line 5.

Want it? Just put this into spec/machinist_spec.rb. If you have anything to add or improve, please fork.