Simultaneous changes in Rails 2.3.3 and Mocha >=0.9.6 have caused some headaches in test::unit (or shoulda) tests. In my case I saw anomalies such as expectations persisting across tests. You put expects(:foo).never in test A and get “unsatisfied expectation” failure in test B where you happen to call :foo. This is due to unfortunate dependency on load order which could cause runner logic to be erroneously overridden. Here’s the steps you need to take to tidy up this setup to make sure it works correctly.
Update mocha to >= 0.9.7
Install test-unit gem
Don’t load mocha yourself
If you had anything like this line in your test environment, REMOVE IT.
config.gem "mocha"
Ensure correct load order
If using Shoulda, make sure your test.rb environment loads test-unit before shoulda.
config.gem "thoughtbot-shoulda", :lib => "shoulda", :source => "http://gems.github.com", :version => ">=2.10.1"
This should hopefully fix mocha issues with rails 2.3.3.
For more explanation check out this message on mocha’s mail list and this lighthouse ticket.
Hi, Maxim. It appears that simply ensuring that mocha comes after shoulda in test.rb is sufficient for me. I was seeing similar “bleed through” of expectations between test cases and this fixed the problem for me, without having to install a new version of Test::Unit. I am also running with Rails 2.3.4, though.
Oh, that’s good. I was kind of in the dark so just decided to post all my steps. In the end I would still advise not to require mocha at all, Rails already does that for you afaik.