Skip to content

Commit

Permalink
get rid of those nasty [brackets] when formatting failure messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Apr 2, 2010
1 parent 2670d32 commit a565922
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/rspec/mocks/error_generator.rb
Expand Up @@ -19,7 +19,13 @@ def raise_unexpected_message_error(sym, *args)

def raise_unexpected_message_args_error(expectation, *args)
expected_args = format_args(*expectation.expected_args)
actual_args = args.empty? ? "(no args)" : format_args(*args)
actual_args = format_args(*args)
__raise "#{intro} received #{expectation.sym.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}"
end

def raise_similar_message_args_error(expectation, *args)
expected_args = format_args(*expectation.expected_args)
actual_args = args.collect {|a| format_args(*a)}.join(", ")
__raise "#{intro} received #{expectation.sym.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/mocks/message_expectation.rb
Expand Up @@ -244,7 +244,7 @@ def generate_error
if similar_messages.empty?
@error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *@args_expectation.args)
else
@error_generator.raise_unexpected_message_args_error(self, *@similar_messages)
@error_generator.raise_similar_message_args_error(self, *@similar_messages)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/rspec/mocks/mock_spec.rb
Expand Up @@ -102,7 +102,7 @@ module Mocks
lambda {
@mock.something("a","d","c")
@mock.rspec_verify
}.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: ([\"a\", \"d\", \"c\"])")
}.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")")
end

it "should raise exception if args don't match when method called even when using null_object" do
Expand All @@ -111,7 +111,7 @@ module Mocks
lambda {
@mock.something("a","d","c")
@mock.rspec_verify
}.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: ([\"a\", \"d\", \"c\"])")
}.should raise_error(Rspec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")")
end

it "should fail if unexpected method called" do
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/mocks/stubbed_message_expectations_spec.rb
Expand Up @@ -17,7 +17,7 @@ module Mocks
double.foo('third')
lambda do
double.rspec_verify
end.should raise_error(%Q|Double "double" received :foo with unexpected arguments\n expected: ("first")\n got: (["second"], ["third"])|)
end.should raise_error(%Q|Double "double" received :foo with unexpected arguments\n expected: ("first")\n got: ("second"), ("third")|)
double.rspec_reset
end
end
Expand Down

0 comments on commit a565922

Please sign in to comment.