aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/zero/renderer.rb12
-rw-r--r--spec/unit/renderer/render_spec.rb6
2 files changed, 13 insertions, 5 deletions
diff --git a/lib/zero/renderer.rb b/lib/zero/renderer.rb
index 5bbb875..54d2d29 100644
--- a/lib/zero/renderer.rb
+++ b/lib/zero/renderer.rb
@@ -121,11 +121,13 @@ module Zero
# @param types [Array] the types for the template
# @return [Tilt::Template] a prepared tilt template
def template(name, types)
- types.each do |type|
- template = templates[name][type]
- unless template.nil?
- return template if template.kind_of?(Tilt::Template)
- return Tilt.new(template)
+ if templates.has_key? name
+ types.each do |type|
+ template = templates[name][type]
+ unless template.nil?
+ return template if template.kind_of?(Tilt::Template)
+ return Tilt.new(template)
+ end
end
end
raise ArgumentError.new "No template found for '#{name}'!"
diff --git a/spec/unit/renderer/render_spec.rb b/spec/unit/renderer/render_spec.rb
index a4064da..63ea3db 100644
--- a/spec/unit/renderer/render_spec.rb
+++ b/spec/unit/renderer/render_spec.rb
@@ -31,4 +31,10 @@ describe Zero::Renderer, '#render' do
it 'renders json content' do
subject.render('index', json_types, binding).should match("{text: 'success'}")
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
end