Rails and Mocha problem

I recently set up an app on a new (old) computer, and I’m having
problems running my tests. For some reason, mocha is not behaving at
all. The first thing that happened was that all calls to stub
(Mocha::API#stub) failed with a

“undefined method `stub’ for #AnyObjectTest:0xb68ae420”.

After some investigation in irb and script/console I tried to “import
Mocha::API” in my test/test_helper.rb. That solved my initial problem,
but brought on

“/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:426:in
`load_missing_constant’: Expected
/usr/lib/ruby/gems/1.8/gems/mocha-0.9.7/lib/mocha/integration/test_unit.rb
to define Mocha::Integration::TestUnit (LoadError)”

So, obviously something’s amiss. I’m on Ubuntu. I installed Mocha
through RubyGems 1.3.5 (manually installed, not the apt one).

Any ideas on how to fix this?

2009/9/6 Christian J. [email protected]

but brought on

“/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:426:in
`load_missing_constant’: Expected
/usr/lib/ruby/gems/1.8/gems/mocha-0.9.7/lib/mocha/integration/test_unit.rb
to define Mocha::Integration::TestUnit (LoadError)”

So, obviously something’s amiss. I’m on Ubuntu. I installed Mocha
through RubyGems 1.3.5 (manually installed, not the apt one).

Any ideas on how to fix this?

Hi Christian,

I suspect this is a load order problem. After the release of 0.9.6
[1], Mocha no longer loads Test::Unit itself. Instead Mocha now needs
you to load Test::Unit before you load Mocha. Exactly how you solve
this depends on how you are currently loading Test::Unit and Mocha,
but usually it may simply be a matter of moving a require ‘mocha’
statement below a require ‘test/unit’ statement.

If you need any more help, please post to the Mocha mailing list [2].

Thanks, James.

[1] Mocha Release 0.9.6 - James Mead
[2] http://groups.google.com/group/mocha-developer

Thanks alot! TestUnit was required before Mocha, but somehow I managed
to require Autotest before that again, and Autotest requires TestUnit as
well. So, everything works now, thanks :slight_smile: