Allow clicking links by a regular expression

This commit is contained in:
Bryan Helmkamp 2008-10-28 16:02:35 -04:00
parent 738798d4e6
commit 9b43961643
2 changed files with 15 additions and 1 deletions

View File

@ -23,7 +23,13 @@ module Webrat
def matches_text?(link_text)
html = text.gsub(' ',' ')
matcher = /#{Regexp.escape(link_text.to_s)}/i
if link_text.is_a?(Regexp)
matcher = link_text
else
matcher = /#{Regexp.escape(link_text.to_s)}/i
end
html =~ matcher || title =~ matcher
end

View File

@ -46,6 +46,14 @@ describe "clicks_link" do
@session.clicks_link "Link text", :method => :put
end
it "should click links by regexp" do
@session.response_body = <<-EOS
<a href="/page">Link text</a>
EOS
@session.should_receive(:get).with("/page", {})
@session.clicks_link /link [a-z]/i
end
it "should click rails javascript links with authenticity tokens" do
@session.response_body = <<-EOS
<a href="/posts" onclick="var f = document.createElement('form');