黄瓜 + webrat:检查出现两次的文本

发布于 2024-08-03 00:28:33 字数 666 浏览 5 评论 0原文

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

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 

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

I am working on a rails app to self teach BDD and testing in general. Using cucumber + webrat + rspec, after railcasts video tuts.
In this app a quiz has_many questions. The view I am testing should render the question twice and non contiguously. (not testing contiguity here)
I have a cucumber scenario aimed at checking this

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 

My step is defined like this:

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

I tested the regex with a tool, and it seems to work, but the test fails on cucumber.
I googled for some documentation, but webrat's only documentation is the API docs; I wasn't able to get the response displayed as text.
Any suggestion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百思不得你姐 2024-08-10 00:28:33

您是否尝试过响应。正文

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

Have you tried response.body

Then /^I should see "([^\"]*)" twice$/ do |text|
  regexp = Regexp.new(text + "(.+)" + text)
  response.body.should contain(regexp)
end
淡写薰衣草的香 2024-08-10 00:28:33

我必须修改达米安的答案才能使其跨界工作。

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

I had to modify Damian's answer to get this to work across lines.

Then /^I should see "([^\"]*)" twice$/ do |text|
  regexp = Regexp.new(text + "(.+)" + text, Regexp::MULTILINE)
  response.body.should contain(regexp)
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文