require 'spec_helper' describe Arbre do setup_arbre_context! it "should render a single element" do content = span("Hello World") content.to_s.should == <<-HTML Hello World HTML end it "should render a child element" do content = span do span "Hello World" end content.to_s.should == <<-HTML Hello World HTML end it "should render an unordered list" do content = ul do li "First" li "Second" li "Third" end content.to_s.should == <<-HTML HTML end it "should return the correct object" do list_1 = ul list_2 = li list_1.should be_instance_of(Arbre::HTML::Ul) list_2.should be_instance_of(Arbre::HTML::Li) end it "should allow local variables inside the tags" do first = "First" second = "Second" content = ul do li first li second end content.to_s.should == <<-EOS EOS end it "should add children and nested" do content = div do ul li do li end end content.to_s.should == <<-HTML
  • HTML end it "should pass the element in to the block if asked for" do content = div do |d| d.ul do li end end content.to_s.should == <<-HTML
    HTML end it "should move content tags between parents" do content = div do span(ul(li)) end content.to_s.should == <<-HTML
    HTML end it "should add content to the parent if the element is passed into block" do content = div do |d| d.id = "my-tag" ul do li end end content.to_s.should == <<-HTML
    HTML end it "should have the parent set on it" do item = nil list = ul do li "Hello" item = li "World" end item.parent.should == list end ["Hello World", 1, 1.5].each do |value| it "should append the return value of '#{value}' when no other children added to the DOM" do li do value end.to_s.should == "
  • #{value}
  • \n" end end ["Hello World", 1, 1.5].each do |value| it "should not append the return value of '#{value}' when children have been added to the DOM" do li do text_node("Already Added") value end.to_s.should == "
  • Already Added
  • \n" end end describe "text nodes" do it "should turn strings into text nodes" do li do "Hello World" end.children.first.should be_instance_of(Arbre::HTML::TextNode) end end describe "self-closing nodes" do it "should not self-close script tags" do tag = script :type => 'text/javascript' tag.to_s.should == <<-HTML HTML end it "should self-close meta tags" do tag = meta :content => "text/html; charset=utf-8" tag.to_s.should == <<-HTML HTML end it "should self-close link tags" do tag = link :rel => "stylesheet" tag.to_s.should == <<-HTML HTML end end describe "html safe" do it "should escape the contents" do span("
    ").to_s.should == <<-HTML <br /> HTML end it "should return html safe strings" do span("
    ").to_s.should be_html_safe end it "should not escape html passed in" do span(span("
    ")).to_s.should == <<-HTML <br /> HTML end it "should escape string contents when passed in block" do span { span { "
    " } }.to_s.should == <<-HTML <br /> HTML end it "should escape the contents of attributes" do span(:class => "
    ").to_s.should == <<-HTML HTML end end end