From 9b43961643e4e283f31100ca678d766befe7fa6e Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Tue, 28 Oct 2008 16:02:35 -0400 Subject: [PATCH] Allow clicking links by a regular expression --- lib/webrat/core/link.rb | 8 +++++++- spec/api/clicks_link_spec.rb | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/webrat/core/link.rb b/lib/webrat/core/link.rb index e478494..89e532f 100644 --- a/lib/webrat/core/link.rb +++ b/lib/webrat/core/link.rb @@ -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 diff --git a/spec/api/clicks_link_spec.rb b/spec/api/clicks_link_spec.rb index 9b1e8be..3bfe6f7 100644 --- a/spec/api/clicks_link_spec.rb +++ b/spec/api/clicks_link_spec.rb @@ -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 + Link text + 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