黄瓜 +水豚检查多次出现的文本
我想检查给定的字符串在某些情况下是否出现多次,
我在其他地方找到了这个:
Then /^I should see "([^\"]*)" twice$/ do |text|
regexp = Regexp.new(text + "(.+)" + text)
response.body.should contain(regexp)
end
这是为 webrat 编写的。我试图用 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
这让我期望 #has_xpath("//*") 返回 true,得到 false
我还尝试了上述正则表达式的多行变体。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在弄乱了正则表达式后最终使用了解决方案。我认为“([^/])”会将某些内容作为正则表达式,而不是“([^”])”将某些内容作为纯文本:
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: