# encoding: utf-8 require 'bacon' $:.unshift File.expand_path('../../lib', __FILE__) require "fragment" describe 'Fragment' do def fragment(&block); Fragment.new(&block).to_s; end it "Builds simple tags" do fragment{ br }.should == '
' fragment{ p }.should == '

' end it "Opens and closes tags" do fragment{ p{} }.should == '

' fragment{ div{} }.should == '
' end it "Nests tags" do fragment{ p{ br } }.should == '


' end it "Builds deeply nested tags" do fragment do p do div do ol do li end end end end.should == '

' end it "Builds deeply nested tags with repetition" do fragment do p do div do ol do li li end ol do li li end end end end.should == '

' end it "Builds deeply nested tags with strings" do fragment do p do div {'Hello, World'} end end.should == '

Hello, World

' end it "Allows to write directly if needed" do fragment do write "" end.should == '' end it "Builds a full HTML page" do fragment do doctype html do head do title {"Hello World"} end body do h1 {"Hello World"} end end end.should == "\nHello World

Hello World

" end it "Builds with some ruby inside" do fragment do table do tr do %w[one two three].each do |s| td{s} end end end end.should == '
onetwothree
' end it "Builds escapeable attributes" do fragment { a(:href => "http://example.org/?a=one&b=two") { "Click here" } }.should == "Click here" end it "Should accept attributes in a string" do fragment{ input("type='text'") }.should == "" end it 'Should accept symbols as attributes' do input = fragment{ input(:type => :text, :value => :one) } input.should =~ /type='text'/ input.should =~ /value='one'/ end it 'Builds tags with prefix' do fragment{ tag "prefix:local" }.should == '' end it 'Builds tags with a variety of characters' do # with "-" fragment{ tag "hello-world" }.should == '' # with Hiragana fragment{ tag "あいうえお" }.should == '<あいうえお />' end it "Has a practicle way to add attributes like 'selected' based on boolean" do @selected = false fragment do option({:name => 'opt', :selected => @selected}) option(:name => 'opt', :selected => !@selected) option(:name => 'opt', :selected => @i_am_nil) end.should == "