Skip to content

Commit

Permalink
Merge pull request #82 from liamdawson/generalize-errors
Browse files Browse the repository at this point in the history
Subclass errors from a general Lotus module error
  • Loading branch information
jodosha committed Nov 3, 2015
2 parents d588671 + e9eb2b9 commit 060861d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions lib/lotus/view/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Base view error
#
# This is a base error used to produce Lotus view errors.
#
# Allows better rescue options than simply catching `StandardError`.
#
# @since 0.4.4
module Lotus
module View
class Error < ::StandardError
end
end
end
3 changes: 2 additions & 1 deletion lib/lotus/view/rendering/layout_registry.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'lotus/view/rendering/null_template'
require 'lotus/view/rendering/templates_finder'
require 'lotus/view/error'

module Lotus
module View
Expand All @@ -9,7 +10,7 @@ module Rendering
# This is raised at the runtime when Lotus::Layout cannot find it's template.
#
# @since 0.3.0
class MissingTemplateLayoutError < ::StandardError
class MissingTemplateLayoutError < Lotus::View::Error
def initialize(template)
super("Can't find layout template '#{ template }'")
end
Expand Down
3 changes: 2 additions & 1 deletion test/layout_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end
end

it "raise error if template isn't found" do
it "raise subclassed error if template isn't found" do
Lotus::View.unload!

class MissingLayout
Expand All @@ -19,6 +19,7 @@ class MissingLayout
Lotus::View.load!
}.must_raise(Lotus::View::Rendering::MissingTemplateLayoutError)
error.message.must_include "Can't find layout template 'MissingLayout'"
error.class.ancestors.must_include Lotus::View::Error
end

it 'concrete methods are available in layout template' do
Expand Down

0 comments on commit 060861d

Please sign in to comment.