ruby - 背景中的 cucumber <reference>?

标签 ruby cucumber

这是一个关于 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>

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

最佳答案

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

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:中得到了它的覆盖 我认为这些步骤将运行且简单,无需过多重复

关于ruby - 背景中的 cucumber <reference>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13712449/

相关文章:

ruby-on-rails - Rails 模型中的邻近地区

Ruby 为不同类型的对象设置成员资格

ruby - Rails axlsx gem 加载文件

CodeMirror 的 cucumber 测试

testing - 你如何将 cucumber 的功能文本文件传递给运行? IE。重新运行.txt

ruby - 在一个网站上使用多个主题 jekyll

ruby - 在类构造函数中有参数是否可以接受?

cucumber - 避免在小 cucumber 中重复自己

rest - 在 Karate DSL 框架中,我们如何添加自定义步骤定义以将其功能扩展到 REST 功能之外?

ruby - 如何在 iPad 模拟器上运行 Cucumber、Ruby 脚本