From 2762f68363d7578ca02b77e4248496c62873d93c Mon Sep 17 00:00:00 2001 From: Gibheer Date: Tue, 27 Nov 2012 21:02:07 +0100 Subject: [PATCH] better specs for render --- spec/fixtures/templates/index.html.erb | 1 + spec/fixtures/templates/index.json.erb | 1 + spec/unit/renderer/render_spec.rb | 44 +++++++++++++------------- 3 files changed, 24 insertions(+), 22 deletions(-) create mode 100644 spec/fixtures/templates/index.html.erb create mode 100644 spec/fixtures/templates/index.json.erb diff --git a/spec/fixtures/templates/index.html.erb b/spec/fixtures/templates/index.html.erb new file mode 100644 index 0000000..2e9ba47 --- /dev/null +++ b/spec/fixtures/templates/index.html.erb @@ -0,0 +1 @@ +success diff --git a/spec/fixtures/templates/index.json.erb b/spec/fixtures/templates/index.json.erb new file mode 100644 index 0000000..535f10a --- /dev/null +++ b/spec/fixtures/templates/index.json.erb @@ -0,0 +1 @@ +{text: 'success'} diff --git a/spec/unit/renderer/render_spec.rb b/spec/unit/renderer/render_spec.rb index 6bb7801..a4064da 100644 --- a/spec/unit/renderer/render_spec.rb +++ b/spec/unit/renderer/render_spec.rb @@ -1,34 +1,34 @@ require 'spec_helper' describe Zero::Renderer, '#render' do - subject { Zero::Renderer.new(template_path) } - let(:template_path) { 'foo' } + subject { Zero::Renderer.new(template_path, type_map) } + let(:template_path) { 'spec/fixtures/templates' } let(:file_list) { ['./foo/welcome/index.html.erb'] } + let(:type_map) {{ + 'html' => ['text/html', 'text/xml', '*/*'], + 'json' => ['application/json', 'plain/text'] + }} + let(:html_types) { ['text/html'] } + let(:json_types) { ['application/json'] } + let(:binding) { SpecTemplateContext.new('foo') } - shared_examples_for 'the rendering' do - before :each do - subject.stub(:search_files).and_return(file_list) - subject.stub(:template).and_return(Tilt[:erb].new {template} ) - end - - it "renders the template" do - subject.render('welcome/index', 'text/html', binding).should eq(result) - end + before :each do + subject.read_template_path! end - context 'a simple template' do - let(:template) { 'success' } - let(:binding) { Object.new } - let(:result) { template } - - it_behaves_like 'the rendering' + it 'returns a tilt template' do + subject.render('index', html_types, binding).should be_kind_of(String) end - context 'a complex template' do - let(:template) { 'success <%= name %>' } - let(:binding) { SpecTemplateContext.new('bar') } - let(:result) { 'success bar' } + it 'renders html content' do + subject.render('index', html_types, binding).should match('success') + end - it_behaves_like 'the rendering' + 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 end