Support &nbsp's as spaces in matching link text (Patch from Luke Melia)

This commit is contained in:
Bryan Helmkamp 2008-07-25 19:26:59 -04:00
parent 2e20267c90
commit 8405c6cfb0
2 changed files with 12 additions and 1 deletions

View File

@ -20,8 +20,9 @@ module Webrat
end end
def matches_text?(link_text) def matches_text?(link_text)
html = text.gsub(' ',' ')
matcher = /#{Regexp.escape(link_text.to_s)}/i matcher = /#{Regexp.escape(link_text.to_s)}/i
text =~ matcher || title =~ matcher html =~ matcher || title =~ matcher
end end
def text def text

View File

@ -29,6 +29,7 @@ describe "clicks_link" do
@session.clicks_delete_link "Link text" @session.clicks_delete_link "Link text"
end end
it "should click post links" do it "should click post links" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<a href="/page">Link text</a> <a href="/page">Link text</a>
@ -181,6 +182,15 @@ describe "clicks_link" do
@session.clicks_link "Link" @session.clicks_link "Link"
end end
it "should treat non-breaking spaces as spaces" do
@session.response_body = <<-EOS
<a href="/page1">This&nbsp;is&nbsp;a&nbsp;link</a>
EOS
@session.should_receive(:get).with("/page1", {})
@session.clicks_link "This is a link"
end
it "should click link within a selector" do it "should click link within a selector" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<a href="/page1">Link</a> <a href="/page1">Link</a>