7

My Cucumber just won't find the step definitions. The file structure (Only the specs folder inside the Rails root) looks like this:

-> specs
   -> features
      -> main_structure.feature
      -> step_definitions
         -> main_structure_steps.rb

This is the main_structure.feature:

Feature: Main structure
  Scenario: Viewing the Structure page
    When I am on the structure page

And this the main_structure_steps.rb:

When(/^I am on the structure page$/) do
  visit '/'
end

Now I run the cucumber command like this:

→ cucumber spec/features -r features 

I get this output:

Using the default profile...
Feature: Main structure

  Scenario: Viewing the Structure page # spec/features/main_structure.feature:2
    When I am on the structure page    # spec/features/main_structure.feature:3
      Undefined step: "I am on the structure page" (Cucumber::Undefined)
      spec/features/main_structure.feature:3:in `When I am on the structure page'

1 scenario (1 undefined)
1 step (1 undefined)
0m0.229s

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

When(/^I am on the structure page$/) do
  pending # express the regexp above with the code you wish you had
end

/Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:1037:in `block in process_args': invalid option: -r (OptionParser::InvalidOption)
    from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:1016:in `new'
    from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:1016:in `process_args'
    from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:1066:in `_run'
    from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:1059:in `run'
    from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247@global/gems/minitest-4.7.5/lib/minitest/unit.rb:795:in `block in autorun'

There is also an error message at the bottom, that doesn't appear when I run the test in RubyMine. But in both cases, the step definitions are not found. This is the Rubymine output:

Testing started at 21:29 ...


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

When(/^I am on the structure page$/) do
  pending # express the regexp above with the code you wish you had
end
1 scenario (1 undefined)
1 step (1 undefined)
0m0.001s

Process finished with exit code 0

Tell me if you need any additional infos.

Rudolf
  • 1,856
  • 2
  • 19
  • 32
  • Does it find step definitions when you run that single feature explicitly? e.g. `cucumber spec/features/main_structure.feature` – Bala Sep 12 '13 at 19:48
  • Just ran `cucumber spec/features/main_structure.feature -r features`, same result. – Rudolf Sep 12 '13 at 19:49
  • 1
    I believe the spec folder is a subfolder from where you are running cucumber? – Bala Sep 12 '13 at 19:51
  • That was it. Post it as an answer and you'll get my confirmation and upvote ;) `cucumber spec/features/main_structure.feature -r spec/features` did the job (See the last `-r spec/features`). – Rudolf Sep 12 '13 at 19:55

4 Answers4

12

Try

cucumber spec/features/main_structure.feature -r spec/features
Bala
  • 11,068
  • 19
  • 67
  • 120
  • As of 2016, the Cucumber devs removed the `-r` command. Do you know how to do the same thing in Cucumber 1.2.4? `--help` doesn't show an equivalent to -r. – JaneGoodall May 26 '16 at 22:29
1

Similar to my question:Cucumber Test acting in a strange way

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

When(/^I am on the structure page$/) do
  pending # express the regexp above with the code you wish you had
end

As the error saying. Put the code above in web_steps.rb and then replace pending # express the regexp above with the code you wish you had with the code you want

Community
  • 1
  • 1
Mostafa Hussein
  • 11,063
  • 3
  • 36
  • 61
  • Sorry, I forgot to mention that. This is already included in the main_structure_steps.rb. – Rudolf Sep 12 '13 at 19:47
  • my cucmber-rails version was 1.0.6 , maybe this could be a problem because as the book i am following said that cucumber has removed web steps in the newer versions , so the version i was allowed to work with 1.0.6 which has web_steps.rb – Mostafa Hussein Sep 12 '13 at 19:51
1

I Also had a similar problem with Java and for me the reason was that I had 2 Cucumber plugins installed in NetBeans IDE. I left Cetriolo and removed Cucumber Features and tests started working

Denys
  • 146
  • 4
0

make sure glue syntax is like below:

glue={"packageName"}

Here packageName is the package where you step definition java file exists

Ajay
  • 1
  • I think your answer relates to the java version cucumber, but you can see from the tags below the post that the question is about cucumber for ruby. – robd Jan 19 '17 at 21:37