【问题标题】:cucumber + webrat: checking text appearing twicecucumber + webrat:检查出现两次的文本
【发布时间】:2011-02-03 10:20:42
【问题描述】:

我正在开发一款用于自学 BDD 和一般测试的 Rails 应用程序。在 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 文档;我无法将响应显示为文本。 有什么建议吗?

【问题讨论】:

    标签: rspec cucumber webrat


    【解决方案1】:

    您尝试过回复吗。正文

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

    【讨论】:

    • 当你陷入代码中很容易错过这些东西!
    【解决方案2】:

    我必须修改 Damian 的答案才能让它跨行工作。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-31
      • 2011-01-22
      • 2010-11-25
      • 1970-01-01
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多