我有这两个测试。他们几乎都做同样的事情,所以我不想写两个单独的步骤做同样的事情。
Scenario: I delete a question link
Given I am on the home page
When I "delete" a "question" link
Then A "question" link should be "deleted"
Scenario: I delete a account link
Given I am on the home page
When I "delete" an "account" link
Then An "account" link should be "deleted"
如果我想编写一个适用于I "delete" a "question" link
和I "delete" an "account" link
的步骤,我将如何修改以下正则表达式以处理“a”和“an”。
/^I "([^"]*)" a/an?? "([^"]*)" link$/
答案 0 :(得分:4)
这应该做:
/^I "([^"]*)" an? "([^"]*)" link$/
问号表示“n”字符可以是字符串的一部分但不必
如果类型中有任何“值”,您也可以使用:
/^I "([^"]*)" (a|an) "([^"]*)" link$/