Undefined method `mock'

68 views
Skip to first unread message

Sonny Parlin

unread,
Nov 20, 2009, 2:47:47 PM11/20/09
to mocha-developer
I'm getting an error when using shoulda and mocha together with rails
2.3.4.

My test.rb environment file has these lines:
config.gem 'test-unit', :lib => 'test/unit'
config.gem 'thoughtbot-shoulda', :lib => 'shoulda'

The error:
/usr/bin/ruby1.8 -I"lib:test" "/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/
lib/rake/rake_test_loader.rb" "test/functional/
tweets_controller_test.rb"
/usr/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/
context.rb:398:in `send': undefined method `mock' for
TweetsControllerTest:Class (NoMethodError)

Mocha is mocha-0.9.8
Shoulda is thoughtbot-shoulda-2.10.2

I saw this thread:
http://groups.google.com/group/mocha-developer/browse_thread/thread/7f3e98aa73ed425a

Which 1. doesn't appear to be active, and 2. the solutions proposed
didn't solve the issue for me.

Any help would be greatly appreciated.

-Sonny

Sonny Parlin

unread,
Nov 20, 2009, 10:56:12 PM11/20/09
to mocha-developer
I think this is more of a problem with shoulda, it doesn't seem to
matter what I use (flexmock, mocha, etc...) I always get an undefined
method error.

On Nov 20, 2:47 pm, Sonny Parlin <tpar...@gmail.com> wrote:
> I'm getting an error when using shoulda and mocha together with rails
> 2.3.4.
>
> My test.rb environment file has these lines:
> config.gem 'test-unit', :lib => 'test/unit'
> config.gem 'thoughtbot-shoulda', :lib => 'shoulda'
>
> The error:
> /usr/bin/ruby1.8 -I"lib:test" "/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/
> lib/rake/rake_test_loader.rb" "test/functional/
> tweets_controller_test.rb"
> /usr/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.2/lib/shoulda/
> context.rb:398:in `send': undefined method `mock' for
> TweetsControllerTest:Class (NoMethodError)
>
> Mocha is mocha-0.9.8
> Shoulda is thoughtbot-shoulda-2.10.2
>
> I saw this thread:http://groups.google.com/group/mocha-developer/browse_thread/thread/7...

James Mead

unread,
Nov 23, 2009, 11:03:21 AM11/23/09
to mocha-d...@googlegroups.com
Are you still seeing the problem?

It does sound like a load order problem.

I don't know whether any of this [1] might help...?

The key is that Mocha must be after Test::Unit or MiniTest so it can
monkey-patch them.

Let us know if you need more help.

Cheers, James.

[1] http://blog.floehopper.org/articles/2009/09/18/mocha-nomethoderror-load-order-since-version-0-9-6


2009/11/21 Sonny Parlin <tpa...@gmail.com>:
> --
>
> You received this message because you are subscribed to the Google Groups "mocha-developer" group.
> To post to this group, send email to mocha-d...@googlegroups.com.
> To unsubscribe from this group, send email to mocha-develop...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mocha-developer?hl=.
>
>
>

Sonny Parlin

unread,
Nov 23, 2009, 11:06:25 AM11/23/09
to mocha-developer
I figured the issue out, it was my fault. I was trying to use the mock
and stub methods outside the setup block in shoulda.

On Nov 23, 11:03 am, James Mead <jamesmea...@gmail.com> wrote:
> Are you still seeing the problem?
>
> It does sound like a load order problem.
>
> I don't know whether any of this [1] might help...?
>
> The key is that Mocha must be after Test::Unit or MiniTest so it can
> monkey-patch them.
>
> Let us know if you need more help.
>
> Cheers, James.
>
> [1]http://blog.floehopper.org/articles/2009/09/18/mocha-nomethoderror-lo...
>
> 2009/11/21 Sonny Parlin <tpar...@gmail.com>:

James Mead

unread,
Nov 23, 2009, 11:07:25 AM11/23/09
to mocha-d...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages