diff options
Diffstat (limited to 'spec/unit/renderer')
-rw-r--r-- | spec/unit/renderer/read_template_path_spec.rb | 66 | ||||
-rw-r--r-- | spec/unit/renderer/render_spec.rb | 54 | ||||
-rw-r--r-- | spec/unit/renderer/template_path.rb | 8 | ||||
-rw-r--r-- | spec/unit/renderer/type_map_spec.rb | 13 |
4 files changed, 0 insertions, 141 deletions
diff --git a/spec/unit/renderer/read_template_path_spec.rb b/spec/unit/renderer/read_template_path_spec.rb deleted file mode 100644 index 8655777..0000000 --- a/spec/unit/renderer/read_template_path_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -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 diff --git a/spec/unit/renderer/render_spec.rb b/spec/unit/renderer/render_spec.rb deleted file mode 100644 index 30d2225..0000000 --- a/spec/unit/renderer/render_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'spec_helper' - -describe Zero::Renderer, '#render' do - subject { Zero::Renderer.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'] } - let(:binding) { SpecTemplateContext.new('foo') } - - before :each do - subject.read_template_path! - end - - it 'returns a tilt template' do - subject.render('index', html_types, binding).should be_kind_of(String) - end - - it 'renders html content' do - subject.render('index', html_types, binding).should match('success') - end - - it 'returns a tilt template for different types' do - subject.render('index', json_types, binding).should be_kind_of(String) - end - - it 'renders json content' do - subject.render('index', json_types, binding).should match("{text: 'success'}") - end - - it 'returns an ArgumentError, if given template does not exist' do - expect { - subject.render('foobar', html_types, binding) - }.to raise_error(ArgumentError, "No template found for 'foobar'!") - end - - it 'returns an ArgumentError, if no template fits types' do - expect { - subject.render('index', foo_types, binding) - }.to raise_error( - ArgumentError, - "No template found for any of this types #{foo_types.join ', '}!" - ) - end - - it 'uses the context' do - subject.render('context', html_types, binding).should match('foo') - - end -end diff --git a/spec/unit/renderer/template_path.rb b/spec/unit/renderer/template_path.rb deleted file mode 100644 index 261faa8..0000000 --- a/spec/unit/renderer/template_path.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'spec_helper' - -describe Zero::Renderer, '#template_path' do - subject { Zero::Renderer.new(template_path) } - let(:template_path) { 'foo' } - - its(:type_map) { should be(template_path) } -end diff --git a/spec/unit/renderer/type_map_spec.rb b/spec/unit/renderer/type_map_spec.rb deleted file mode 100644 index 290e579..0000000 --- a/spec/unit/renderer/type_map_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper' - -describe Zero::Renderer, '#type_map' do - subject { Zero::Renderer.new(template_path, type_map) } - let(:template_path) { 'foo' } - let(:type_map) { {'html' => ['text/html']} } - - its(:type_map) { should be(type_map) } - - it 'returns an empty Hash, if type_map is not set while initialization' do - Zero::Renderer.new(template_path).type_map.should eq({}) - end -end |