2

我有这两个测试。他们几乎做同样的事情,所以我不想写两个独立的步骤来做几乎同样的事情。

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" linkand一起使用的步骤,I "delete" an "account" link我将如何修改以下正则表达式来处理“a”和“an”。

/^I "([^"]*)" a/an?? "([^"]*)" link$/
4

1 回答 1

4

这应该这样做:

/^I "([^"]*)" an? "([^"]*)" link$/

问号表示“n”字符可以是字符串的一部分,但不必

如果类型中有任何“值”,您也可以使用:

/^I "([^"]*)" (a|an) "([^"]*)" link$/
于 2012-09-12T17:16:25.347 回答