We want to test our step definitions for cucumber. One thing we would like to be able to check is that tests which we expect to fail actually do fail. To do this, we would like to write scenarios that we know will fail and add them to our test suite, but tag or otherwise denote them so that they "pass" if and only if they fail. How would one approach this?
You should be testing for the negative state. A failing step is simply the inverse of a passing step. So do something like:
Then /i should not be true/ do
some_value.should_not be_true
end
That is how I would go about testing for failure. You can also catch exceptions and such, and verify that a block does in fact throw that exception
lambda do
something_that_horks
end.should raise_error(Specific::Error)
You simply reverse the tests in your test cases to test for negative results, not positive results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With