Question

When i run cucumber it displays the possible steps that i should define, an example from the RSpec book:

1 scenario (1 undefined)
4 steps (4 undefined)
0m0.001s
You can implement step definitions for undefined steps with these snippets:
Given /^I am not yet playing$/ do
  pending
end
When /^I start a new game$/ do
  pending
end
Then /^the game should say “Welcome to CodeBreaker”$/ do
  pending
end
Then /^the game should say “Enter guess:”$/ do
  pending
end

Is there a way that it will automaticly create the step definitions file, so i don't have to rewrite or copy paste by hand but i can just to customize them to be more generic?

Was it helpful?

Solution

Cucumber doesn't offer this feature. Probably because you would have to tell it where to put the step definitions file, and what to name it.

OTHER TIPS

Like Kevin said, Cucumber would have to know the name of the file to put it in, and there are no good defaults to go with, other than using the same file name as the feature file. And that is something I consider an antipattern: http://wiki.github.com/aslakhellesoy/cucumber/feature-coupled-steps-antipattern

Intellij Idea or RubyIDE does exactly what you are asking for:

  • Detects missing step definitions
  • Creates missing step definitions in a new file (you choose the name of the file) or in one of the existing step definition files
  • Highlights matched step parameters

see http://i48.tinypic.com/10r63o4.gif for a step by step picture

Enjoy

There is a possibility this kind of feature could be useful, but as Kevin says, it doesn't exist at present. But it could also get quite messy, quite quickly.

Maybe you already do this, but there's nothing stopping you cut and pasting the output direct into your text editor, or even piping the output direct to your text editor if you're so inclined. Then at least you're getting pretty much most of the way there, bar creating the file and naming.

try this https://github.com/unxusr/kiwi it auto generate your feature file and make the step definitions file for you and you just fill in the steps with code. In later version will write the code of the steps and run the test all of that automagically

You can use a work around way to generate steps file all you have to do is to run the Cucumber on a feature doesn't have defined steps by identify a specific feature as the following command:

1) using path

bundle exec cucumber {PATH}
note path would start with features/....
for example 
features/users/login.feature

1) using tags

bundle exec cucumber --tags=@{TAG}
note tag should be above your scenario in the steps file
for example 
  @TAG
   Scenario:

And you will have the suggested steps in the console with pending status

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top