From 0f7a277c577a3cdf5765147066ec80e0b570cd1b Mon Sep 17 00:00:00 2001 From: Miha Filej Date: Thu, 13 Nov 2008 15:00:24 +0100 Subject: [PATCH] Make Webrat::Label#text strip out newlines --- lib/webrat/core/label.rb | 6 +++++- spec/api/field_labeled_spec.rb | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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