aboutsummaryrefslogtreecommitdiff
path: root/spec/unit/renderer/read_template_path_spec.rb
blob: 86557779f8d51314583ab952ad6de385c01b02b3 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
    Dir.stub(:[]) do |arg|
      if arg == 'foo/**/*.*'
        file_list 
      else
        []
      end
    end
  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

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

    it_behaves_like 'a template loader'
  end

  it 'creates an empty templates list without templates in path' do
    subject = Zero::Renderer.new("bar", {})
    subject.read_template_path!

    subject.templates.should eq({})
  end
end