spec/view/view_render_spec.rb in garterbelt-0.0.9 vs spec/view/view_render_spec.rb in garterbelt-0.1.0

- old
+ new

@@ -70,47 +70,47 @@ @input = Garterbelt::ContentTag.new(:view => @view, :type => :input) @img = Garterbelt::ContentTag.new(:view => @view, :type => :img) end it 'will clear the buffer' do - @view.buffer = [:foo] + @view._buffer = [:foo] @view.render_buffer - @view.buffer.should == [] + @view._buffer.should == [] end it 'will call render on each tag in the buffer' do - @view.buffer << @hr << @input << @img + @view._buffer << @hr << @input << @img @hr.should_receive(:render) @input.should_receive(:render) @img.should_receive(:render) @view.render_buffer end it 'will add non renderable items to the output as strings' do - @view.buffer << "foo " << :bar + @view._buffer << "foo " << :bar @view.render_buffer @view.output.should include 'foo bar' end end describe 'tag nesting' do it 'should render correctly at one layer deep' do - @view.buffer << Garterbelt::ClosedTag.new(:type => :hr, :view => @view) + @view._buffer << Garterbelt::ClosedTag.new(:type => :hr, :view => @view) @view.render.should == "<hr>\n" end describe 'second level' do before do - @view.buffer << Garterbelt::ContentTag.new(:type => :p, :view => @view) do - @view.buffer << Garterbelt::ClosedTag.new(:type => :hr, :view => @view) + @view._buffer << Garterbelt::ContentTag.new(:type => :p, :view => @view) do + @view._buffer << Garterbelt::ClosedTag.new(:type => :hr, :view => @view) end @view.render end it 'should leave an empty buffer' do - @view.buffer.should be_empty + @view._buffer.should be_empty end it 'should include the content' do @view.output.should include "<hr>" end @@ -120,16 +120,16 @@ end end describe 'multi level' do before do - @view.buffer << Garterbelt::ContentTag.new(:type => :form, :view => @view) do - @view.buffer << Garterbelt::ContentTag.new(:type => :fieldset, :view => @view) do - @view.buffer << Garterbelt::ContentTag.new(:type => :label, :view => @view, :attributes => {:for => 'email'}) do - @view.buffer << Garterbelt::ClosedTag.new(:type => :input, :view => @view, :attributes => {:name => 'email', :type => 'text'}) + @view._buffer << Garterbelt::ContentTag.new(:type => :form, :view => @view) do + @view._buffer << Garterbelt::ContentTag.new(:type => :fieldset, :view => @view) do + @view._buffer << Garterbelt::ContentTag.new(:type => :label, :view => @view, :attributes => {:for => 'email'}) do + @view._buffer << Garterbelt::ClosedTag.new(:type => :input, :view => @view, :attributes => {:name => 'email', :type => 'text'}) end - @view.buffer << Garterbelt::ContentTag.new(:type => :input, :view => @view, :attributes => {:type => 'submit', :value => 'Login or whatever'}) + @view._buffer << Garterbelt::ContentTag.new(:type => :input, :view => @view, :attributes => {:type => 'submit', :value => 'Login or whatever'}) end end @view.render end @@ -184,14 +184,30 @@ end describe 'block initalized content' do it 'has a #render_block method that renders that content' do @view = BasicView.new do - @view.buffer << Garterbelt::ContentTag.new(:type => :p, :view => @view, :content => 'Block level p tag') + @view._buffer << Garterbelt::ContentTag.new(:type => :p, :view => @view, :content => 'Block level p tag') end @view.render_block.should include "Block level p tag" end + + it 'passes the block to the content method' do + class PassItOn < Garterbelt::View + def content + p do + yield + end + end + end + + @view = PassItOn.new do + @view._buffer << Garterbelt::ContentTag.new(:type => :span, :view => @view, :content => 'spanning it up!') + end + + @view.render.should include "spanning it up!" + end end end describe 'renderers' do describe '#tag' do @@ -206,16 +222,16 @@ @view.tag(:p, "content", {:class => 'classy'}).is_a?(Garterbelt::ContentTag).should be_true end it 'adds it to the buffer' do tag = @view.tag(:p, "content", {:class => 'classy'}) - @view.buffer.should include tag + @view._buffer.should include tag end it 'works with block content' do tag = @view.tag(:p, "content", {:class => 'classy'}) do - @view.buffer << "foo" + @view._buffer << "foo" end tag.content.is_a?(Proc).should be_true end end @@ -231,30 +247,30 @@ @view.closed_tag(:hr, :class => 'linear').is_a?(Garterbelt::ClosedTag).should be_true end it 'adds it to the buffer' do tag = @view.closed_tag(:hr, :class => 'linear') - @view.buffer.should include tag + @view._buffer.should include tag end end describe '#non_escape_tag' do it 'calls #tag' do @view.should_receive(:tag) @view.non_escape_tag(:pre, "<div>content</div>", {:class => 'classy'}) end it 'sets and resets the escape when escape is originally set to true' do - @view.should_receive(:escape=).with(false).ordered + @view.should_receive(:_escape=).with(false).ordered @view.should_receive(:tag).ordered - @view.should_receive(:escape=).with(true).ordered + @view.should_receive(:_escape=).with(true).ordered @view.non_escape_tag(:pre, "<div>content</div>", {:class => 'classy'}) end it 'does not set the escape when set to false' do - @view.escape = false - @view.should_not_receive(:escape=) + @view._escape = false + @view.should_not_receive(:_escape=) @view.non_escape_tag(:pre, "<div>content</div>", {:class => 'classy'}) end end describe '#text' do @@ -270,11 +286,11 @@ @view.text("content") end it 'adds the Text object to the buffer' do @view.text("content") - text = @view.buffer.last + text = @view._buffer.last text.is_a?(Garterbelt::Text).should be_true text.content.should == 'content' end end @@ -283,19 +299,19 @@ @view.should_receive(:text).and_return('text') @view.raw_text("<div>foo</div>") end it 'sets escape before and after for a view that is set to escape' do - @view.should_receive(:escape=).with(false).ordered + @view.should_receive(:_escape=).with(false).ordered @view.should_receive(:text).and_return('text') - @view.should_receive(:escape=).with(true).ordered + @view.should_receive(:_escape=).with(true).ordered @view.raw_text("<div>foo</div>") end it 'does not set escape if the view is not escaping' do - @view.escape = false - @view.should_not_receive(:escape=) + @view._escape = false + @view.should_not_receive(:_escape=) @view.raw_text("<div>foo</div>") end end describe 'html tag helpers' do @@ -350,29 +366,29 @@ @view.comment_tag('This is a comment.').is_a?(Garterbelt::Comment).should be_true end it 'puts it on the buffer' do comment = @view.comment_tag("new comment now") - @view.buffer.last.should == comment + @view._buffer.last.should == comment end end describe 'doctype' do it 'makes a Doctype object' do @view.doctype(:html5).is_a?(Garterbelt::Doctype).should be_true end it 'puts it on the buffer' do doctype = @view.doctype - @view.buffer.last.should == doctype + @view._buffer.last.should == doctype end end describe 'xml' do it 'adds an xml to the buffer' do xml = @view.xml xml.is_a?(Garterbelt::Xml).should be_true - @view.buffer.last.should == xml + @view._buffer.last.should == xml end it 'makes a closed tag with default options' do xml = @view.xml xml.attributes[:version].should == 1.0 \ No newline at end of file