user108471 user108471 - 2 years ago 138
Ruby Question

How do I "skip" a scenario with a tag in Cucumber?

I currently have a project with a pretty large pile of Cucumber

files where many of the Scenarios are known to be broken. These scenarios are tagged with
, and we avoid running them by executing cucumber with
-t ~@broken
. Unfortunately, this makes these scenarios effectively invisible when we examine the cucumber output. They don't appear as passed, failed, or skipped. What I'd like is for a count of these scenarios to be included in the cucumber output. They should show as "skipped" tests, rather than not showing at all.

What I tried:

Before('@broken') do |scenario|

But this raises a
exception which, uncaught, just fails the scenario.

I know I can write a step like:

Given /^PENDING/ do

And then go through all my feature files and add this step to every scenario with the
tag. This seems crazy, though. It doesn't fit with the semantics of what a "step" is supposed to be (not to mention that it requires broad changes to all my feature files instead of just adding a hook to a tag).

Is this something I can do with just a tag?

Answer Source


According to your comment, you are using cucumber-1.3.10. It is not possible with that version.

In cucumber-jvm and cucumber-js it works as expected marking the scenario as pending, but surprisingly in ruby, if the Pending exception is thrown from the Before (or After) hook, it will mark the scenario as failed instead of pending.

So your first suggestion was right. You should use a tagged hook.

Before('@broken') do

But you will have to update your Gemfile to use the latest version of cucumber, that is 2.0.0.beta.3 at this moment.

source ''
group :test do
  gem 'cucumber', '2.0.0.beta.3'

Then the output will be as expected, marked as pending (not skipped as there is no such thing as a skipped scenario, only passed/failed/pending/undefined/skipped steps and passed/failed/pending/undefined scenarios).

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download