Ruby on Rails: Cucumber: how do I Rake a single feature?

38,564

Solution 1

To answer the Rake question directly, you can use:

rake FEATURE=features/adding_products.feature cucumber

but the Using Rake wiki page advises against using rake for anything but on a CI server because it's slower to start. Just use the cucumber command line instead, i.e.:

cucumber features/adding_products.feature

or, if you must:

bundle exec cucumber features/adding_products.feature

Solution 2

The correct way is to run it using the cucumber executable if you're using Rails 2, or bundle exec cucumber if you're using Rails 3 (and thus Bundler).

To run a specific feature:

[command] features/signing_in.feature

To run a specific scenario from that feature:

[command] features/signing_in.feature:6

The line number can be any line inside that feature, but is usually the first line.

If you run rake cucumber:ok and some scenarios fail, at the bottom of the output you will see something like this:

cucumber features/sigining_in.feature:6 # Signing in via form

You can triple-click this line and paste it into your terminal to just run that scenario.

Solution 3

The rake did not worked for me. Just replaced the rake with bundle exec, and it worked. below is a sample.

bundle exec cucumber features/users/signup.feature --require features

Solution 4

I'm not sure cucumber's tag feature was available when the question asked, but i prefer setting @active tag

  @active
  Feature ..

or

  @active
  Scenario ..

and

  cucumber --tags @active

Solution 5

I like the short command $ cucumber -n.

If:

Feature: Manage Contents
  In order to manage instances from custom content types
  …

Then:

$ cucumber -n "Manage Contents"
Share:
38,564

Related videos on Youtube

NullVoxPopuli
Author by

NullVoxPopuli

I do stuff

Updated on October 29, 2020

Comments

  • NullVoxPopuli
    NullVoxPopuli over 3 years

    Reason why I want to run them individually, is because I need to have them individually set up in my Rake file, because, My Java Heap Space fills up when I run them all together

    • uKolka
      uKolka almost 14 years
      Java Heap Space? How does Java figure into this if you're using a Rake/Rails/Cucumber stack?
    • ap2
      ap2 over 12 years
      running on jruby, i'm guessing
    • NullVoxPopuli
      NullVoxPopuli over 12 years
      not directly. I'm using some libraries along with cucumber that use jruby though. I think CapyBara is one. =\
  • Bastien
    Bastien about 13 years
    To run a single scenario, you can also type this: cucumber --name "Signing in via form"
  • sivabudh
    sivabudh almost 13 years
    For me, this works cucumber -r features features/adding_products.feature
  • Indika K
    Indika K almost 11 years
    Worked for me too. If I omit the --require features cucumber failed to identify the step definitions.
  • AMIC MING
    AMIC MING almost 11 years
    for new version, you can do this too - bundle exec cucumber features/adding_products.feature
  • comandante N
    comandante N over 10 years
    right, had the same problem. the alternative apparently is to hard code that --require features replacig this line in config/cucumber.yml std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip" with std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip --require features/" see this question
  • konyak
    konyak about 10 years
    Note: "Any feature that is located inside a sub-directory of features directory must require features [--require features]." Per github.com/cucumber/cucumber/wiki/Running-Features
  • Alex Pan
    Alex Pan over 8 years
    Thank you Ryan and Bastien. This should be the accepted answer.
  • AMIC MING
    AMIC MING over 8 years
    Good one Buddy, you are the Genius