Sha256: 3cd045b1adf0511484aa407394741231da093319eac15f87a5ae7b5c00bfa0f6

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

describe Hotcell::Commands::Include do
  def parse source
    Hotcell::Template.parse(source)
  end

  let(:resolver_class) do
    Class.new(Hotcell::Resolver) do
      attr_reader :templates
      def initialize templates
        @templates = templates.stringify_keys
      end

      def resolve path, context = nil
        templates[path] or raise 'Template not found'
      end
    end
  end
  let(:templates) { {
    template1: 'Hello',
    template2: 'Hello, {{ name }}',
    template3: '{{ name }} - {{ action }}'
  } }
  let(:resolver) { resolver_class.new templates }
  let(:render_options) { { shared: { resolver: resolver } } }

  describe '#render' do
    specify { parse("{{ include 'template0' }}").render(render_options).should =~ /Template not found/ }
    specify { parse("{{ include 'template1' }}").render!(render_options).should == 'Hello' }
    specify { parse("{{ include 'template2' }}").render(render_options).should == 'Hello, ' }
    specify { parse(
      "{{ include 'template2', name: 'Pyrosha' }}"
    ).render(render_options).should == 'Hello, Pyrosha' }
    specify { parse(
      "{{! name = Pyrosha; action = 'CRUSH!' }}{{ include 'template3', name: 'Hulk' }}"
    ).render(render_options).should == 'Hulk - CRUSH!' }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hotcell-0.3.0 spec/lib/hotcell/commands/include_spec.rb