undefined method `any_instance` when running a controller spec generated from scaffold #7

sivabudh opened this Issue Jul 4, 2011 · 1 comment


None yet
1 participant

sivabudh commented Jul 4, 2011

Firstly, I'm sorry if this turns out not to really be an issue with rspec-rails, but I just want to confirm that it really is not an issue.

Here's my what I use in my project:
mock: rr 1.0.2 <-- please note I use RR and not the default rspec mock
rspec: 2.6.0
rspec-rails: 2.6.1
Rails: rails 3.1 rc4
fixture: fabrication 0.9.5

In spec_helper.rb, I have:
config.mock_with :rr

In application.rb, I have:
g.test_framework :rspec, :fixture => true, :view_specs => false
g.fixture_replacement :fabrication

I then generate scaffold by executing:

rails generate scaffold something

And when I try to rspec the controller spec file, I would get:

undefined method any_instance on the Something:Class

Is this expected?

sivabudh commented Jul 4, 2011

Okay, it really is my lack of understanding of how to use RSpec with RR.

Simply put, when one uses a mocking library that isn't RSpec, you will have to modify the tests accordingly.

Specifically, when you use RR, everytime you see a line like:
The equivalent in RR would be:
mock.instance_of(YourClass).save {false}

And if you see something like:
YourClass.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
The equivalent in RR would be:
mock.instance_of(YourClass).update_attributes({'these' => 'params'})

Of course, if you use something else besides RR, you will have to adjust accordingly, which is what I've just learned. ;-)

@sivabudh sivabudh closed this Jul 4, 2011

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