Sha256: 3739fc07bc85668fd73f12a25b710cd16f7c3b87d1fec7e8166ae16cc3a9a323

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'

describe InlineTemplates do
  describe 'render' do
    it 'builds elements' do
      test_rit do
        ~ span('test')
      end.should == "<span>test</span>"
    end

    it 'builds multiple elements' do
      test_rit do
        ~ span('test 1')
        ~ span('test 2')
      end.should == "<span>test 1</span><span>test 2</span>"
    end

    it 'captures' do
      test_rit do
        ~ div do
          ~ span('test')
        end
      end.should == "<div><span>test</span></div>"
    end

    it 'handles locals and conditionals' do
      locals = {
        :cond => true,
        :a => 'foo',
        :b => 'bar'
      }

      test_block = proc do
        if cond
          ~ a
        else
          ~ b
        end
      end

      test_rit(locals, &test_block).should == "foo"
      locals[:cond] = false
      test_rit(locals, &test_block).should == "bar"
    end

    it 'supports response postprocessing' do
      test_rit do
        e1 = div 'foo'
        e2 = span 'bar'

        ~ (e1 + e2)
      end.should == "<div>foo</div><span>bar</span>"
    end

    it 'properly handles nested blocks' do
      locals = { :list => [ '1', '2', '3', '4' ] }
      test_rit(locals) do
        ~ ul do
          list.each do |item|
            ~ li(item)
          end
        end
      end.should == '<ul><li>1</li><li>2</li><li>3</li><li>4</li></ul>'
    end

    it 'implements t helper' do
      test_rit do
        ~ t('<br />')
      end.should == "&lt;br /&gt;"
    end

    it 'implements h helper' do
      test_rit do
        ~ h('<br />')
      end.should == "<br />"
    end

    it 'passes instance variables' do
      test_rit do
        ~ t(@virtual_path)
      end.should == "(inline)"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inline_templates-0.0.1 spec/inline_templates_spec.rb