0
0

better specs for render

This commit is contained in:
Gibheer 2012-11-27 21:02:07 +01:00
parent 9b941a9191
commit 2762f68363
3 changed files with 24 additions and 22 deletions

View File

@ -0,0 +1 @@
success

View File

@ -0,0 +1 @@
{text: 'success'}

View File

@ -1,34 +1,34 @@
require 'spec_helper' require 'spec_helper'
describe Zero::Renderer, '#render' do describe Zero::Renderer, '#render' do
subject { Zero::Renderer.new(template_path) } subject { Zero::Renderer.new(template_path, type_map) }
let(:template_path) { 'foo' } let(:template_path) { 'spec/fixtures/templates' }
let(:file_list) { ['./foo/welcome/index.html.erb'] } 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
before :each do subject.read_template_path!
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
end end
context 'a simple template' do it 'returns a tilt template' do
let(:template) { 'success' } subject.render('index', html_types, binding).should be_kind_of(String)
let(:binding) { Object.new }
let(:result) { template }
it_behaves_like 'the rendering'
end end
context 'a complex template' do it 'renders html content' do
let(:template) { 'success <%= name %>' } subject.render('index', html_types, binding).should match('success')
let(:binding) { SpecTemplateContext.new('bar') } end
let(:result) { 'success bar' }
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
end end