New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with RR: undefined method `to_sym' for ActiveRecord::Base:Class #59

Closed
jocranford opened this Issue Feb 26, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@jocranford

jocranford commented Feb 26, 2014

I've been using RR for mocks and stubs with RSpec 2.99. When I upgraded to 3.0.0.beta2 I got the following error in the tests:
Failure/Error: stub(ActiveRecord::Base).transaction
NoMethodError:
undefined method `to_sym' for ActiveRecord::Base:Class

The code we were using to stub with RR looked like this:
stub(object).method

I've fixed the code to use RSpec mocks now but raising the issue in case others want to use RR. I was using the latest version.

@myronmarston

This comment has been minimized.

Show comment
Hide comment
@myronmarston

myronmarston Feb 26, 2014

Member

Hmm, can you put together a bit of code that demonstrates the problem? It's not clear to my why that would happen and I'm not an RR user.

Member

myronmarston commented Feb 26, 2014

Hmm, can you put together a bit of code that demonstrates the problem? It's not clear to my why that would happen and I'm not an RR user.

@jocranford

This comment has been minimized.

Show comment
Hide comment
@jocranford

jocranford Feb 26, 2014

Here you go: https://gist.github.com/jocranford/9225540

This runs OK with rspec 2.99.beta1 but not with rspec 3.0.0.beta2.

jocranford commented Feb 26, 2014

Here you go: https://gist.github.com/jocranford/9225540

This runs OK with rspec 2.99.beta1 but not with rspec 3.0.0.beta2.

@myronmarston

This comment has been minimized.

Show comment
Hide comment
@myronmarston

myronmarston Feb 26, 2014

Member

Thanks for the extremely clear code example :).

To use rr with rspec, you need to configure it:

RSpec.configure do |rspec|
  rspec.mock_with :rr
end

With that in place, there's no need to require 'rr' (rspec will do that for you when you tell it you want to use rr). This config is necessary because if you don't configure rspec and tell it you are using rr, it will try to load rspec-mocks (since that's the default mocking library). rspec-mocks and rr both provide a stub method and you'll have the kind of problem you're seeing. I'm actually extremely surprised it ever worked for you without the mock_with :rr configuration!

Member

myronmarston commented Feb 26, 2014

Thanks for the extremely clear code example :).

To use rr with rspec, you need to configure it:

RSpec.configure do |rspec|
  rspec.mock_with :rr
end

With that in place, there's no need to require 'rr' (rspec will do that for you when you tell it you want to use rr). This config is necessary because if you don't configure rspec and tell it you are using rr, it will try to load rspec-mocks (since that's the default mocking library). rspec-mocks and rr both provide a stub method and you'll have the kind of problem you're seeing. I'm actually extremely surprised it ever worked for you without the mock_with :rr configuration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment