From 643d8a04580a76d07fe4ebe9177c6f34657e9eac Mon Sep 17 00:00:00 2001 From: Zach Dennis Date: Tue, 27 Jan 2009 12:47:24 -0500 Subject: [PATCH] Updated the regex used for locating fields with labels to match properly on label text that didn't end in a word character --- lib/webrat/core/locators/field_labeled_locator.rb | 2 +- spec/public/locators/field_labeled_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/lib/webrat/core/locators/field_labeled_locator.rb b/lib/webrat/core/locators/field_labeled_locator.rb index adaa2c2..0f3929c 100644 --- a/lib/webrat/core/locators/field_labeled_locator.rb +++ b/lib/webrat/core/locators/field_labeled_locator.rb @@ -20,7 +20,7 @@ module Webrat def matching_label_elements label_elements.select do |label_element| - text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i + text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}(\b|\Z)/i end end diff --git a/spec/public/locators/field_labeled_spec.rb b/spec/public/locators/field_labeled_spec.rb index 7a102df..0eaa2dd 100644 --- a/spec/public/locators/field_labeled_spec.rb +++ b/spec/public/locators/field_labeled_spec.rb @@ -154,4 +154,18 @@ describe "field_labeled" do with_an_id_of "element_42", :for => "The Label" end + describe "finding a field whose label ends with an non word character" do + using_this_html <<-HTML + +
+ + +
+ + HTML + + should_return_a Webrat::TextField, :for => "License #" + with_an_id_of "element_42", :for => "License #" + should_raise_error_matching /Could not find .* "Other License #"/, :for => "Other License #" + end end -- 1.6.1