Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expect failed step and pass on failure in Cucumber?

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?

like image 454
kerkeslager Avatar asked Feb 01 '11 15:02

kerkeslager


1 Answers

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.

like image 139
BeepDog Avatar answered Nov 09 '22 15:11

BeepDog