有没有办法手动创建黄瓜步骤定义?某种Rails生成器,也许?
现在我所做的是create features/new_feature.feature
,运行cucumber
,创建step_definitions/new_feature_steps.rb
,然后将终端中的步骤定义复制到new_feature_steps.rb
。
有更快的方法吗?或者我是否手动执行此操作?
BTW我会很感激有关这个主题的文章。我正在为Ruby on Rails应用程序学习Cucumber。
我见过this thread,但四年内没有更新。
答案 0 :(得分:1)
我认为只需付出很少的努力就可以实现。例如这是我的专题文件。
Feature: dummy
Scenario: First
Given I set sessions to "10"
Then it should have "10"
然后在irb
s = `cucumber features/adding.feature -d` #=> "Feature: dummy\n\n Scenario: First...
f = File.new("features/steps.rb","w") #=> create steps.rb file
f.puts s.scan(/(?<=snippets\:).*/m) #=> scan for step definitions and write to steps.rb
f.close
您的steps.rb现已
Given(/^I set sessions to "(.*?)"$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Then(/^it should have "(.*?)"$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
您可以将其转换为接受文件名等参数的命令行实用程序。