Skip to content

Commit

Permalink
When generating failure message, don't use description if nil or empty
Browse files Browse the repository at this point in the history
  • Loading branch information
nddeluca committed Sep 12, 2013
1 parent b34488c commit 203f662
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rspec/mocks/error_generator.rb
Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions spec/rspec/mocks/failing_argument_matchers_spec.rb
Expand Up @@ -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.