Permalink
Browse files

Merge pull request #417 from nddeluca/check-for-valid-arg-description

When generating a failure message for expected args, don't use description if nil or empty
  • Loading branch information...
2 parents b3305ee + 203f662 commit 3ff4185d575c5714986e0d5a8d009da36749b4cf @myronmarston myronmarston committed Oct 2, 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)
@@ -118,6 +118,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 3ff4185

Please sign in to comment.