@larryq,您比您想象的更接近解决方案...
可选功能:
Feature: optional parameter
Scenario: Parameter is not given
Given xyz
When I check the favorite color count
Then foo
Scenario: Parameter is given
Given xyz
When I check the favorite color count for email address 'john@anywhere.com'
Then foo
optional_steps.rb
When /^I check the favorite color count( for email address \'(.*)\'|)$/ do |_, email|
puts "using '#{email}'"
end
Given /^xyz$/ do
end
Then /^foo$/ do
end
输出:
Feature: optional parameter
Scenario: Parameter is not given
Given xyz
When I check the favorite color count
using ''
Then foo
Scenario: Parameter is given
Given xyz
When I check the favorite color count for email address 'john@anywhere.com'
using 'john@anywhere.com'
Then foo
2 scenarios (2 passed)
6 steps (6 passed)
0m9.733s