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-26 20:07:37 +01:00
|
|
|
let(:file_list) { ['./foo/welcome/index.html.erb'] }
|
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'] }
|
2012-11-29 21:41:13 +01:00
|
|
|
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
|
2012-11-29 21:25:50 +01:00
|
|
|
|
|
|
|
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
|
2012-11-29 21:41:13 +01:00
|
|
|
|
|
|
|
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
|
2012-11-26 20:07:37 +01:00
|
|
|
end
|