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)
|
def matches_text?(link_text)
|
||||||
html = text.gsub(' ',' ')
|
html = text.gsub(' ',' ')
|
||||||
|
|
||||||
|
if link_text.is_a?(Regexp)
|
||||||
|
matcher = link_text
|
||||||
|
else
|
||||||
matcher = /#{Regexp.escape(link_text.to_s)}/i
|
matcher = /#{Regexp.escape(link_text.to_s)}/i
|
||||||
|
end
|
||||||
|
|
||||||
html =~ matcher || title =~ matcher
|
html =~ matcher || title =~ matcher
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,6 +46,14 @@ describe "clicks_link" do
|
|||||||
@session.clicks_link "Link text", :method => :put
|
@session.clicks_link "Link text", :method => :put
|
||||||
end
|
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
|
it "should click rails javascript links with authenticity tokens" do
|
||||||
@session.response_body = <<-EOS
|
@session.response_body = <<-EOS
|
||||||
<a href="/posts" onclick="var f = document.createElement('form');
|
<a href="/posts" onclick="var f = document.createElement('form');
|
||||||
|
Loading…
Reference in New Issue
Block a user