Permalink
Browse files

Use the improved message from the prev commit for stubs, not message …

…expectations.

- Closes #147, #123.
  • Loading branch information...
1 parent 1ebc698 commit 49ce4966ca99574ac28b6e8ed7ec02ac055db901 @dchelimsky dchelimsky committed Jun 4, 2012
View
@@ -128,9 +128,7 @@ def message_received(message, *args, &block)
raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(message) or null_object?)
elsif stub = find_almost_matching_stub(message, *args)
stub.advise(*args)
- raise_unexpected_message_args_error(stub, *args)
- elsif expectation = find_almost_matching_satisfied_expectation(message,*args)
- raise_missing_default_stub_error(expectation, *args) if not null_object?
+ raise_missing_default_stub_error(stub, *args)
elsif @object.is_a?(Class)
@object.superclass.__send__(message, *args, &block)
else
@@ -139,13 +137,13 @@ def message_received(message, *args, &block)
end
# @private
- def raise_unexpected_message_args_error(expectation, *args)
- @error_generator.raise_unexpected_message_args_error(expectation, *args)
+ def raise_unexpected_message_error(method_name, *args)
+ @error_generator.raise_unexpected_message_error method_name, *args
end
# @private
- def raise_unexpected_message_error(method_name, *args)
- @error_generator.raise_unexpected_message_error method_name, *args
+ def raise_unexpected_message_args_error(expectation, *args)
+ @error_generator.raise_unexpected_message_args_error(expectation, *args)
end
# @private
@@ -172,10 +170,6 @@ def find_almost_matching_expectation(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_almost_matching_satisfied_expectation(method_name, *args)
- method_double[method_name].expectations.find {|expectation| expectation.matches_name_but_not_args(method_name, *args) }
- end
-
def find_matching_method_stub(method_name, *args)
method_double[method_name].stubs.find {|stub| stub.matches?(method_name, *args)}
end
@@ -99,4 +99,3 @@ def assign_stubs(stubs)
end
end
end
-
@@ -1,10 +0,0 @@
-require 'spec_helper'
-
-describe 'with' do
- it "should ask the user to stub a default value first if the message might be received with other args as well" do
- obj = Object.new
- obj.should_receive(:foobar).with(1)
- obj.foobar(1)
- lambda{ obj.foobar(2) }.should raise_error(RSpec::Mocks::MockExpectationError, /Please stub a default value first if message might be received with other args as well./)
- end
-end
@@ -208,10 +208,10 @@ def existing_private_instance_method
end.should raise_error(/received :foo with unexpected arguments/)
end
- it "complains if called with other arg" do
+ it "complains if called with other arg", :github_issue => [123,147] do
lambda do
@stub.foo("other")
- end.should raise_error(/received :foo with unexpected arguments/)
+ end.should raise_error(/received :foo with unexpected arguments.*Please stub a default value/m)
end
it "does not complain if also mocked w/ different args" do

0 comments on commit 49ce496

Please sign in to comment.