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
Make have_received complain if passed a block #364
Closed
timcowlishaw
wants to merge
3
commits into
rspec:master
from
timcowlishaw:feature-have-received-complains-if-passed-a-block
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,15 @@ module Mocks | |
}.to raise_error(/0 times/) | ||
end | ||
|
||
it "warns when a block is used to match the arguments" do | ||
dbl = double_with_met_expectation(:expected_method) | ||
self.stub(:warn => nil) | ||
expect(dbl).to have_received(:expected_method) { }; line = __LINE__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice hack for avoid calculating the |
||
file = __FILE__ | ||
message = /have_received ignores its block argument. Called from #{file}:#{line}/ | ||
expect(self).to have_received(:warn).with(message) | ||
end | ||
|
||
context "with" do | ||
it 'passes when the given args match the args used with the message' do | ||
dbl = double_with_met_expectation(:expected_method, :expected, :args) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
see I think this is worth merging into 2-14... just as an FYI /cc @myronmarston @samphippen
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.
It's kind of a weird message though:
have_received
won't ignore its block argument in 3.x, right?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 think we should leave 2-14 as is and do things with blocks in 3-0. If we raise this warning now, nobody will expect the reintroduction in 3
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 lean toward that too. I think the best options are to either choose to classify this as a bug and "fix" it entirely in 2.14, or wait until 3.x to introduce it as a feature.
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 think, upon balance, I'd classify this as a feature and add it in 3-0. @alindeman @JonRowe @timcowlishaw what do you think?
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'm very happy with that. I started looking at implementing it this morning, but it still needs a little more work. will open a PR shortly!
Thanks,
Tim
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.
Cool! If you need a hand tomorrow let me know and I'm happy to help.
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 agree with @samphippen and @alindeman: this is a new feature, and adding a warning in 2.14 will add confusion. (Plus I want to focus on 3.0 and stop working on 2.14!)