14
votes

I've inherited a Rails (3) app and am trying to get to grips with the existing Cucumber tests. I've got the following setup in the app's 'features' folder (I've missed out any files which aren't relevant, eg extra features and steps)

/features
  /people
    new-person.feature
  /step_definitions
    people_steps.rb
    web_steps.rb
  /support
    env.rb
    paths.rb
    selectors.rb

If I run 'rake' then it runs all the features in features/people/new-person.feature, correctly using the steps listed in step_definitions.

However, I don't want to run rake every time as it takes too long, I just want to run a specific test in Cucumber, e.g. cucumber features/people/new-person.feature -l 8

When I do this, it runs the feature but hasn't loaded the steps. I get this back:

Using the default profile...
Feature: Add a new person
  In order to allocate tasks to people
  As a community manager
  I want to add a new person

  Scenario: Secondary navigation should contain "Add new person" # features/people/new-person.feature:8
    Given I am on the new person page                            # features/people/new-person.feature:9
      Undefined step: "I am on the new person page" (Cucumber::Undefined)
      features/people/new-person.feature:9:in `Given I am on the new person page'
    Then I should not see "Add new person"                       # features/people/new-person.feature:10
      Undefined step: "I should not see "Add new person"" (Cucumber::Undefined)
      features/people/new-person.feature:10:in `Then I should not see "Add new person"'

1 scenario (1 undefined)
2 steps (2 undefined)
0m0.005s

You can implement step definitions for undefined steps with these snippets:

Given /^I am on the new person page$/ do
  pending # express the regexp above with the code you wish you had
end

Then /^I should not see "([^"]*)"$/ do |arg1|
  pending # express the regexp above with the code you wish you had
end

If you want snippets in a different programming language, just make sure a file
with the appropriate file extension exists where cucumber looks for step definitions.

Why isn't Cucumber loading the steps in? I'm guessing that I need to require the steps somewhere but I can't work out where.

Thanks, Max

2
For the sake of argument move the feature file up one directory. I don't have a require anywhere in my various .feature files, and I didn't see any configuration goop in features/support/ files that seemed to point to this. are you certain your people_steps.rb code is functional? Have you sacrificed a chicken yet? - jaydel
@jaydel - it all works fine when i run it with simply rake, ie the steps are all loaded fine. I would like to continue to subdir my features just for the sake of organising them into sensible groups. - Max Williams
@jaydel - but, moving the feature files into the main features folder did fix the problem... There must be a require somewhere that i need to add an extra "../" i reckon. - Max Williams
ah, perfect. good stuff. thanks for bringing it back to us :) - jaydel
Please post your solution as an answer and accept it in two days. That way it will show up properly as answered in question listings and search results. - hammar

2 Answers

11
votes

Max Williams found the answer to his question:

EDIT - found the answer, here: https://rspec.lighthouseapp.com/projects/16211/tickets/401-envrb-not-loaded-when-running-individual-features-in-sub-directories

In config/cucumber.yml there's a line that looks like this:

std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"

change it to

std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip --require features/"

This is like adding --require features/ to the end of your cucumber test run and makes it load everything up properly.

0
votes

I did not already have a cucumber.yml file to change, for whatever reason. So, simply creating a blank /config/cucumber.yml file and putting the line in it:

std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip --require features/"

did not work. (That is not surprising, I figured there was supposed to be more to it than just that one line.)

I found a good example of a FULL, working, cucumber.yml example file here: http://jdfrens.blogspot.com/2010/03/uh-yes-i-did-define-that-cucumber-step.html