require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe Garterbelt::View do class BasicView < Garterbelt::View def content end def alt_content end end before do @view = BasicView.new end describe 'rendering' do it 'clears the output on start' do @view.output = 'Foo the magic output!' @view.render @view.output.should_not include 'Foo the magic output!' end describe 'methods' do it 'renders the :content method by default' do @view.should_receive(:content) @view.render end it 'renders an alternate method when requested' do @view.should_receive(:foo) @view.render(:foo) end end it 'returns the output' do @view.render.should === @view.output end describe "render_buffer" do before do @hr = Garterbelt::ContentTag.new(:view => @view, :type => :hr) @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.render_buffer @view.buffer.should == [] end it 'will call render on each tag in the buffer' do @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.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.render.should == "
\W*