summaryrefslogtreecommitdiff
path: root/spec/unit/renderer/read_template_path_spec.rb
blob: 85220074091c2c85c69300775c307192d1f2c1f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'spec_helper'

describe Zero::Renderer, 'read_template_path!' do
  subject { Zero::Renderer.new(template_path, type_map) }
  let(:template_path) { 'foo' }
  let(:file_list) { ['./foo/welcome/index.html.erb'] }

  before :each do
    subject.stub(:search_files).and_return(file_list)
  end

  shared_examples_for 'a template loader' do
    it 'creates a template tree' do
      subject.read_template_path!
      subject.templates['welcome/index'].should eq(result)
    end
  end

  context 'without mapping' do
    let(:type_map) { {} }
    let(:result) { { 'html' => './foo/welcome/index.html.erb' } }

    it_behaves_like 'a template loader'
  end

  context 'with a single mapping' do
    let(:type_map) { {'html' => 'text/html' } }
    let(:result) { { 'text/html' => './foo/welcome/index.html.erb' } }

    it_behaves_like 'a template loader'
  end

  context 'with multiple mappings' do
    let(:type_map) { {'html' => ['text/html', 'text/xml'] } }
    let(:result) { {
      'text/html' => './foo/welcome/index.html.erb',
      'text/xml'  => './foo/welcome/index.html.erb'
    } }

    it_behaves_like 'a template loader'
  end
end