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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,14 @@ module Mocks | |
}.to raise_error(/0 times/) | ||
end | ||
|
||
it "raises an exception when a block is used to match the arguments" do | ||
dbl = double_with_met_expectation(:expected_method) | ||
expect { | ||
expect(dbl).to have_received(:expected_method) { |argument| | ||
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. @timcowlishaw this can be reduced to one line: `expect(dbl).to have_received(:expected_method) {} |
||
} | ||
}.to raise_error(/have_received matcher does not take a block argument/) | ||
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. Given that you are using 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. I realised this is dumb, because it'll happen in the backtrace. Sorry @timcowlishaw. 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. I think this might make more sense as a warning with caller(0). What do you think @JonRowe ? 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. I just think we need to spec which line these come from, as we've had a few instances where we've messed it up, or the ruby implementation has a different idea about caller. 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. what do you think about warning versus raising though? We get the backtrace for free with a raise but it stops execution. I think a warning is a better solution. 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. Agree 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. Yep, agreed on both counts. Assuming you wouldn't rather a PR allowing Thanks, Tim 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. Do this, we'll merge it (maybe into 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. Great stuff. Will sort this out tomorrow! |
||
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) | ||
|
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.
@timcowlishaw I think this might be easier to understand if it were changed to
matcher does not take a block argument. Called from #{caller(0)}
. WDYT?