If you use Mocha and RSpec then read this

25 Nov 2008

I like RSpec, but I’m not a huge fan of it’s built in mocking framework. So, when I have the choice, I swap it out for Mocha. However, I really miss mock_model. If you haven’t used it, mock_model is an RSpec method where you pass in an ActiveRecord object and it stubs out a whole bunch AR magic so you don’t have to. This is crazy useful when testing controllers because when you controller has a line like this:
redirect_to(@model)

I don’t want to dig through a ton of Rails code to figure out what I need to stub on this model, I just want it to work. But I just found out that Mislav Marohnić has written a plugin that implements mock_model for Mocha – so now I can get the best of both worlds. You can find it here:
http://github.com/mislav/rspec-rails-mocha

Thanks Mislav.