0
0
zero/spec/unit/zero/renderer/render_spec.rb

55 lines
1.6 KiB
Ruby
Raw Normal View History

2012-11-26 20:07:37 +01:00
require 'spec_helper'
describe Zero::Renderer, '#render' do
2012-11-27 21:02:07 +01:00
subject { Zero::Renderer.new(template_path, type_map) }
let(:template_path) { 'spec/fixtures/templates/' }
2012-11-27 21:02:07 +01:00
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'] }
2012-11-27 21:02:07 +01:00
let(:binding) { SpecTemplateContext.new('foo') }
2012-11-26 20:07:37 +01:00
2012-11-27 21:02:07 +01:00
before :each do
subject.read_template_path!
2012-11-26 20:07:37 +01:00
end
2012-11-27 21:02:07 +01:00
it 'returns a tilt template' do
subject.render('index', html_types, binding).should be_kind_of(String)
end
2012-11-26 20:07:37 +01:00
2012-11-27 21:02:07 +01:00
it 'renders html content' do
subject.render('index', html_types, binding).should match('success')
2012-11-26 20:07:37 +01:00
end
2012-11-27 21:02:07 +01:00
it 'returns a tilt template for different types' do
subject.render('index', json_types, binding).should be_kind_of(String)
end
2012-11-26 20:07:37 +01:00
2012-11-27 21:02:07 +01:00
it 'renders json content' do
subject.render('index', json_types, binding).should match("{text: 'success'}")
2012-11-26 20:07:37 +01:00
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
2013-01-06 17:39:57 +01:00
it 'uses the context' do
subject.render('context', html_types, binding).should match('foo')
end
2012-11-26 20:07:37 +01:00
end