Reputation: 392
I have the following class structure:
class A
def process(processor)
processor.process_x
end
end
class Processor
def process_x
end
end
and the following test:
context "when process is called" do
object_a = A.new
processor = Processor.new
it "calls processor.process_x" do
object_a.process(processor)
expect(processor).to receive(:process_x)
end
end
but the test keeps failing. I even put a byebug
and saw the processor's process_x
method being called
how can I troubleshoot this?
Upvotes: 2
Views: 1651
Reputation: 392
I see my problem, after reading this I realized I should add the expectation first, then invoke the method:
context "when process is called" do
object_a = A.new
processor = Processor.new
it "calls processor.process_x" do
expect(processor).to receive(:process_x) *** HERE
object_a.process(processor) *** HERE
end
end
Upvotes: 11