Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix failure message when message received with incorrect args.

- Closes #34.
  • Loading branch information...
commit 77844a31c7fcb6a550646ac446826dd08b551c60 1 parent 38a6295
@txus txus authored dchelimsky committed
Showing with 12 additions and 1 deletion.
  1. +1 −1  lib/rspec/mocks/proxy.rb
  2. +11 −0 spec/rspec/mocks/mock_spec.rb
View
2  lib/rspec/mocks/proxy.rb
@@ -142,7 +142,7 @@ def find_matching_expectation(method_name, *args)
end
def find_almost_matching_expectation(method_name, *args)
- method_double[method_name].expectations.find {|expectation| expectation.matches_name_but_not_args(method_name, *args)}
+ method_double[method_name].expectations.find {|expectation| expectation.matches_name_but_not_args(method_name, *args) && !expectation.called_max_times?}
end
def find_matching_method_stub(method_name, *args)
View
11 spec/rspec/mocks/mock_spec.rb
@@ -109,6 +109,17 @@ module Mocks
}.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
+ describe "even when a similar expectation with different arguments exist" do
+ it "raises exception if args don't match when method called, correctly reporting the offending arguments" do
+ @mock.should_receive(:something).with("a","b","c").once
+ @mock.should_receive(:something).with("z","x","c").once
+ lambda {
+ @mock.something("a","b","c")
+ @mock.something("z","x","g")
+ }.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"z\", \"x\", \"c\")\n got: (\"z\", \"x\", \"g\")")
+ end
+ end
+
it "raises exception if args don't match when method called even when the method is stubbed" do
@mock.stub(:something)
@mock.should_receive(:something).with("a","b","c")
Please sign in to comment.
Something went wrong with that request. Please try again.