diff options
author | Gibheer <gibheer@gmail.com> | 2013-02-27 21:15:05 +0100 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2013-02-27 21:15:05 +0100 |
commit | 714c540e4b40c931be365d12c31bbe9cbdfa5fb9 (patch) | |
tree | b74dc71ea720484cebf74bb62a1deb0267682a23 /spec/unit | |
parent | d74f3da383908b26358014ffdfbc3d2e86473d6f (diff) |
reworked parts of the template finder
The template finder is now the instance to ask for templates. It was
already looking for them, so it should be able to handle questions
regarding the existence of templates too.
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/zero/renderer/template_finder/exist_for_types_predicate_spec.rb | 25 | ||||
-rw-r--r-- | spec/unit/zero/renderer/template_finder/exist_predicate_spec.rb | 15 | ||||
-rw-r--r-- | spec/unit/zero/renderer/template_finder/get_spec.rb | 27 | ||||
-rw-r--r-- | spec/unit/zero/renderer/template_finder/templates_spec.rb (renamed from spec/unit/zero/renderer/template_finder/get_templates_spec.rb) | 9 |
4 files changed, 68 insertions, 8 deletions
diff --git a/spec/unit/zero/renderer/template_finder/exist_for_types_predicate_spec.rb b/spec/unit/zero/renderer/template_finder/exist_for_types_predicate_spec.rb new file mode 100644 index 0000000..794a4c9 --- /dev/null +++ b/spec/unit/zero/renderer/template_finder/exist_for_types_predicate_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe Zero::Renderer::TemplateFinder, '#exist_for_types?' do + subject { described_class.new(template_path, type_map) } + let(:template_path) { 'spec/fixtures/templates/' } + let(:type_map) { {'html' => 'text/html'} } + let(:html_types) { ['text/html'] } + let(:foo_types) { ['foo/bar', 'bar/foo'] } + + it 'returns true when template exists' do + expect(subject.exist_for_types?('index', html_types)).to be(true) + end + + it 'returns false when template does not exist' do + expect(subject.exist_for_types?('not_found', html_types)).to be(false) + end + + it 'returns false when template for types does not exists' do + expect(subject.exist_for_types?('index', foo_types)).to be(false) + end + + it 'returns false when no types are defined' do + expect(subject.exist_for_types?('index', [])).to be(false) + end +end diff --git a/spec/unit/zero/renderer/template_finder/exist_predicate_spec.rb b/spec/unit/zero/renderer/template_finder/exist_predicate_spec.rb new file mode 100644 index 0000000..0444622 --- /dev/null +++ b/spec/unit/zero/renderer/template_finder/exist_predicate_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe Zero::Renderer::TemplateFinder, '#exist?' do + subject { described_class.new(template_path, type_map) } + let(:template_path) { 'spec/fixtures/templates/' } + let(:type_map) { {'html' => 'text/html'} } + + it 'returns true when the template exists' do + expect(subject.exist?('index')).to be(true) + end + + it 'returns false when the template does not exist' do + expect(subject.exist?('not_found')).to be(false) + end +end diff --git a/spec/unit/zero/renderer/template_finder/get_spec.rb b/spec/unit/zero/renderer/template_finder/get_spec.rb new file mode 100644 index 0000000..d4d40e9 --- /dev/null +++ b/spec/unit/zero/renderer/template_finder/get_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe Zero::Renderer::TemplateFinder, '#get' do + subject { described_class.new(template_path, type_map) } + let(:template_path) { 'spec/fixtures/templates/' } + let(:type_map) {{ + 'html' => ['text/html', 'text/xml', '*/*'], + 'json' => ['application/json', 'plain/text'] + }} + let(:html_types) { ['text/html'] } + let(:json_types) { ['application/json'] } + let(:foo_types) { ['foo/bar', 'bar/foo'] } + + it 'returns a Tilt template' do + expect(subject.get('index', html_types)).to be_kind_of(Tilt::Template) + end + + it 'raises an Error when the template is not found' do + expect { subject.get('not_exist', html_types) }.to raise_error( + ArgumentError, /Template 'not_exist' does not exist/) + end + + it 'raises an Error when no type for the template was found' do + expect { subject.get('index', foo_types) }.to raise_error( + ArgumentError, /Template 'index' not found/) + end +end diff --git a/spec/unit/zero/renderer/template_finder/get_templates_spec.rb b/spec/unit/zero/renderer/template_finder/templates_spec.rb index 5928e66..e6c0edd 100644 --- a/spec/unit/zero/renderer/template_finder/get_templates_spec.rb +++ b/spec/unit/zero/renderer/template_finder/templates_spec.rb @@ -17,7 +17,7 @@ describe Zero::Renderer::TemplateFinder, '#initialize' do shared_examples_for 'a template loader' do it 'creates a template tree' do - subject.get_templates['welcome/index'].should eq(result) + subject.templates['welcome/index'].should eq(result) end end @@ -55,11 +55,4 @@ describe Zero::Renderer::TemplateFinder, '#initialize' do 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 |