Permalink
Browse files

When generating failure message, don't use description if nil or empty

  • Loading branch information...
1 parent b34488c commit 203f662bd8d63690d3e322b11d241d3869053a45 @nddeluca nddeluca committed Sep 12, 2013
Showing with 40 additions and 1 deletion.
  1. +7 −1 lib/rspec/mocks/error_generator.rb
  2. +33 −0 spec/rspec/mocks/failing_argument_matchers_spec.rb
@@ -171,7 +171,13 @@ def format_args(*args)
end
def arg_list(*args)
- args.collect {|arg| arg.respond_to?(:description) ? arg.description : arg.inspect}.join(", ")
+ args.collect {|arg| arg_has_valid_description(arg) ? arg.description : arg.inspect }.join(", ")
+ end
+
+ def arg_has_valid_description(arg)
+ return false unless arg.respond_to?(:description)
+
+ !arg.description.nil? && !arg.description.empty?
end
def format_received_args(*args)
@@ -119,6 +119,39 @@ def inspect
@double.msg arg
end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (3)\n got: (my_thing)")
end
+
+ it "fails with sensible message when arg#description is nil" do
+ arg = Class.new do
+ def description
+ end
+
+ def inspect
+ "my_thing"
+ end
+ end.new
+
+ expect do
+ @double.should_receive(:msg).with(arg)
+ @double.msg 3
+ end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (my_thing)\n got: (3)")
+ end
+
+ it "fails with sensible message when arg#description is blank" do
+ arg = Class.new do
+ def description
+ ""
+ end
+
+ def inspect
+ "my_thing"
+ end
+ end.new
+
+ expect do
+ @double.should_receive(:msg).with(arg)
+ @double.msg 3
+ end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (my_thing)\n got: (3)")
+ end
end
end
end

0 comments on commit 203f662

Please sign in to comment.