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
yield_control hardening #1167
yield_control hardening #1167
Conversation
6c23382
to
6e9f6c3
Compare
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.
Nice catch.
Looks good. Thanks!
6e9f6c3
to
b3c7629
Compare
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.
Ok, I think this needs implementing properly soon but if you don't have the bandwidth to do that these tweaks shall suffice.
…t_most Currently, `exactly(:trice)` would always provide a failure with message 'expected given block to yield control', even if control was yielded. `at_least(:trice)` yields a cryptic error 'ArgumentError: comparison of Integer with nil failedinstead of an error as it should'. Some unused code was detected and removed.
ad7ec3b
to
90aac3f
Compare
90aac3f
to
1341b05
Compare
In particular, it would be reasonable to expect yield_control.at_least(1).at_most(4).times to work This also simplifies the failure message in case no count constraint was called.
1341b05
to
04efb1f
Compare
@@ -67,6 +67,22 @@ def each_arg(*args, &block) | |||
expect(val).to be_nil | |||
end | |||
|
|||
it 'raises an error if given an invalid count argument' do |
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.
Just for clarity, do you mind to add examples for a failure message like
expect {
expect { |b| 0.times.each(&b) }.to yield_control.at_least(:once)
}.to fail_with(/expected given block to yield control at least once but did not yield/)
expect {
expect { |b| 2.times.each(&b) }.to yield_control.at_most(:once)
}.to fail_with(/expected given block to yield control at most once but yielded twice/)
expect {
expect { |b| 1.times.each(&b) }.to yield_control.at_least(:twice)
}.to fail_with(/expected given block to yield control at least twice but yielded once/)
expect {
expect { |b| 0.times.each(&b) }.to yield_control
}.to fail_with(/expected given block to yield control but did not yield/)
Thanks! |
Prevent invalid argument given to yield_control.exactly / at_least / at_most Previously `exactly(:trice)` would always provide a failure with message 'expected given block to yield control', even if control was yielded. `at_least(:trice)` yields a cryptic error 'ArgumentError: comparison of Integer with nil failedinstead of an error as it should'.
Prevent invalid argument given to yield_control.exactly / at_least / at_most Previously `exactly(:trice)` would always provide a failure with message 'expected given block to yield control', even if control was yielded. `at_least(:trice)` yields a cryptic error 'ArgumentError: comparison of Integer with nil failedinstead of an error as it should'.
Prevent invalid argument given to yield_control.exactly / at_least / at_most Previously `exactly(:trice)` would always provide a failure with message 'expected given block to yield control', even if control was yielded. `at_least(:trice)` yields a cryptic error 'ArgumentError: comparison of Integer with nil failedinstead of an error as it should'. --- This commit was imported from rspec/rspec-expectations@96bad96.
This commit was imported from rspec/rspec-expectations@f3da44b.
This fixes two misuses of
yield_control
.The following resulted in strange failures
Worse, the following doesn't test what is thought to be tested:
This PR fixes both.