dry-web 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -9
- data/CHANGELOG.md +8 -0
- data/Gemfile +4 -0
- data/dry-web.gemspec +2 -2
- data/lib/dry/web/container.rb +13 -31
- data/lib/dry/web/version.rb +1 -1
- data/spec/unit/container_spec.rb +1 -42
- metadata +9 -18
- data/lib/dry/web/settings.rb +0 -57
- data/lib/dry/web/settings/file_loader.rb +0 -28
- data/lib/dry/web/settings/file_parser.rb +0 -49
- data/spec/unit/settings/file_loader_spec.rb +0 -16
- data/spec/unit/settings/file_parser_spec.rb +0 -29
- data/spec/unit/settings_spec.rb +0 -105
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bd38cff5b681971b1dc6b4291944d7d22c2b1fe
|
4
|
+
data.tar.gz: 3552ee32bd6052c1f4a1f50058ebdaf0977bead5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a390ec0d28183d82e79cbdc288c0ef63b977b84f6e1d0ef5417c0e0ef1b18a7e3ddf04ed54ae9d37510532fbd5fd56aa4ada3792df8ed80a80be4b3200602d8
|
7
|
+
data.tar.gz: 9698aa2a296a5767ec936caf8c31994fc04a1e7daa4b43b77617a8359ac94d1affdd6f9bc31ad0d50d6e722daa2cb8a19bfea0d18eebfd3e5231027de3b0e777
|
data/.travis.yml
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
language: ruby
|
2
|
-
dist: trusty
|
3
|
-
sudo: required
|
4
2
|
cache: bundler
|
5
|
-
bundler_args: --without tools
|
3
|
+
bundler_args: --without benchmarks tools
|
6
4
|
script:
|
7
5
|
- bundle exec rake spec
|
6
|
+
before_install: gem update --system
|
8
7
|
after_script:
|
9
8
|
- bundle exec codeclimate-test-reporter
|
10
9
|
rvm:
|
11
|
-
- 2.
|
12
|
-
- 2.3
|
13
|
-
- 2.
|
14
|
-
-
|
15
|
-
- jruby-9.1.6.0
|
10
|
+
- 2.5.0
|
11
|
+
- 2.4.3
|
12
|
+
- 2.3.6
|
13
|
+
- jruby-9.1.9.0
|
16
14
|
env:
|
17
15
|
global:
|
18
|
-
-
|
16
|
+
- COVERAGE='true'
|
19
17
|
notifications:
|
20
18
|
email: false
|
21
19
|
webhooks:
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -2,6 +2,10 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
gem 'dry-system', git: 'https://github.com/dry-rb/dry-system.git', branch: 'master'
|
6
|
+
gem 'dry-monitor', git: 'https://github.com/dry-rb/dry-monitor.git', branch: 'master'
|
7
|
+
gem 'dry-events', git: 'https://github.com/dry-rb/dry-events.git', branch: 'master'
|
8
|
+
|
5
9
|
group :test do
|
6
10
|
gem 'byebug', platform: :mri
|
7
11
|
gem 'codeclimate-test-reporter'
|
data/dry-web.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = '>= 2.1.0'
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "dry-system", "~> 0.
|
24
|
-
spec.add_runtime_dependency "dry-monitor"
|
23
|
+
spec.add_runtime_dependency "dry-system", "~> 0.9"
|
24
|
+
spec.add_runtime_dependency "dry-monitor", "~> 0.1"
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.7"
|
27
27
|
spec.add_development_dependency "rake", "~> 11.0"
|
data/lib/dry/web/container.rb
CHANGED
@@ -4,41 +4,23 @@ require 'dry/monitor'
|
|
4
4
|
module Dry
|
5
5
|
module Web
|
6
6
|
class Container < Dry::System::Container
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
setting :logger
|
11
|
-
setting :listeners, false
|
7
|
+
use :env, inferrer: -> { ENV.fetch('RACK_ENV', 'development').to_sym }
|
8
|
+
use :logging
|
9
|
+
use :notifications
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
super.
|
16
|
-
configure_logger.
|
17
|
-
configure_notifications.
|
18
|
-
configure_rack_monitor.
|
19
|
-
attach_listeners
|
20
|
-
end
|
21
|
-
|
22
|
-
def configure_logger
|
23
|
-
if key?(:logger)
|
24
|
-
self
|
25
|
-
elsif config.logger
|
26
|
-
register(:logger, config.logger)
|
27
|
-
else
|
28
|
-
config.logger = Monitor::Logger.new(config.root.join(config.log_dir).realpath.join("#{config.env}.log"))
|
29
|
-
config.logger.level = config.log_levels.fetch(config.env, Logger::ERROR)
|
30
|
-
register(:logger, config.logger)
|
31
|
-
self
|
32
|
-
end
|
33
|
-
end
|
11
|
+
setting :logger_class, Monitor::Logger
|
12
|
+
setting :listeners, false
|
34
13
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
14
|
+
def self.inherited(klass)
|
15
|
+
klass.after(:configure) do
|
16
|
+
register_rack_monitor
|
17
|
+
attach_listeners
|
39
18
|
end
|
19
|
+
super
|
20
|
+
end
|
40
21
|
|
41
|
-
|
22
|
+
class << self
|
23
|
+
def register_rack_monitor
|
42
24
|
return self if key?(:rack_monitor)
|
43
25
|
register(:rack_monitor, Monitor::Rack::Middleware.new(self[:notifications]))
|
44
26
|
self
|
data/lib/dry/web/version.rb
CHANGED
data/spec/unit/container_spec.rb
CHANGED
@@ -2,19 +2,6 @@ RSpec.describe "Dry::Web::Container" do
|
|
2
2
|
subject(:container) { Class.new(Dry::Web::Container) }
|
3
3
|
|
4
4
|
describe "settings" do
|
5
|
-
# Do some acrobatics to make the container reload a setting from scratch
|
6
|
-
# and apply a new default
|
7
|
-
def reload_setting_for(key)
|
8
|
-
if Dry::Web::Container.instance_variables.include?(:@_config)
|
9
|
-
Dry::Web::Container.remove_instance_variable(:@_config)
|
10
|
-
end
|
11
|
-
|
12
|
-
Dry::Web::Container.instance_variable_get(:@_settings).delete_if do |setting|
|
13
|
-
setting.name == key
|
14
|
-
end
|
15
|
-
load "dry/web/container.rb"
|
16
|
-
end
|
17
|
-
|
18
5
|
describe ".config.logger" do
|
19
6
|
it 'sets up default logger for development env' do
|
20
7
|
container.configure do |config|
|
@@ -81,36 +68,8 @@ RSpec.describe "Dry::Web::Container" do
|
|
81
68
|
|
82
69
|
describe ".config.env" do
|
83
70
|
context "existing RACK_ENV environment variable" do
|
84
|
-
before do
|
85
|
-
@rack_env = ENV["RACK_ENV"]
|
86
|
-
ENV["RACK_ENV"] = "production"
|
87
|
-
|
88
|
-
reload_setting_for :env
|
89
|
-
end
|
90
|
-
|
91
|
-
after do
|
92
|
-
ENV["RACK_ENV"] = @rack_env
|
93
|
-
end
|
94
|
-
|
95
71
|
it "returns the RACK_ENV" do
|
96
|
-
expect(Dry::Web::Container.config.env).to eq :
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "no RACK_ENV set" do
|
101
|
-
before do
|
102
|
-
@rack_env = ENV["RACK_ENV"]
|
103
|
-
ENV.delete("RACK_ENV")
|
104
|
-
|
105
|
-
reload_setting_for :env
|
106
|
-
end
|
107
|
-
|
108
|
-
after do
|
109
|
-
ENV["RACK_ENV"] = @rack_env
|
110
|
-
end
|
111
|
-
|
112
|
-
it "defaults to development" do
|
113
|
-
expect(Dry::Web::Container.config.env).to eq :development
|
72
|
+
expect(Class.new(Dry::Web::Container).config.env).to eq :test
|
114
73
|
end
|
115
74
|
end
|
116
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-system
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.9'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dry-monitor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '0.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '0.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,9 +114,6 @@ files:
|
|
114
114
|
- lib/dry-web.rb
|
115
115
|
- lib/dry/web/console.rb
|
116
116
|
- lib/dry/web/container.rb
|
117
|
-
- lib/dry/web/settings.rb
|
118
|
-
- lib/dry/web/settings/file_loader.rb
|
119
|
-
- lib/dry/web/settings/file_parser.rb
|
120
117
|
- lib/dry/web/version.rb
|
121
118
|
- log/.gitkeep
|
122
119
|
- spec/fixtures/multiple_env_files/.env
|
@@ -125,9 +122,6 @@ files:
|
|
125
122
|
- spec/fixtures/test/log/.gitkeep
|
126
123
|
- spec/spec_helper.rb
|
127
124
|
- spec/unit/container_spec.rb
|
128
|
-
- spec/unit/settings/file_loader_spec.rb
|
129
|
-
- spec/unit/settings/file_parser_spec.rb
|
130
|
-
- spec/unit/settings_spec.rb
|
131
125
|
homepage: https://github.com/dry-rb/dry-web
|
132
126
|
licenses:
|
133
127
|
- MIT
|
@@ -148,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
142
|
version: '0'
|
149
143
|
requirements: []
|
150
144
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.6.
|
145
|
+
rubygems_version: 2.6.11
|
152
146
|
signing_key:
|
153
147
|
specification_version: 4
|
154
148
|
summary: Lightweight web application stack on top of dry-system
|
@@ -159,6 +153,3 @@ test_files:
|
|
159
153
|
- spec/fixtures/test/log/.gitkeep
|
160
154
|
- spec/spec_helper.rb
|
161
155
|
- spec/unit/container_spec.rb
|
162
|
-
- spec/unit/settings/file_loader_spec.rb
|
163
|
-
- spec/unit/settings/file_parser_spec.rb
|
164
|
-
- spec/unit/settings_spec.rb
|
data/lib/dry/web/settings.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require "dry/web/settings/file_loader"
|
2
|
-
|
3
|
-
module Dry
|
4
|
-
module Web
|
5
|
-
class Settings
|
6
|
-
SettingValueError = Class.new(StandardError)
|
7
|
-
|
8
|
-
def self.schema
|
9
|
-
@schema ||= {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.setting(name, type = nil)
|
13
|
-
settings(name => type)
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.settings(new_schema)
|
17
|
-
check_schema_duplication(new_schema)
|
18
|
-
@schema = schema.merge(new_schema)
|
19
|
-
|
20
|
-
self
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.check_schema_duplication(new_schema)
|
24
|
-
shared_keys = new_schema.keys & schema.keys
|
25
|
-
|
26
|
-
raise ArgumentError, "Setting :#{shared_keys.first} has already been defined" if shared_keys.any?
|
27
|
-
end
|
28
|
-
private_class_method :check_schema_duplication
|
29
|
-
|
30
|
-
def self.load_files(root, env)
|
31
|
-
FileLoader.new.(root, env)
|
32
|
-
end
|
33
|
-
private_class_method :load_files
|
34
|
-
|
35
|
-
def self.load(root, env)
|
36
|
-
env_data = load_files(root, env)
|
37
|
-
schema = self.schema
|
38
|
-
|
39
|
-
Class.new do
|
40
|
-
extend Dry::Configurable
|
41
|
-
|
42
|
-
schema.each do |key, type|
|
43
|
-
value = ENV.fetch(key.to_s.upcase) { env_data[key.to_s.upcase] }
|
44
|
-
|
45
|
-
begin
|
46
|
-
value = type[value] if type
|
47
|
-
rescue => e
|
48
|
-
raise SettingValueError, "error typecasting +#{key}+: #{e}"
|
49
|
-
end
|
50
|
-
|
51
|
-
setting key, value
|
52
|
-
end
|
53
|
-
end.config
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "dry/web/settings/file_parser"
|
2
|
-
|
3
|
-
module Dry
|
4
|
-
module Web
|
5
|
-
class Settings
|
6
|
-
class FileLoader
|
7
|
-
def call(root, env)
|
8
|
-
files(root, env).reduce({}) do |hash, file|
|
9
|
-
hash.merge(parser.(file))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def parser
|
16
|
-
@parser ||= FileParser.new
|
17
|
-
end
|
18
|
-
|
19
|
-
def files(root, env)
|
20
|
-
[
|
21
|
-
root.join(".env"),
|
22
|
-
root.join(".env.#{env}")
|
23
|
-
].compact
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module Dry
|
2
|
-
module Web
|
3
|
-
class Settings
|
4
|
-
class FileParser
|
5
|
-
# Regex extracted from dotenv gem
|
6
|
-
# https://github.com/bkeepers/dotenv/blob/master/lib/dotenv/parser.rb#L14
|
7
|
-
LINE = %r(
|
8
|
-
\A
|
9
|
-
\s*
|
10
|
-
(?:export\s+)? # optional export
|
11
|
-
([\w\.]+) # key
|
12
|
-
(?:\s*=\s*|:\s+?) # separator
|
13
|
-
( # optional value begin
|
14
|
-
'(?:\'|[^'])*' # single quoted value
|
15
|
-
| # or
|
16
|
-
"(?:\"|[^"])*" # double quoted value
|
17
|
-
| # or
|
18
|
-
[^#\n]+ # unquoted value
|
19
|
-
)? # value end
|
20
|
-
\s*
|
21
|
-
(?:\#.*)? # optional comment
|
22
|
-
\z
|
23
|
-
)x
|
24
|
-
|
25
|
-
def call(file)
|
26
|
-
File.readlines(file).each_with_object({}) do |line, hash|
|
27
|
-
parse_line(line, hash)
|
28
|
-
end
|
29
|
-
rescue Errno::ENOENT
|
30
|
-
{}
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def parse_line(line, hash)
|
36
|
-
if (match = line.match(LINE))
|
37
|
-
key, value = match.captures
|
38
|
-
hash[key] = parse_value(value || "")
|
39
|
-
end
|
40
|
-
hash
|
41
|
-
end
|
42
|
-
|
43
|
-
def parse_value(value)
|
44
|
-
value.strip.sub(/\A(['"])(.*)\1\z/, '\2')
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require "dry/web/settings/file_loader"
|
2
|
-
|
3
|
-
RSpec.describe Dry::Web::Settings::FileLoader do
|
4
|
-
let(:klass) { Dry::Web::Settings::FileLoader }
|
5
|
-
let(:root) { SPEC_ROOT.join("fixtures/multiple_env_files") }
|
6
|
-
let(:env) { :test }
|
7
|
-
subject(:data) { klass.new.(root, env) }
|
8
|
-
|
9
|
-
describe "#call" do
|
10
|
-
it "will create hash with both variables from files" do
|
11
|
-
expect(subject["ONLY_ON_ENV"]).to eq ("will be loaded from env")
|
12
|
-
expect(subject["ONLY_IN_TEST"]).to eq ("will be loaded from env.test")
|
13
|
-
expect(subject["IN_BOTH_ENVIRONMENT"]).to eq (".env.test")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require "dry/web/settings/file_parser"
|
2
|
-
|
3
|
-
RSpec.describe Dry::Web::Settings::FileParser do
|
4
|
-
let(:klass) { Dry::Web::Settings::FileParser }
|
5
|
-
let(:parser) { klass.new }
|
6
|
-
|
7
|
-
describe "#call" do
|
8
|
-
context "with existing file" do
|
9
|
-
let(:file) { SPEC_ROOT.join("fixtures/test/.env.test") }
|
10
|
-
subject(:settings) { parser.(file) }
|
11
|
-
|
12
|
-
it "will retrun a hash with all variables and its value" do
|
13
|
-
expect(subject["API_KEY"]).to eq ("yaml123")
|
14
|
-
expect(subject["PRECOMPILE_ASSETS"]).to eq ("1")
|
15
|
-
expect(subject["UNDECLARED"]).to eq ("not declared in settings")
|
16
|
-
expect(subject["TESTING"]).to eq ("variables with = in it")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "without existing file" do
|
21
|
-
let(:file) { SPEC_ROOT.join("fixtures/test/.env") }
|
22
|
-
subject(:settings) { parser.(file) }
|
23
|
-
|
24
|
-
it "will retrun a empty hash" do
|
25
|
-
expect(subject).to eq ({})
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/spec/unit/settings_spec.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
require "dry/web/settings"
|
2
|
-
|
3
|
-
RSpec.describe Dry::Web::Settings do
|
4
|
-
describe ".setting" do
|
5
|
-
it "raises an error if a duplicate setting is specified" do
|
6
|
-
expect {
|
7
|
-
Class.new(Dry::Web::Settings) do
|
8
|
-
setting :foo
|
9
|
-
setting :foo
|
10
|
-
end
|
11
|
-
}.to raise_error(ArgumentError)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe ".load" do
|
16
|
-
subject(:settings) {
|
17
|
-
Class.new(Dry::Web::Settings) do
|
18
|
-
setting :api_key
|
19
|
-
setting :precompile_assets
|
20
|
-
setting :env_only_setting
|
21
|
-
end.load(SPEC_ROOT.join("fixtures/test"), :test)
|
22
|
-
}
|
23
|
-
|
24
|
-
it "loads settings from ENV first (as upper-cased variables)" do
|
25
|
-
ENV["ENV_ONLY_SETTING"] = "hello"
|
26
|
-
expect(settings.env_only_setting).to eq "hello"
|
27
|
-
end
|
28
|
-
|
29
|
-
it "loads settings from a env file (as upper-cased keys) if unavailable from ENV" do
|
30
|
-
expect(settings.api_key).to eq "yaml123"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "ignores undeclared settings in the env file" do
|
34
|
-
expect(settings).not_to respond_to(:undeclared)
|
35
|
-
end
|
36
|
-
|
37
|
-
context "without file" do
|
38
|
-
subject(:settings) {
|
39
|
-
Class.new(Dry::Web::Settings) do
|
40
|
-
setting :api_key
|
41
|
-
setting :precompile_assets
|
42
|
-
end.load(SPEC_ROOT.join("fixtures/test"), :development)
|
43
|
-
}
|
44
|
-
|
45
|
-
it "will retrun an config hash " do
|
46
|
-
expect(settings.to_h).to eq ({api_key: nil, precompile_assets: nil})
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "specific env file will merge on top of `.env`" do
|
51
|
-
subject(:settings) {
|
52
|
-
Class.new(Dry::Web::Settings) do
|
53
|
-
setting :in_both_environment
|
54
|
-
end.load(SPEC_ROOT.join("fixtures/multiple_env_files"), :test)
|
55
|
-
}
|
56
|
-
|
57
|
-
it "will retrun the value set from the test env " do
|
58
|
-
expect(settings.in_both_environment).to eq ".env.test"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "settings with types" do
|
63
|
-
before do
|
64
|
-
Test::CoercingBool = Class.new do
|
65
|
-
def self.[](val)
|
66
|
-
%w[1 true].include?(val.to_s)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
Test::ConstraintNotMatched = Class.new(ArgumentError)
|
71
|
-
|
72
|
-
Test::LongString = Class.new do
|
73
|
-
def self.[](val)
|
74
|
-
raise Test::ConstraintNotMatched, "string must be 12 characters or longer" if val.length < 12
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "coercing types" do
|
80
|
-
subject(:settings) {
|
81
|
-
Class.new(Dry::Web::Settings) do
|
82
|
-
setting :precompile_assets, Test::CoercingBool
|
83
|
-
end.load(SPEC_ROOT.join("fixtures/test"), :test)
|
84
|
-
}
|
85
|
-
|
86
|
-
it "supports coercion input data" do
|
87
|
-
expect(settings.precompile_assets).to eq true
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "constraining types" do
|
92
|
-
subject(:settings) {
|
93
|
-
Class.new(Dry::Web::Settings) do
|
94
|
-
setting :api_key, Test::LongString
|
95
|
-
end.load(SPEC_ROOT.join("fixtures/test"), :test)
|
96
|
-
}
|
97
|
-
|
98
|
-
it "raises helpful exceptions if input data does not match constraints" do
|
99
|
-
expect { settings }.to raise_error(Dry::Web::Settings::SettingValueError)
|
100
|
-
expect { settings }.to raise_error(/error typecasting \+api_key\+/)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|