I’m looking to test that a class method calls a specific instance method. Is there any way to do this? This is the best I’ve got, but it fails.
describe '#foo' do
let(:job) { create :job }
it 'calls job.bar' do
job.should_receive(:bar)
Job.foo
end
end
I need to be sure that the right instance of job is called, not just any instance. I appreciate any help.
You can use stubs on the method by which
.foogets the instance.For instance:
What this does is ensures that the instance that you expect to have methods called on is the one that actually gets used by
.foo.You can add expectations or argument matchers to this, so:
Job.should_receive(:find).with(job.id).and_return(job)