2

这是一个关于 Cucumber 的棘手问题:

Feature: Some feature

Background:
    Given I am on the root page

Scenario Outline: Relevant flash messages should appear
    When I fill in some_field with: <name>
    Then I should see the text: <relevant_flash>

    Examples:
        | name          | relevant_flash    |
        | Some name     | Some message      |

Scenario Outline: Irrelevant flash messages should not appear
    When I fill in some_field with: <name>
    Then I should not see the text: <irrelevant_flash>

    Examples:
        | name          | irrelevant_flash  |
        | Some name     | Some message      |

我讨厌不得不重复:

 When I fill in some_field with: <name>

但由于显而易见的原因,它不能仅仅移动到背景中。或者可以吗?如果您有解决方法,请告诉我...

4

2 回答 2

0

好吧,我可以用这样的东西来简化你的黄瓜:

Feature: Some feature

 Scenario Outline: Relevant flash messages should appear
    Given I am on the root page
    When I fill in some_field with: <name>
    Then I should see <message>
  Examples:
        |        name           |        message        |
        | Some name             | Relevant message      |
        | Some other name       | Irrelevant message    |
        | Some another name     | another flash message |

你注意到我把它拿出来了,Background:因为我们把它盖上了Scenario Outline: 我认为这个步骤会运行并且很简单,没有太多的重复

于 2012-12-13T20:14:00.097 回答
0

通过将成功和失败的消息组合在一起,您的方案大纲可以更好地组织以避免重复。

Feature: Some feature

Background:
    Given I am on the root page

Scenario Outline: Relevant flash messages should appear
    When I fill in some_field with: <name>
    Then I should see <relevant_message>

    Examples:
        | name                  | relevant_flash     |
        | Some name             | Some message       |
        | Some irrelevant name  | Irrelevant message |
        | Name for blank msg    |                    |
于 2012-12-09T19:27:39.640 回答