Cucumber: Automatic Step File Creation

Cucumber: Automatic step file creation?

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.

Cucumber step definitions: Is there a way to automate creating them?

With a very little effort I guess it can be achieved. e.g. This is my feature file.

Feature: dummy

Scenario: First
Given I set sessions to "10"
Then it should have "10"

then in 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

Your steps.rb now has

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

You can convert this into a command line utility that accepts parameter for filename etc.



Related Topics



Leave a reply



Submit