3

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?

nutsmuggler
  • 1,707
  • 5
  • 21
  • 27

2 Answers2

6

Have you tried response.body

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

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
ryansch
  • 79
  • 1
  • 10