Skip to content
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

Merged
merged 1 commit into from
Jun 4, 2012
Merged

Issue #123 #147

merged 1 commit into from
Jun 4, 2012

Conversation

Bodhisattva2-0
Copy link

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."

@@ -28,6 +28,13 @@ def raise_unexpected_message_args_error(expectation, *args)
end

# @private
def raise_no_stub_with_default_behavior(expectation,*args)
Copy link
Contributor

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?

Copy link
Author

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.

@Bodhisattva2-0
Copy link
Author

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)
Copy link
Contributor

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?

@dchelimsky
Copy link
Contributor

I'm going to go ahead and take what you've got and go from there. Thanks for the pull!

dchelimsky added a commit that referenced this pull request Jun 4, 2012
Issue #123: Improved error message when user forgets to stub a method with a default.
@dchelimsky dchelimsky merged commit 1ebc698 into rspec:master Jun 4, 2012
@dchelimsky
Copy link
Contributor

I made some adjustments in 49ce496.

@travisbot
Copy link

This pull request passes (merged 409955f into 4b70b45).

Bodhisattva2-0 pushed a commit to c42engineering/rspec-mocks that referenced this pull request Jun 8, 2012
@alindeman alindeman mentioned this pull request Jun 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants