Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip Cucumber steps?

Tags:

cucumber

I have the scenario like:

  1. Given I go to this page
  2. When I type cucumber
  3. And I click
  4. Then I should see the text
  5. And I should not see the line

If I run this scenario it will execute all the 5 steps. But I want to skip the 4th step (Then I should see the text) and execute the 5th step.

Please give me your suggestions. Thanks in advance. :)

like image 566
NMKP Avatar asked Dec 21 '12 10:12

NMKP


2 Answers

I have had to skip steps conditionally based on environments. I used next to skip steps. Here is an example on how to do what you wanted.

Then /^I should see the text/$ do
    next if @environment == 'no text'

    ...
       <The actual step definition>
    ...
end
like image 96
mvndaai Avatar answered Nov 19 '22 00:11

mvndaai


TL;DR - don't do it - you're (probably) getting it wrong. And you can't (easily) do it. As Aslak wrote (one of Cucumber main creators):

A step can have the following results:

  • undefined (no matching stepdef)
  • pending (a matching stepdef that throws PendingException)
  • passed (a matching stepdef that doesn't throw anything)
  • failed (a matching stepdef that throws an exception that isn't PendingException)
  • skipped (a step following a step that threw any exception (undefined, pending or failed))

What you're asking for is a new kind of result - ignored. It could be implemented by throwing an IgnoredException. This would mean that skipped would have to be changed to: (a step following a step that threw any exception (undefined, pending or failed) - unless the exception was IgnoredException)

I'm not sure I like this. It sounds like more complicated than it needs to be. You already have the necessary information that something is amiss - your step will either fail or be pending. I don't see the value in continuing to execute the following steps. You still have to implement the failing/pending step.

As long as you're reminded that "there is work to be done here" I don't think it's wortwhile complicating Cucumber to tell you what kind of work needs to be done...

Aslak

Whole discussion is here: http://comments.gmane.org/gmane.comp.programming.tools.cucumber/10146

like image 40
Ernest Avatar answered Nov 19 '22 00:11

Ernest