3

我正在开发一个 Rails 应用程序来自学 BDD 和一般测试。在 railcasts video tuts 之后使用 cucumber + webrat + rspec。在这个应用程序中,一个测验 has_many questions。我正在测试的视图应该两次且不连续地呈现问题。(这里不测试连续性)我有一个旨在检查这个的黄瓜场景

Given quiz titled "Pearl Jam" has questions named "Corduroy, Dissident"
When I go to the experiment page for quiz titled "Pearl Jam"
Then I should see "Corduroy" twice
And I should see "Dissident" twice 

我的步骤是这样定义的:

Then /^I should see "([^\"]*)" twice$/ do |text|
  regexp = Regexp.new(text + "(.+)" + text)
  response.should contain(regexp)
end 

我用一个工具测试了正则表达式,它似乎可以工作,但是在黄瓜上测试失败了。
我搜索了一些文档,但 webrat 的唯一文档是 API 文档;我无法将响应显示为文本。有什么建议吗?

4

2 回答 2

6

你有没有试过回应。身体

Then /^I should see "([^\"]*)" twice$/ do |text|
  regexp = Regexp.new(text + "(.+)" + text)
  response.body.should contain(regexp)
end
于 2009-08-28T13:44:35.150 回答
1

我不得不修改 Damian 的答案以使其跨行工作。

Then /^I should see "([^\"]*)" twice$/ do |text|
  regexp = Regexp.new(text + "(.+)" + text, Regexp::MULTILINE)
  response.body.should contain(regexp)
end
于 2011-02-03T02:20:42.017 回答