Ruby:防止黄瓜裁员的方法?

时间:2011-10-05 08:35:34

标签: ruby cucumber

有没有人知道我如何缩短它并减少冗余:

Feature: nosql
  Scenario: flatfile

    Sometimes a user just wants to have flatfile storage like the
    classic Jekyll CMS.  When this is the case we should make sure
    that we adhere to classic folder and file structure, and store
    the generated content in _site unless the user decides that
    they want generation to be stored inside of memcached, then we
    should go ahead and use that.

    Given I have chosen flatfile storage for my site
    When I request a page, "the_page"
    And I have chosen flatfile generation
    Then I should pull the page from "_site"

    Given I have chosen flatfile storage for my site
    When I request a page, "the_page"
    And I have chosen memcached generation
    Then I should pull the page from memcached

我只是看到过多的重复文本,尽管Cucumber旨在帮助人们进行沟通,但由于在某些类型的场景中所有的重复,它们似乎会让事情“过于愚蠢”?除非我遗漏了什么。

还有另一个小问题,我如何使一个功能具有另一个功能的依赖?例如,memcached本身就是一个特性,所以我如何在这个特性中需要这个特性,这样如果没有实现memcached,那么flatfile场景在遇到memcached存储时会失败。

编辑:我也知道flatfile存储不是nosql,我只是把它扔在那里因为我还没有决定除了Git我想要哪个nosql ...所以现在更容易抛出flatfile所以我我可以开始为我的项目抓住黄瓜。

4 个答案:

答案 0 :(得分:4)

您可以使用Background,如下所示:

Feature: nosql
  Background:
    Sometimes a user just wants to have flatfile storage like the
    classic Jekyll CMS.  When this is the case we should make sure
    that we adhere to classic folder and file structure, and store
    the generated content in _site unless the user decides that
    they want generation to be stored inside of memcached, then we
    should go ahead and use that.

    Given I have chosen flatfile storage for my site
    When I request a page, "the_page"

  Scenario: flatfile
    When I have chosen flatfile generation
    Then I should pull the page from "_site"

  Scenario: memcached
    When I have chosen memcached generation
    Then I should pull the page from memcached

答案 1 :(得分:1)

Background是选项,请参阅this

答案 2 :(得分:1)

通过查看您的功能,我会说它在测试堆栈中的50%比黄瓜低。我会从最终用户的角度编写测试,因为如果他们选择一个选项,给定一个页面,他们会看到该页面按照他们的预期返回给他们。一旦您的功能选项失败,请下载到您的低级测试框架,并围绕您正在使用的存储引擎类型编写测试。

使用Cucumber我总是努力寻求用户对系统的期望/响应反馈循环,无论该用户是一个人,另一个服务器,移动设备等。想想更多的黑盒式测试。

答案 3 :(得分:0)

Background的替代方法是使用Scenario Outline,虽然这些很容易过度使用并且会影响可读性 - 请使用您的最佳判断:

Scenario Outline: Choosing generation strategy
    Given I have chosen flatfile storage for my site
    When I request a page, "the_page"
    And I have chosen <generation_type> generation
    Then I should pull the page from <storage_type>
Examples:
| generation_type | storage_type |
| flatfile        | "_site"      |
| memcached       | memcached    |

你问题的另一部分有点不清楚。黄瓜/小黄瓜没有特征之间的依赖概念,并且有充分的理由。我认为memcached是不是一个功能,而是“向用户显示页面”功能的实现细节。

如果您尚未实现memcached缓存,那么该方案将失败,因此您应该向其添加@wip标记,并告诉Cucumber在CI版本中排除该标记。

如果满足memcached存储,则使flatfile方案失败取决于您如何实现这些步骤定义。 “我选择了flatfile generation”步骤应该将站点设置为使用flatfile(而不是memcached)生成,如果页面是从错误的源中提取的,则最后一步应该失败。