I have a test case like this:
describe WorkCardsController do
it "something" do
work_card = instance_double(WorkCard, {:started?=>true} )
#some more code
end
end
When I run RSpec, I get an error:
undefined method 'instance_double' for #<Rspec::Core::ExampleGroup::Nested_1::Nested_8::Nested_3:0x007f0788b98778>
According to http://rubydoc.info/github/rspec/rspec-mocks/RSpec/Mocks/ExampleMethods this method exists. So I tried to access it directly by:
describe WorkCardsController do
it "something" do
work_card = RSpec::Mocks::ExampleMethods::instance_double(WorkCard, {:started?=>true} )
#some more code
end
end
And then I got a very surprising error:
undefined method 'instance_double' for Rspec::Mocks::ExampleMEthods:Module
which is contrary to the documentation I linked above.
What am I missing?
From the documentation you pointed to:
Mix this in to your test context (such as a test framework base class) to use rspec-mocks with your test framework.
Try to include
it into your code:
include RSpec::Mocks::ExampleMethods
Your direct approach failed, because calling
RSpec::Mocks::ExampleMethods::instance_double(...)
expects that the method was declared as a class method:
def self.instance_double(...)
but it has been declared as an instance method :
def instance_double(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With