better specs for render
This commit is contained in:
parent
9b941a9191
commit
2762f68363
1
spec/fixtures/templates/index.html.erb
vendored
Normal file
1
spec/fixtures/templates/index.html.erb
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
success
|
1
spec/fixtures/templates/index.json.erb
vendored
Normal file
1
spec/fixtures/templates/index.json.erb
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{text: 'success'}
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user