2014-02-05 83 views
0

有沒有辦法手動創建黃瓜步驟定義?也許是某種Rails生成器?黃瓜步驟定義:有沒有一種方法來自動創建它們?

現在我要做的就是create features/new_feature.feature,運行cucumber,創建step_definitions/new_feature_steps.rb,然後在終端複製步驟定義來new_feature_steps.rb

有沒有更快的方式做到這一點,或者我手動做到這一點?

順便說一句我很感激關於這個話題的文章。我正在爲我們的Ruby on Rails應用程序學習Cucumber。

我曾見過this thread,但它在四年內還沒有更新。

回答

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 

可以將此轉化爲接受參數文件名等

+0

哦命令行實用程序,那麼它必須來自CLI。我認爲有一些黃瓜任務或這種類型的東西。謝謝 :) –