ruby! rails! kids! oh my! … and other fun from terry heath
RSS icon Email icon Home icon
  • Machinist + RSpec matcher

    Posted on March 20th, 2010 terry 14 comments

    Most of the time when I’m putting the skeleton of my Rails app together, I end up with a test like this:

    After discovering Remarkable this week, I decided it was worth putting that into a macro matcher*. So now you can just say it { should work_with_machinist }. Here’s the code. Not tested. Enjoy:

    * Thanks @David for pointing out it’s a matcher, not a macro

    ** Clarification: From reading the comments, I realize that this doesn’t seem useful unless you’ve used machinist. Machinist’s make method works on an ActiveRecord model, and works something like this: calls .new() with the fake params, calls save!, and then calls reload. If any of those fail, it raises an exception, so this effectively tests your blueprints for validation and callback sanity.