I want to check if a given string appears multiple times in some scenarios
I found this elsewhere:
Then /^I should see "([^\"]*)" twice$/ do |text|
regexp = Regexp.new(text + "(.+)" + text)
response.body.should contain(regexp)
end
Which was written for webrat. I’m trying to express it with Capybara:
Then /^I should see "([^"]*)" twice$/ do |text|
regexp = Regexp.new(text + "(.+)" + text)
if page.respond_to? :should
page.should have_xpath('//*', :text => regexp)
else
assert page.has_xpath?('//*', :text => regexp)
end
end
Which gives me expected #has_xpath(“//*”) to return true, got false
I also tried a multiline variant of the above regexp.
The solution I ended up using after messing with the regexp. I gather that “([^/])” will takes something as a regular expression versus “([^”])” taking something as plaintext: