-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from dry-rb/refactor/clarify-template-lookup
Clarify config handling & template lookup
- Loading branch information
Showing
8 changed files
with
97 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Dry | ||
class View | ||
# Error raised when critical settings are not configured | ||
# | ||
# @api private | ||
class UndefinedConfigError < StandardError | ||
def initialize(key) | ||
super("no +#{key}+ configured") | ||
end | ||
end | ||
|
||
# Error raised when template could not be found within a view's configured | ||
# paths | ||
# | ||
# @api private | ||
class TemplateNotFoundError < StandardError | ||
def initialize(template_name, lookup_paths) | ||
msg = [ | ||
"Template +#{template_name}+ could not be found in paths:", | ||
lookup_paths.map { |path| " - #{path}"} | ||
].join("\n\n") | ||
|
||
super(msg) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
h1 Hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dry/view" | ||
require "dry/view/context" | ||
|
||
RSpec.describe "View / errors" do | ||
specify "Raising an error when paths are not configured" do | ||
view = Class.new(Dry::View) do | ||
config.template = "hello" | ||
end.new | ||
|
||
expect { view.() }.to raise_error(Dry::View::UndefinedConfigError, "no +paths+ configured") | ||
end | ||
|
||
specify "Raising an error when template is not configured" do | ||
view = Class.new(Dry::View) do | ||
config.paths = FIXTURES_PATH.join("integration/errors") | ||
end.new | ||
|
||
expect { view.() }.to raise_error(Dry::View::UndefinedConfigError, "no +template+ configured") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters