Give a better error message on received expectations with args
Created by: penelopezone
Related #253 (closed)
So I've built something that seems a bit alright. I'm not sure this totally makes sense on things like, I'd love some feedback on that.
expected: 0 times with any arguments
received: 1 time
An example spec:
describe "bees" do
it "should things" do
dbl = double
dbl.should_not_receive(:foo).with(:bar)
dbl.foo(:bar)
dbl
end
it "should also things" do
dbl = double.as_null_object
dbl.foo(:bar)
expect(dbl).not_to have_received(:foo).with(:bar)
end
end
and execution result:
FF
Failures:
1) bees should things
Failure/Error: dbl.foo(:bar)
(Double).foo(:bar)
expected: 0 times with arguments: (:bar)
received: 1 time with arguments: (:bar)
# ./253_spec.rb:5:in `block (2 levels) in <top (required)>'
2) bees should also things
Failure/Error: expect(dbl).not_to have_received(:foo).with(:bar)
(Double).foo(:bar)
expected: 0 times with arguments: (:bar)
received: 1 time with arguments: (:bar)
# ./253_spec.rb:12:in `block (2 levels) in <top (required)>'
Finished in 0.00085 seconds
2 examples, 2 failures
Failed examples:
rspec ./253_spec.rb:2 # bees should things
rspec ./253_spec.rb:9 # bees should also things