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 'argument parsing' do describe 'render method' do it 'finds in as the first argument' do @view.should_receive(:bar) @view.render(:bar) end it 'finds it in the options' do @view.should_receive(:baz) @view.render :method => :baz end end describe ':style option' do it 'is found in options as the second argument' do @view.stub(:foo) @view.render(:foo, {:style => :minified}) @view.render_style.should == :minified end it 'is found when options are the first argument' do @view.stub(:content) @view.render(:style => :text) @view.render_style.should == :text end end 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*