diff --git a/lib/webrat/core/label.rb b/lib/webrat/core/label.rb index 4f3d77d..7107f10 100644 --- a/lib/webrat/core/label.rb +++ b/lib/webrat/core/label.rb @@ -11,7 +11,11 @@ module Webrat end def text - @element.inner_text + str = @element.inner_text + str.gsub!("\n","") + str.strip! + str.squeeze!(" ") + str end end diff --git a/spec/api/field_labeled_spec.rb b/spec/api/field_labeled_spec.rb index 6c0e955..ebfe2f2 100644 --- a/spec/api/field_labeled_spec.rb +++ b/spec/api/field_labeled_spec.rb @@ -108,4 +108,21 @@ describe "field_labeled" do with_an_id_of "element_42", :for => "The Label" should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label" end + + describe "finding a field with it's label containing newlines" do + using_this_html <<-HTML +
+ + +
+ HTML + + should_return_a Webrat::TextField, :for => "A label with a link on it's own line" + with_an_id_of "element_42", :for => "A label with a link on it's own line" + should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label" + end + end