Cucumber 黄瓜中的可选参数
我有一个步骤定义,其中我想有一个可选参数。我相信两次调用此步骤的示例比任何其他方法都能更好地解释我所追求的Cucumber 黄瓜中的可选参数,cucumber,Cucumber,我有一个步骤定义,其中我想有一个可选参数。我相信两次调用此步骤的示例比任何其他方法都能更好地解释我所追求的 I check the favorite color count I check the favorite color count for email address 'john@anywhere.com' 首先,我想使用默认的电子邮件地址 定义此步骤的好方法是什么?我不是regexp大师。我尝试这样做,但cucumber在regexp参数不匹配方面给了我一个错误: Then(/^I c
I check the favorite color count
I check the favorite color count for email address 'john@anywhere.com'
首先,我想使用默认的电子邮件地址
定义此步骤的好方法是什么?我不是regexp大师。我尝试这样做,但cucumber在regexp参数不匹配方面给了我一个错误:
Then(/^I check the favorite color count (for email address "([^"]*))*"$/) do |email = "default_email@somewhere.com"|
可选。功能:
Feature: Optional parameter
Scenario: Use optional parameter
When I check the favorite color count
When I check the favorite color count for email address 'john@anywhere.com'
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
可选_steps.rb
When /^I check the favorite color count(?: for email address (.*))?$/ do |email|
email ||= "default@domain.com"
puts 'using ' + email
end
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: Use optional parameter
When I check the favorite color count
using default@domain.com
When I check the favorite color count for email address 'john@anywhere.com'
using 'john@anywhere.com'
1 scenario (1 passed)
2 steps (2 passed)
0m0.047s
@拉里克,你比你想象的更接近解决方案 可选。功能:
Feature: Optional parameter
Scenario: Use optional parameter
When I check the favorite color count
When I check the favorite color count for email address 'john@anywhere.com'
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
可选_steps.rb
When /^I check the favorite color count(?: for email address (.*))?$/ do |email|
email ||= "default@domain.com"
puts 'using ' + email
end
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
两步定义有什么不对?没有本质上的问题。我只是想伸展一下我的肌肉,看看有什么可能。两个定义意味着大部分时间重复代码,所以理论上条件从句更好。这很好用,谢谢你,但是我可以问一下
?:
位做了什么吗??:
是一个。