click link by title

This commit is contained in:
Dan Barry 2008-07-18 11:32:41 -05:00
parent 66a5af0f56
commit 130f5a9d1b
2 changed files with 14 additions and 1 deletions

View File

@ -14,7 +14,8 @@ module Webrat
end end
def matches_text?(link_text) def matches_text?(link_text)
text =~ /#{Regexp.escape(link_text.to_s)}/i matcher = /#{Regexp.escape(link_text.to_s)}/i
text =~ matcher || title =~ matcher
end end
def text def text
@ -27,6 +28,10 @@ module Webrat
authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token} authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token}
end end
def title
@element['title']
end
def href def href
@element["href"] @element["href"]
end end

View File

@ -148,6 +148,14 @@ describe "clicks_link" do
@session.clicks_link "Link text" @session.clicks_link "Link text"
end end
it "should work with anchor titles" do
@session.response_body = <<-EOS
<a href="/page" title="Link title">Link text</a>
EOS
@session.expects(:get).with("/page", {})
@session.clicks_link "Link title"
end
it "should match the first matching link" do it "should match the first matching link" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<a href="/page1">Link text</a> <a href="/page1">Link text</a>