Skip to content

Commit

Permalink
Use is_a_matcher? to decide if #description is used in error output
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Phippen committed Sep 4, 2014
1 parent 9f96a86 commit 7e1a938
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rspec/mocks/error_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def arg_list(*args)
end

def arg_has_valid_description(arg)
return false unless arg.respond_to?(:description)
return false unless RSpec::Support.is_a_matcher?(arg)

!arg.description.nil? && !arg.description.empty?
end
Expand Down
15 changes: 15 additions & 0 deletions spec/rspec/mocks/diffing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,19 @@
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :foo with unexpected arguments\n expected: ([:a, :b, :c])\n got: ([]) \n@@ -1,2 +1,2 @@\n-[[:a, :b, :c]]\n+[[]]\n")
reset d
end

it "does not use the object's description for a non-matcher object that implements #description" do
allow(RSpec::Mocks.configuration).to receive(:color?).and_return(false)
d = double("double")

#object here because double.description changes the inspect value
collab = Object.new.tap {|o| allow(o).to receive(:description).and_return("This string") }
collab_inspect = collab.inspect

expect(d).to receive(:foo).with(collab)
expect {
d.foo([])
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :foo with unexpected arguments\n expected: (#{collab_inspect})\n got: ([]) \n@@ -1,2 +1,2 @@\n-[#{collab_inspect}]\n+[[]]\n")
reset d
end
end

0 comments on commit 7e1a938

Please sign in to comment.