Sha256: 5560e9982b2f01e719fe1fa212c1b20d19d768def4b2b8351822781973796540

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe Garterbelt::View, 'Partials' do
  describe '#partial' do
    before do
      @view = Garterbelt::View.new
      @view.output = "Foo You!\n"
      @view.level = 3
      @view.buffer = ['foo', 'bar']
    end
    
    describe 'with an instance' do
      before do
        @child_instance = Garterbelt::View.new
      end
      
      it 'sets the curator of the instance to the current view' do
        @child_instance.should_receive(:curator=).with(@view)
        @view.partial(@child_instance)
      end
      
      it 'adds the instance to the curator view buffer' do
        @view.partial(@child_instance)
        @view.buffer.should include @child_instance
      end
    end
    
    describe 'with a class and initialization options' do
      class PartedOut < Garterbelt::View
        needs :x => 'x'
        def content
          text "foo #{x}"
        end
      end
      
      it 'constructs a new instance' do
        @part = PartedOut.new
        PartedOut.should_receive(:new).and_return(@part)
        @view.partial(PartedOut, :x => '!= x')
      end
      
      it 'adds the instance to the buffer' do
        @view.partial(PartedOut, :x => '!= y?')
        partial = @view.buffer.last
        partial.is_a?(PartedOut).should be_true
      end
      
      
      it 'has the curator as the current view' do
        @view.partial(PartedOut, :x => 'what about z?')
        partial = @view.buffer.last
        partial.curator.should == @view
      end
      
      it 'has the correct initalization options' do
        @view.partial(PartedOut, :x => '= foo')
        partial = @view
      end
      
      it 'passes along the block, wait do views take blocks right now?'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
garterbelt-0.0.4 spec/view/view_partial_spec.rb
garterbelt-0.0.3 spec/view/view_partial_spec.rb
garterbelt-0.0.2 spec/view/view_partial_spec.rb