require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
module Nokogiri
module HTML
class TestBuilder < Nokogiri::TestCase
def test_hash_as_attributes
builder = Nokogiri::HTML::Builder.new do
div(:id => 'awesome') {
h1 "america"
}
end
assert_equal('
america
',
builder.to_html.gsub(/\n/, ''))
end
def test_has_ampersand
builder = Nokogiri::HTML::Builder.new do
div.rad.thing! {
text ""
b "hello & world"
}
end
assert_equal(
'<awe&some>hello & world
',
builder.to_html.gsub(/\n/, ''))
end
def test_multi_tags
builder = Nokogiri::HTML::Builder.new do
div.rad.thing! {
text ""
b "hello"
}
end
assert_equal(
'<awesome>hello
',
builder.doc.to_html.gsub(/\n/, ''))
end
def test_attributes_plus_block
builder = Nokogiri::HTML::Builder.new do
div.rad.thing! {
text ""
}
end
assert_equal('<awesome>
',
builder.doc.to_html.chomp)
end
def test_builder_adds_attributes
builder = Nokogiri::HTML::Builder.new do
div.rad.thing! "tender div"
end
assert_equal('tender div
',
builder.doc.to_html.chomp)
end
def test_bold_tag
builder = Nokogiri::HTML::Builder.new do
b "bold tag"
end
assert_equal('bold tag', builder.doc.to_html.chomp)
end
def test_html_then_body_tag
builder = Nokogiri::HTML::Builder.new do
html {
body {
b "bold tag"
}
}
end
assert_equal('bold tag',
builder.doc.to_html.chomp)
end
end
end
end