Cucumber: Automatic step file creation?

2019-02-23 08:04发布

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?

6条回答
叼着烟拽天下
2楼-- · 2019-02-23 08:31

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

查看更多
你好瞎i
3楼-- · 2019-02-23 08:39

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.

查看更多
看我几分像从前
4楼-- · 2019-02-23 08:44

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

查看更多
姐就是有狂的资本
5楼-- · 2019-02-23 08:46

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

查看更多
手持菜刀,她持情操
6楼-- · 2019-02-23 08:51

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

查看更多
聊天终结者
7楼-- · 2019-02-23 08:52

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.

查看更多
登录 后发表回答