黄瓜中的可选参数 [英] Optional parameter in cucumber
本文介绍了黄瓜中的可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个步骤定义,其中我想有一个可选参数。我相信两个调用这个步骤的例子比任何其他我更好地解释。
I have a step definition in which I'd like to have an optional parameter. I believe an example of two calls to this step explains better than anything else what I'm after.
I check the favorite color count
I check the favorite color count for email address 'john@anywhere.com'
首先,我想使用默认的电子邮件地址。
In the first instance, I would like to use a default email address.
什么是定义此步骤的好方法?我不是regexp大师。我尝试这样做,但黄瓜给了我一个错误关于regexp参数不匹配:
What's a good way of defining this step? I'm no regexp guru. I tried doing this but cucumber gave me an error regarding regexp argument mismatches:
Then(/^I check the favorite color count (for email address "([^"]*))*"$/) do |email = "default_email@somewhere.com"|
推荐答案
optional.feature:
optional.feature:
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'
optional_steps.rb
optional_steps.rb
When /^I check the favorite color count(?: for email address (.*))?$/ do |email|
email ||= "default@domain.com"
puts 'using ' + email
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
这篇关于黄瓜中的可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文