黄瓜和DELETE与Mongoid

时间:2011-08-18 19:56:59

标签: ruby-on-rails ruby cucumber mongoid

所以,我目前正在尝试测试一个与Mongoid with Cucumber连接的Rails应用程序。我有一切设置(或者我相信),以便运行以下测试:

Feature: Create and manage about entries
  In order to use the about data effectively
  As an application consumer
  I want to create and manage some about entries

  Scenario: Create about entries
    Given the following abouts exist
      | title             |   body_copy   |
      | "About entry #1"  | "hello body!" |
    When I go to the list of about entries
    Then I should see "About entry #1"

  Scenario: Create and retreive specific about entry
    Given the following abouts exist
      | id                        | title             |   body_copy   |
      | 4e4d37756ea257f031000003  | "About entry #1"  | "hello body!" |
    When I go to about entry with id 4e4d37756ea257f031000003
    Then I should see "About entry #1"

在我的路径文件中,我有以下条目来支持上述测试:

when /^the list of about entries$/i
  '/abouts'
when /^about entry with id (.+)$/i
  "/abouts/#{$1}"

这些测试效果很好。但是,我需要测试删除操作。我在网上进行了一些研究但是一切似乎都要通过UI来删除这些项目而我遇到的问题是我的Rails应用程序只提供JSON文件和JSON文件,我需要一种更好的(更程序化的)测试方式而不需要用户界面涉及到。对于模拟,我使用的是Pickle内置的默认模拟。我愿意在必要时使用其他模拟软件,例如工厂女孩,但是你必须给我一些详细的反馈,我可以如何连接它。我目前的删除测试(不起作用)是:

  Scenario: Delete about
    Given the following abouts exist
      | title   | body_copy    |
      | title 1 | body_copy 1  |
      | title 2 | body_copy 2  |
      | title 3 | body_copy 3  |
      | title 4 | body_copy 4  |
    When I delete the 3rd about
    Then I should see the following abouts:
      | Title   | body_copy    |
      | title 1 | body_copy 1  |
      | title 2 | body_copy 2  |
      | title 4 | body_copy 4  |

问题是自动生成的测试(见上文)使用click_link "Destroy"方法调用,但这不起作用。

1 个答案:

答案 0 :(得分:0)

您需要更改删除步骤的实现(如果您使用Cucumber生成的默认值,则在您的web_steps.rb中)发送DELETE HTTP请求。我建议使用RestClient gem,但还有很多其他选择。

目前处于PragProg测试阶段的Cucumber Book有一章介绍如何使用Cucumber来测试这样的REST API。