require File.dirname(__FILE__) + "/../spec_helper"
module Simply
describe HTMLBuilder do
before(:each) do
@builder = HTMLBuilder.new
end
it "should create a self-closing hr tag" do
@builder.br
@builder.to_s.should == "
"
end
it "should create a self closing hr tag" do
@builder.hr
@builder.to_s.should == "
foo
" end it "should contain the text inside the paragraph tags" do @builder.p "bar baz" @builder.to_s.should == "bar baz
" end it "should take options with a string given" do @builder.p "bar baz", :class => :something @builder.to_s.should == "bar baz
" end it "should have a paragraph tag which takes a block" do @builder.p do text "foo" end @builder.to_s.should == "foo
" end Simply::HTMLBuilder::SELF_CLOSING_TAGS.each do |tag| it "should have the tag #{tag}" do @builder.send(tag) @builder.to_s.should == "<#{tag} />" end end it "should set options given to a self-closing tag" do @builder.img :src => "foo" @builder.to_s.should == "" end it "should set two options to a self-closing tag" do @builder.img :src => "foo", :alt => :some_text out = @builder.to_s out.should =~ /foo
' end Simply::HTMLBuilder::BLOCK_TAGS.each do |tag| it "should have the #{tag} tag" do @builder.send(tag, "foo") @builder.to_s.should == "<#{tag}>foo#{tag}>" end it "should contain the text inside the #{tag} tags" do @builder.send(tag, "bar baz") @builder.to_s.should == "<#{tag}>bar baz#{tag}>" end it "should take options with a string given" do @builder.send(tag, "bar baz", :class => :something) @builder.to_s.should == "<#{tag} class=\"something\">bar baz#{tag}>" end it "should have a paragraph tag which takes a block" do @builder.send(tag) do text "foo" end @builder.to_s.should == "<#{tag}>foo#{tag}>" end end it "should raise an argument error when calling a closing tag with no options" do lambda { @builder.p }.should raise_error(ArgumentError) end it "should escape special html values" do @builder.h1 'Apples & Oranges' @builder.to_s.should == "