From db168bedec17c92a591ab598458ce7dddfd0e3cd Mon Sep 17 00:00:00 2001 From: Noah Davis Date: Wed, 13 Jan 2010 16:42:57 -0500 Subject: [PATCH] Make "should contain" ignore extra whitespace when doing string comparisons --- History.txt | 3 ++- lib/webrat/core/matchers/have_content.rb | 2 +- spec/public/matchers/contain_spec.rb | 23 ++++++++--------------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/History.txt b/History.txt index 0d9900c..c6513a6 100644 --- a/History.txt +++ b/History.txt @@ -1,5 +1,6 @@ * Bug fixes - + + * Make "should contain" ignore extra whitespace when doing string comparisons (Noah Davis) * Make selenium matchers handle negative match more consistently with positive match (Luke Melia) == 0.6.0 / 2009-11-28 diff --git a/lib/webrat/core/matchers/have_content.rb b/lib/webrat/core/matchers/have_content.rb index c3b6f33..24827ca 100644 --- a/lib/webrat/core/matchers/have_content.rb +++ b/lib/webrat/core/matchers/have_content.rb @@ -12,7 +12,7 @@ module Webrat case @content when String - @element.include?(@content) + @element.gsub(/\s+/, ' ').include?(@content) when Regexp @element.match(@content) end diff --git a/spec/public/matchers/contain_spec.rb b/spec/public/matchers/contain_spec.rb index e0677ac..40017fb 100644 --- a/spec/public/matchers/contain_spec.rb +++ b/spec/public/matchers/contain_spec.rb @@ -3,21 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") describe "contain" do include Webrat::Matchers - before(:each) do - @body = <<-HTML -
-
hello, world!
-

Welcome "Bryan"

-

Welcome 'Bryan'

-

Welcome 'Bryan"

- -
- HTML - end - before(:each) do @body = <<-EOF
@@ -34,6 +19,14 @@ describe "contain" do it "should call element#matches? when the argument is a regular expression" do @body.should contain(/hello, world/) end + + it "should treat newlines as spaces" do + "
it takes\ndifferent strokes
".should contain("it takes different strokes") + end + + it "should multiple spaces as a single space" do + "
it takes different strokes
".should contain("it takes different strokes") + end end describe "asserts for contains," do