黄瓜 - 如何从这个小黄瓜场景中删除数据重复?

时间:2012-01-12 23:29:18

标签: ruby cucumber integration gherkin

我有以下Gherkin场景:

Scenario: User Login
    Given a user account exists the email "james.smith@somesite.com" and password "surprise"
    And I am on the login page
    When I fill in the following:
      | email | james.smith@somesite.com |
      | password | surprise |
    And I press "Submit"
    Then....

第二行传递电子邮件地址&步骤定义的密码,然后将这些细节传递给FactoryGirl工厂。

基本上,我不确定如何从这种情况中删除这些重复数据,我想到使用表格却看不出这会有什么帮助,有没有人对如何做到这一点有任何想法?提前谢谢!

2 个答案:

答案 0 :(得分:4)

您可以在电子邮件和密码字段中使用类似FIT的表格,就像他们在https://github.com/cucumber/cucumber/blob/master/examples/i18n/en/features/addition.feature

中的示例中所使用的那样
Scenario Outline: User Login
    Given my account exists with email <email> and password <password>
    And I am on the login page
    When I fill the email <email>
    And I fill the password <password>
    And I press "Submit"
    Then ...

Examples:
    | email        | password |
    | john@doe.com | surprise |

答案 1 :(得分:0)

我们使用的模式是抽象细节,这在几个场景中很常见......

Given my user exists
And I am on the login page
When I login with my credentials
Then I should .... 

然后我们有一个yaml文件,默认值为有效用户名,有效密码,密码无效......我们的步骤调用此文件。

如果你想尝试很多例子,另一个答案会更好,我认为我们的工作经常在你想要登录的地方,但并不总是在每个场景中指定“无聊”的东西。

相关问题