Sha256: 8e1789a931d96640ba37695733c1d62b3dde4aef900e72407461dc872979b79c

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

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

describe Garterbelt::Comment do
  before :all do
    @view = MockView.new
  end
  
  describe 'basics' do
    it 'is decends from Renderer' do
      Garterbelt::Comment.ancestors.should include Garterbelt::Renderer
    end
    
    it 'has conent' do
      comment = Garterbelt::Comment.new(:view => @view, :content => "Initializing ...")
      comment.content.should == "Initializing ..."
      comment.content = "foo"
      comment.content.should == "foo"
    end
    
    it 'raises an error when initializing without content' do
      lambda{ Garterbelt::Comment.new(:view => @view) }.should raise_error( 
        ArgumentError, ":content option required for Garterbelt::Comment initialization" 
      )
    end
    
    it 'has a smaller pool size' do
      Garterbelt::Comment._pool.max_size.should == 1000
    end
  end
  
  describe 'render' do
    before do
      @view = MockView.new
      @comment = Garterbelt::Comment.new(:view => @view, :content => 'Render me')
    end
    
    it 'raises an error with block content' do
      @comment.content = lambda { puts "foo" }
      lambda{ @comment.render }.should raise_error(ArgumentError, "Garterbelt::Comment does not take block content")
    end
    
    it 'it adds the content to the output' do
      @comment.render
      @view.output.should include "Render me"
    end
    
    it 'builds the right header tag' do
      @comment.render
      @view.output.should match /<!-- Render me/
    end
    
    it 'builds the right footer tag' do
      @comment.render
      @view.output.should match /Render me -->/
    end
    
    it 'indents to the view level' do
      @comment.render
      @view.output.should match /^\W{4}<!-- Render me/
    end
    
    it 'does not escape the content' do
      @comment.content = "<div>foo</div>"
      @comment.render
      @view.output.should include "<div>foo</div>"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
garterbelt-0.0.4 spec/renderers/comment_spec.rb
garterbelt-0.0.3 spec/renderers/comment_spec.rb
garterbelt-0.0.2 spec/renderers/comment_spec.rb