【发布时间】:2011-08-18 19:56:59
【问题描述】:
所以,我目前正在尝试用 Cucumber 测试一个用 Mongoid 连接的 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 文件,我需要一种更好(更编程)的方式来测试没有UI 参与其中。就模拟而言,我使用的是 Pickle 内置的默认模拟。如有必要,我愿意使用其他模拟软件,例如 factory-girl,但你必须给我一些详细的反馈,我该如何连接它。我目前的删除测试(不起作用)是:
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" 方法调用,但这不起作用。
【问题讨论】:
标签: ruby-on-rails ruby cucumber mongoid