Scenario
I\'m writing a library (no Ruby on Rails) for which I\'d like to have very detailed Cucumber features. This especially includes describing erro
It is possible to raise an exception in a When
block and then make assertions about it in the following Then
blocks.
Using your example:
When /^I do something unwanted$/ do
@result = -> { throw_an_exception! }
end
Then /^an "(.*)" should be thrown$/ do |error|
expect{ @result.call }.to raise_error(error)
end
That example uses RSpec's matchers but the important part is the ->
(Lambda); which allows the reference to the throw_an_exception!
method to be passed around.
I hope that helps!