Going through the rspec docs i found these lines of code in yielding section of this page http://rubydoc.info/gems/rspec-expectations/frames
Can anyone explain what each line of code in the yielding section does step-by-step
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What does
expect { |b| 5.tap(&b) }.to yield_controldo?It is expecting that the code given in the block invokes
yieldstatement.The code given in the block (viz.
{ |b| 5.tap(&b) }) calls the ruby 1.9 tap method which has ayieldstatement within it’s implementation.So the statement is effectively asserting that ruby 1.9’s tap method has a
yieldstatement. 🙂To better understand this statement, try the following code example:
order.rbfileorder_spec.rbfileOutput from executing the spec:
To understand the other lines in the yielding section, similarly include the
expectstatements in the spec file as follows:Note: The
yield_if_truemethod used in the second line seems to be removed from where it was originally defined; I got it go work by adding it into the Order class as follows: