-
-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #123 #147
Issue #123 #147
Conversation
@@ -28,6 +28,13 @@ def raise_unexpected_message_args_error(expectation, *args) | |||
end | |||
|
|||
# @private | |||
def raise_no_stub_with_default_behavior(expectation,*args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about raise_no_default_stub_error
or raise_missing_default_stub_error
? I think either aligns better with the other raise_xxx_error
method names. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'raise_missing_default_stub_error' sounds better of the lot. I'll make the changes. Thanks.
…ethod with default behavior.
Made both suggested changes. |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I merged locally after you made my suggested changes. All the specs pass but then when I tried it it didn't actually work as expected yet. If you change this example to use stub
instead of should_receive
, you'll see it fail.
The reason is that find_almost_matching_stub
returns the stub and we never get to the next conditional. I'm thinking we can just delegate this branch to raise_missing_default_stub_error
instead of raise_unexpected_message_args_error
and that solves the problem. WDYT?
I'm going to go ahead and take what you've got and go from there. Thanks for the pull! |
Issue #123: Improved error message when user forgets to stub a method with a default.
I made some adjustments in 49ce496. |
Improved error message when user forgets to stub a method with default behavior. Based on this definition of 'with'.
"Constrains a stub or message expectation to invocations with specific arguments. With a stub, if the message might be received with other args as well, you should stub a default value first, and then stub or mock the same message using
with
to constrain to specific arguments."