How can I stub a method within a module:
module SomeModule
def method_one
# do stuff
something = method_two(some_arg)
# so more stuff
end
def method_two(arg)
# do stuff
end
end
I can test method_two
in isolation fine.
I would like to test method_one
in isolation too by stubbing the return value of method_two
:
shared_examples_for SomeModule do
it 'does something exciting' do
# neither of the below work
# SomeModule.should_receive(:method_two).and_return('MANUAL')
# SomeModule.stub(:method_two).and_return('MANUAL')
# expect(described_class.new.method_one).to eq(some_value)
end
end
describe SomeController do
include_examples SomeModule
end
The specs in SomeModule
that are included in SomeController
fail because method_two
throws an exception (it tries to do a db lookup that has not been seeded).
How can I stub method_two
when it is called within method_one
?