【发布时间】:2012-08-01 22:59:47
【问题描述】:
我正在使用 Cucumber 测试基于 Rails 的 Web 服务中的端到端应用程序行为。我目前有一个如下所示的场景大纲(在此构成一个假设场景,即与另一个用户一起创建用户):
Scenario Outline: Create a user with another user
Given I want to create a user as a user "<user>"
When I create a user with name "<name>"
And the user's age is "<age>"
Then then the response should be "<response>"
Scenarios: Create user with 3 args
| user | name | age | response |
| bob | joe | 25 | <some_xml_response> |
我有点难以弄清楚我应该如何为这个大纲编写步骤定义。基本上,我目前正在连接一个 XML blob(用于姓名+年龄),并且需要做一些类似于 rspec 使用 :post 发布到控制器并查看响应的事情。我的步骤定义目前如下所示:
Given /^I want to create a user with another user "([^"]*)"$/ do |user|
@reqxml << "<user><creator>#{user}</creator>"
end
When /^I create a user with name "([^"]*)"$/ do |name|
@reqxml << "<name>#{name}</name>
end
And /^the user's age is "([^"]*)"$/ do |age|
@reqxml << "<age>#{age}</age>"
end
Then /^then the response should be "([^"]*)"$/ do |response|
# ?? not sure if I can use rspec :post here?
end
改进这个 Cucumber 大纲的最佳方法是什么?我还有很多要测试的。在 rspec 中这是相当直截了当的,也许正确的答案是将其粘贴在 RSpec 中。但我真的很想更好地利用 Cucumber,并通过端到端用户故事测试获得更好的“更大”图景。
【问题讨论】:
标签: ruby-on-rails ruby rspec cucumber