I have a method which yields. I am testing it for two conditions.
1) if it yields ( I am successfully able to do this using the yield match)
2) if it does not yield. ( This is where any help in the right direction would be appreciated.)
Method:
def example_method
yield if block_given?
end
Specs:
it 'yields to a block' do
expect{ |b| example_method(&b) }.to yield_with_no_args
end
it 'does not yield if a block is not given' do
end
The first spec passes successfully, but for the second spec I am not sure how to proceed, since the yield match would require a block to be given and if a block is given it would pass, whereas I want to test it for not yielding if a block is not given.
Thanks!
Try something like
expect { example_method }.to_not yield_control
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.