The DomAssertions now also strip surrounding whitespace inside tags.

This commit is contained in:
Eloy Duran
2009-09-25 17:46:21 +02:00
parent deac481eb7
commit b18248ff05
2 changed files with 6 additions and 14 deletions

View File

@@ -4,7 +4,8 @@ module ActionController
def self.strip_whitespace!(nodes)
nodes.reject! do |node|
if node.is_a?(HTML::Text)
node.to_s.strip.empty?
node.content.strip!
node.content.empty?
else
strip_whitespace! node.children
false

View File

@@ -6,8 +6,10 @@ class DomAssertionsTest < ActionView::TestCase
@html_only = '<ul><li>foo</li><li>bar</li></ul>'
@html_with_meaningless_whitespace = %{
<ul>
<li>foo</li>
<li>bar</li>
<li>\tfoo </li>
<li>
bar
</li>
</ul>
}
@more_html_with_meaningless_whitespace = %{<ul>
@@ -15,7 +17,6 @@ class DomAssertionsTest < ActionView::TestCase
<li>foo</li>
<li>bar</li></ul>}
@html_with_meaningful_whitespace = '<ul><li> foo </li><li> bar </li></ul>'
end
test "assert_dom_equal strips meaningless whitespace from expected string" do
@@ -30,12 +31,6 @@ class DomAssertionsTest < ActionView::TestCase
assert_dom_equal @more_html_with_meaningless_whitespace, @html_with_meaningless_whitespace
end
test "assert_dom_equal does not strip important whitespace" do
assert_assertion_fails do
assert_dom_equal @html_with_meaningful_whitespace, @html_only
end
end
test "assert_dom_not_equal strips meaningless whitespace from expected string" do
assert_assertion_fails { assert_dom_not_equal @html_with_meaningless_whitespace, @html_only }
end
@@ -50,10 +45,6 @@ class DomAssertionsTest < ActionView::TestCase
end
end
test "assert_dom_not_equal does not strip important whitespace" do
assert_dom_not_equal @html_with_meaningful_whitespace, @html_only
end
private
def assert_assertion_fails