test/element_node_test.rb in undies-3.0.0.rc.1 vs test/element_node_test.rb in undies-3.0.0.rc.2
- old
+ new
@@ -9,11 +9,11 @@
class BasicTests < Assert::Context
desc 'an element node'
before do
# io test with :pp 1 so we can test newline insertion
# io test with level 1 so we can test element start tag writing
- @io = Undies::IO.new(@out = "", :pp => 1, :level => 1)
+ @io = Undies::IO.new(@out = "", :pp => 1, :level => 2)
@e = Undies::Element.open(:div, "hi")
@en = Undies::ElementNode.new(@io, @e)
end
subject { @en }
@@ -144,24 +144,26 @@
assert_equal @en1, subject.element_node(@en1)
end
should "write out the start tag with IO#newline when an element is given" do
subject.element_node(@en1)
- assert_equal "<div>#{@io.newline}", @out
+ assert_equal "#{@io.line_indent(-1)}<div>#{@io.newline}", @out
end
should "write out any cached content and cache new markup when given" do
subject.element_node @en1
subject.element_node @en2
- assert_equal "<div>#{@io.newline}#{@io.line_indent}<strong>blah</strong>#{@io.newline}", @out
+ assert_equal "#{@io.line_indent(-1)}<div>#{@io.newline}#{@io.line_indent}<strong>blah</strong>#{@io.newline}", @out
assert_equal @en2, subject.cached
end
should "write out the end tag with IO#newline indented when popped" do
subject.element_node(@en1)
+ expected = "#{@io.line_indent(-1)}<div>#{@io.newline}#{@io.line_indent}<strong>blah</strong>#{@io.newline}#{@io.line_indent(-1)}</div>#{@io.newline}"
subject.pop
- assert_equal "<div>#{@io.newline} <strong>blah</strong>#{@io.newline}</div>#{@io.newline}", @out
+
+ assert_equal expected, @out
end
end
class PartialStartTagNotWrittenTests < AddContentStartTagNotWrittenTests
@@ -172,17 +174,18 @@
assert_equal "partial markup", subject.cached
end
should "write out the start tag with IO#newline when a partial is given" do
subject.partial("partial markup")
- assert_equal "<div>#{@io.newline}", @out
+ assert_equal "#{@io.line_indent(-1)}<div>#{@io.newline}", @out
end
should "write out the end tag with IO#newline indented when a partial is given" do
subject.partial(" partial markup\n")
+ expected = "#{@io.line_indent(-1)}<div>#{@io.newline}#{@io.line_indent}partial markup#{@io.newline}#{@io.line_indent(-1)}</div>#{@io.newline}"
subject.pop
- assert_equal "<div>#{@io.newline} partial markup\n</div>#{@io.newline}", @out
+ assert_equal expected, @out
end
end
class AttrsTests < AddContentStartTagNotWrittenTests
@@ -190,18 +193,18 @@
should "modify the parent element's tag attributes" do
subject.attrs(:test => 'value')
subject.element_node(@en1)
- assert_equal "<div test=\"value\">#{@io.newline}", @out
+ assert_equal "#{@io.line_indent(-1)}<div test=\"value\">#{@io.newline}", @out
end
should "not effect the start tag once child elements have been written" do
subject.attrs(:test => 'value')
subject.element_node(@en1)
subject.attrs(:another => 'val')
- assert_equal "<div test=\"value\">#{@io.newline}", @out
+ assert_equal "#{@io.line_indent(-1)}<div test=\"value\">#{@io.newline}", @out
end
end