Allow clicking links by a regular expression
This commit is contained in:
parent
738798d4e6
commit
9b43961643
|
@ -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
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue