I have the following scenario:
Scenario: Open the menu
Given I am on the Home Screen
Then I touch the menu button
If I execute this scenario while I am on the home screen everything works as expected. However, if this scenario gets executed while I'm not on the home screen, the 'Given I am on the Home Screen' instruction returns true even though it is not true and the rest of the scenario continues to be executed (and eventually the scenario fails because I am actually not on the home screen).
I can't find a reason why the 'Given I am on the Home Screen' instruction passes even though it returns false.
I am trying to find a way to execute series of steps only if the Given instruction passes. Is it the right way to do that?
From the Cucumber wiki:
Failed steps
When a Step Definition’s Proc is executed and raises an error, the step is marked as red. What you return from a Step Definition has no significance what so ever. Returning nil or false will not cause a step definition to fail.
Returning false in the step definition is not sufficient. You need to raise an error if the Home Screen is not being displayed.