Expected arguments which respond to #description fail with a useless error
Created by: benlangfeld
class MyObject
def description
end
end
describe "rspec-mocks" do
context "when I call an expected method with the wrong args" do
context "and my arg responds to #description" do
it "gives me a useful error" do
should_receive(:foo).with(1)
foo MyObject.new
end
end
end
end
➭ rspec example.rb [2.0.0]
F
Failures:
1) rspec-mocks when I call an expected method with the wrong args and my arg responds to #description gives me a useful error
Failure/Error: foo MyObject.new
#<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x007f9ca9c3a4e0> received :foo with unexpected arguments
expected: (1)
got: ()
# ./example.rb:11:in `block (4 levels) in <top (required)>'
Finished in 0.00081 seconds
1 example, 1 failure
Failed examples:
rspec ./example.rb:9 # rspec-mocks when I call an expected method with the wrong args and my arg responds to #description gives me a useful error
What I would expect to see here is:
#<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x007f9ca9c3a4e0> received :foo with unexpected arguments
expected: (1)
got: (#<MyObject:0x007fda0b8bc210>)
This doesn't work because my incorrect arg responds to #description
even though it's not a matcher, and this is checked here. I really don't think #description
is a fair test for a matcher, and we should be looking for #rspec_description
or something.
I can make this change (though it also involved modifying rspec-core), but I need to know first that it won't be rejected due to BC concerns.