Rails 2.3.3 + mocha = confusion
I just updated a project to Rails 2.3.3 for the cool new “touch” feature, and saw here that I needed to update to Mocha 0.9.7. I did that, but found that my tests were failing – I got lots of NoMethodError: undefined method `stub’ for #<SomeTest:0×7f2c1d921f80> errors.
In my project, I’d declared my dependence on the Mocha gem in my config/environment.rb file, so that “sudo rake gems:install” would load everything required for development in one shot (which is why the dependency isn’t in config/environments/test.rb). I’ll cut to the chase: I needed to add an extra option to that declaration:
config.gem 'mocha', :version => '=0.9.7', :lib => false
The problem is that mocha configures itself based on what test library you’ve already included when you require Mocha. Unfortunately, the config.gem declaration causes mocha to be loaded before Rails has loaded Test::Unit, so Mocha doesn’t configure itself… so no “stub.” Setting :lib to false postpones loading Mocha until you actually do it in your test/test_helper.rb (or wherever).
[...] Rails 2.3.3 + Mocha = Confusion [...]
Pingback by Mocha NoMethodError / Load order since version 0.9.6 — Friday, September 18, 2009 @ 3:35 am
Thank you thank you so much!
I just spent two hours searching for a solution.
Now i found that blog post. Thanks
Florian
Comment by Florian Vallen — Wednesday, May 5, 2010 @ 6:15 am