sinclair 2.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +3 -3
- data/.rubocop.yml +33 -1
- data/.rubocop_todo.yml +13 -1
- data/Dockerfile +2 -3
- data/Gemfile +17 -0
- data/Makefile +6 -0
- data/README.md +3 -3
- data/lib/sinclair/caster/class_methods.rb +6 -6
- data/lib/sinclair/chain_settable.rb +1 -1
- data/lib/sinclair/class_methods.rb +3 -3
- data/lib/sinclair/config_builder.rb +4 -4
- data/lib/sinclair/config_class.rb +3 -3
- data/lib/sinclair/config_factory.rb +7 -6
- data/lib/sinclair/configurable.rb +5 -5
- data/lib/sinclair/env_settable.rb +1 -1
- data/lib/sinclair/equals_checker.rb +1 -3
- data/lib/sinclair/exception.rb +1 -0
- data/lib/sinclair/input_hash.rb +3 -2
- data/lib/sinclair/matchers/add_class_method_to.rb +1 -1
- data/lib/sinclair/matchers/add_instance_method_to.rb +1 -1
- data/lib/sinclair/matchers/base.rb +2 -1
- data/lib/sinclair/matchers/change_class_method_on.rb +1 -1
- data/lib/sinclair/matchers/change_instance_method_on.rb +1 -1
- data/lib/sinclair/method_builder/base.rb +2 -1
- data/lib/sinclair/method_definition/block_helper.rb +4 -4
- data/lib/sinclair/method_definition/parameter_builder.rb +2 -2
- data/lib/sinclair/method_definition/parameter_helper.rb +2 -2
- data/lib/sinclair/method_definition.rb +8 -8
- data/lib/sinclair/method_definitions.rb +2 -2
- data/lib/sinclair/model/builder.rb +2 -2
- data/lib/sinclair/model.rb +4 -4
- data/lib/sinclair/options/class_methods.rb +0 -2
- data/lib/sinclair/options.rb +0 -2
- data/lib/sinclair/settable/builder.rb +1 -0
- data/lib/sinclair/settable.rb +1 -1
- data/lib/sinclair/version.rb +1 -1
- data/lib/sinclair.rb +6 -6
- data/sinclair.gemspec +3 -20
- data/spec/integration/readme/my_class_spec.rb +2 -2
- data/spec/integration/readme/sinclair/model_spec.rb +2 -2
- data/spec/integration/readme/sinclair/options_spec.rb +1 -1
- data/spec/integration/yard/sinclair/add_class_method_spec.rb +2 -2
- data/spec/integration/yard/sinclair/caster/cast_spec.rb +2 -2
- data/spec/integration/yard/sinclair/caster/cast_with_spec.rb +1 -1
- data/spec/integration/yard/sinclair/config_factory_spec.rb +4 -4
- data/spec/integration/yard/sinclair/core_ext/object_spec.rb +2 -2
- data/spec/lib/sinclair/chain_settable_spec.rb +1 -1
- data/spec/lib/sinclair/config_factory_spec.rb +1 -1
- data/spec/lib/sinclair/equals_checker/reader_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/add_class_method_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/add_class_method_to_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/add_instance_method_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/add_instance_method_to_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/change_class_method_on_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/change_class_method_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/change_instance_method_on_spec.rb +1 -1
- data/spec/lib/sinclair/matchers/change_instance_method_spec.rb +1 -1
- data/spec/lib/sinclair/method_builder/base_spec.rb +1 -1
- data/spec/lib/sinclair/method_builder/block_method_builder_spec.rb +1 -1
- data/spec/lib/sinclair/method_builder/call_method_builder_spec.rb +1 -1
- data/spec/lib/sinclair/method_builder/string_method_builder_spec.rb +1 -1
- data/spec/lib/sinclair/method_definition_spec.rb +1 -0
- data/spec/lib/sinclair/method_definitions_spec.rb +9 -9
- data/spec/lib/sinclair/model_spec.rb +3 -3
- data/spec/lib/sinclair/options/class_methods_spec.rb +1 -1
- data/spec/lib/sinclair/options_spec.rb +3 -3
- data/spec/lib/sinclair/settable/builder_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/models/default_valueable.rb +1 -1
- data/spec/support/models/env_settings.rb +1 -1
- data/spec/support/models/random_generator.rb +1 -1
- data/spec/support/shared_examples/model.rb +2 -2
- data/spec/support/shared_examples/settable.rb +2 -2
- metadata +11 -233
- /data/spec/integration/readme/{sinclair/types_of_definition_spec.rb → sinclair_types_of_definition_spec.rb} +0 -0
- /data/spec/integration/yard/sinclair/{class_methods/build_spec.rb → class_methods_build_spec.rb} +0 -0
data/lib/sinclair/version.rb
CHANGED
data/lib/sinclair.rb
CHANGED
@@ -294,8 +294,8 @@ class Sinclair
|
|
294
294
|
# person.bond_name # returns 'Bond, James Bond'
|
295
295
|
#
|
296
296
|
# @return [Array<MethodDefinition>] the list of all currently defined instance methods
|
297
|
-
def add_method(
|
298
|
-
definitions.add(
|
297
|
+
def add_method(*, type: nil, **, &)
|
298
|
+
definitions.add(*, type:, **, &)
|
299
299
|
end
|
300
300
|
|
301
301
|
# Add a method to the method list to be created on klass
|
@@ -379,8 +379,8 @@ class Sinclair
|
|
379
379
|
# env_fetcher.timeout # returns '10'
|
380
380
|
#
|
381
381
|
# @return [Array<MethodDefinition>] the list of all currently defined class methods
|
382
|
-
def add_class_method(
|
383
|
-
class_definitions.add(
|
382
|
+
def add_class_method(*, type: nil, **, &)
|
383
|
+
class_definitions.add(*, type:, **, &)
|
384
384
|
end
|
385
385
|
|
386
386
|
# Evaluetes a block which will result in a String, the method code
|
@@ -453,8 +453,8 @@ class Sinclair
|
|
453
453
|
#
|
454
454
|
# Purchase.new(2.3, 5).total_price # returns 11.5
|
455
455
|
# @return [Array<MethodDefinition>] the list of all currently defined instance methods
|
456
|
-
def eval_and_add_method(name, &
|
457
|
-
add_method(name, instance_eval(&
|
456
|
+
def eval_and_add_method(name, &)
|
457
|
+
add_method(name, instance_eval(&))
|
458
458
|
end
|
459
459
|
|
460
460
|
private
|
data/sinclair.gemspec
CHANGED
@@ -12,29 +12,12 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.homepage = 'https://github.com/darthjee/sinclair'
|
13
13
|
gem.description = 'Gem for easy concern creation'
|
14
14
|
gem.summary = gem.description
|
15
|
-
gem.required_ruby_version = '>=
|
15
|
+
gem.required_ruby_version = '>= 3.3.1'
|
16
16
|
|
17
17
|
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
18
18
|
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
|
20
19
|
gem.require_paths = ['lib']
|
20
|
+
gem.metadata['rubygems_mfa_required'] = 'false'
|
21
21
|
|
22
|
-
gem.
|
23
|
-
|
24
|
-
gem.add_development_dependency 'bundler', '>= 2.3.25'
|
25
|
-
gem.add_development_dependency 'pry', '0.14.1'
|
26
|
-
gem.add_development_dependency 'pry-nav', '1.0.0'
|
27
|
-
gem.add_development_dependency 'rake', '13.0.1'
|
28
|
-
gem.add_development_dependency 'reek', '6.0.3'
|
29
|
-
gem.add_development_dependency 'rspec', '3.11.0'
|
30
|
-
gem.add_development_dependency 'rspec-core', '3.11.0'
|
31
|
-
gem.add_development_dependency 'rspec-expectations', '3.11.0'
|
32
|
-
gem.add_development_dependency 'rspec-mocks', '3.11.1'
|
33
|
-
gem.add_development_dependency 'rspec-support', '3.11.0'
|
34
|
-
gem.add_development_dependency 'rubocop', '0.80.1'
|
35
|
-
gem.add_development_dependency 'rubocop-rspec', '1.38.1'
|
36
|
-
gem.add_development_dependency 'rubycritic', '4.7.0'
|
37
|
-
gem.add_development_dependency 'simplecov', '0.21.2'
|
38
|
-
gem.add_development_dependency 'yard', '0.9.27'
|
39
|
-
gem.add_development_dependency 'yardstick', '0.9.9'
|
22
|
+
gem.add_dependency 'activesupport', '~> 7.2.x'
|
40
23
|
end
|
@@ -11,14 +11,14 @@ describe Sinclair::Model do
|
|
11
11
|
expect(human1.name).to eq('John Doe')
|
12
12
|
expect(human1.age).to eq(22)
|
13
13
|
expect(human1.gender).to eq(:undefined)
|
14
|
-
expect(human1 == human2).to
|
14
|
+
expect(human1 == human2).to be(true)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'Without comparable' do
|
18
18
|
tv1 = Tv.new(model: 'Sans Sunga Xt')
|
19
19
|
tv2 = Tv.new(model: 'Sans Sunga Xt')
|
20
20
|
|
21
|
-
expect(tv1 == tv2).to
|
21
|
+
expect(tv1 == tv2).to be(false)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -19,7 +19,7 @@ describe 'yard Sinclair#add_class_method' do
|
|
19
19
|
describe 'Adding a method by Block' do
|
20
20
|
it 'returns the timeout' do
|
21
21
|
builder = Sinclair.new(klass)
|
22
|
-
builder.add_class_method(:timeout) { ENV
|
22
|
+
builder.add_class_method(:timeout) { ENV.fetch('TIMEOUT', nil) }
|
23
23
|
builder.build
|
24
24
|
ENV['TIMEOUT'] = '300'
|
25
25
|
|
@@ -30,7 +30,7 @@ describe 'yard Sinclair#add_class_method' do
|
|
30
30
|
describe 'Passing type block' do
|
31
31
|
it 'creates new method' do
|
32
32
|
builder = Sinclair.new(klass)
|
33
|
-
builder.add_class_method(:timeout, type: :block) { ENV
|
33
|
+
builder.add_class_method(:timeout, type: :block) { ENV.fetch('TIMEOUT', nil) }
|
34
34
|
builder.build
|
35
35
|
ENV['TIMEOUT'] = '300'
|
36
36
|
|
@@ -15,8 +15,8 @@ describe 'yard Sinclair::Caster' do
|
|
15
15
|
it 'Casts passing parameter' do
|
16
16
|
base = Random.rand(3..6)
|
17
17
|
initial = Random.rand(10..20)
|
18
|
-
log = MathCaster.cast(initial, :log, base:
|
19
|
-
exp = MathCaster.cast(log, :exp, base:
|
18
|
+
log = MathCaster.cast(initial, :log, base:)
|
19
|
+
exp = MathCaster.cast(log, :exp, base:)
|
20
20
|
|
21
21
|
expect(exp).to be_between(initial - 0.0001, initial + 0.0001)
|
22
22
|
end
|
@@ -45,7 +45,7 @@ describe 'yard Sinclair::Caster.cast_with' do
|
|
45
45
|
values.map! do |config|
|
46
46
|
value = config[:value]
|
47
47
|
klass = config[:klass]
|
48
|
-
my_caster.cast(value, klass, klass:
|
48
|
+
my_caster.cast(value, klass, klass:)
|
49
49
|
end
|
50
50
|
|
51
51
|
expect(values[0]).to eq('{"name":"john","age":20,"country":"BR"}')
|
@@ -6,8 +6,8 @@ describe Sinclair::ConfigFactory do
|
|
6
6
|
describe '#yard' do
|
7
7
|
subject(:factory) do
|
8
8
|
described_class.new(
|
9
|
-
config_class
|
10
|
-
config_attributes:
|
9
|
+
config_class:,
|
10
|
+
config_attributes:
|
11
11
|
)
|
12
12
|
end
|
13
13
|
|
@@ -74,13 +74,13 @@ describe Sinclair::ConfigFactory do
|
|
74
74
|
|
75
75
|
describe 'Setting name with hash and block' do
|
76
76
|
it 'sets name on config' do
|
77
|
-
expect { factory.configure(email:
|
77
|
+
expect { factory.configure(email:) { name 'John' } }
|
78
78
|
.to change(config, :name)
|
79
79
|
.from(nil).to('John')
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'sets email on config' do
|
83
|
-
expect { factory.configure(email:
|
83
|
+
expect { factory.configure(email:) { name 'John' } }
|
84
84
|
.to change(config, :email)
|
85
85
|
.from(nil).to(email)
|
86
86
|
end
|
@@ -7,8 +7,8 @@ describe Object do
|
|
7
7
|
it do
|
8
8
|
object = [1, 2, 3]
|
9
9
|
|
10
|
-
expect(object.is_any?(Hash, Class)).to
|
11
|
-
expect(object.is_any?(Hash, Array)).to
|
10
|
+
expect(object.is_any?(Hash, Class)).to be(false)
|
11
|
+
expect(object.is_any?(Hash, Array)).to be(true)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -69,7 +69,7 @@ describe Sinclair::ChainSettable do
|
|
69
69
|
|
70
70
|
context 'when none has value' do
|
71
71
|
let(:default) { 'some_default_username' }
|
72
|
-
let(:options_hash) { { default:
|
72
|
+
let(:options_hash) { { default: } }
|
73
73
|
|
74
74
|
it 'returns the first value' do
|
75
75
|
expect(settable.username).to eq(default)
|
@@ -153,7 +153,7 @@ describe Sinclair::ConfigFactory do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
context 'when config class was set from common class' do
|
156
|
-
subject(:factory) { described_class.new(config_class:
|
156
|
+
subject(:factory) { described_class.new(config_class:) }
|
157
157
|
|
158
158
|
let(:config_class) { Class.new }
|
159
159
|
|
@@ -6,7 +6,7 @@ describe Sinclair::EqualsChecker::Reader do
|
|
6
6
|
subject(:reader) { described_class.new(attribute) }
|
7
7
|
|
8
8
|
let(:attribute) { :information }
|
9
|
-
let(:model) { SampleModel.new(name
|
9
|
+
let(:model) { SampleModel.new(name:, age:) }
|
10
10
|
let(:name) { 'The Name' }
|
11
11
|
let(:age) { 25 }
|
12
12
|
|
@@ -23,7 +23,7 @@ describe Sinclair::Matchers::AddClassMethod do
|
|
23
23
|
expect { matcher.matches?(proc {}) }
|
24
24
|
.to raise_error(
|
25
25
|
SyntaxError, 'You should specify which class the method is being added to' \
|
26
|
-
|
26
|
+
"add_class_method(:#{method}).to(klass)"
|
27
27
|
)
|
28
28
|
end
|
29
29
|
end
|
@@ -60,7 +60,7 @@ describe Sinclair::Matchers::AddClassMethodTo do
|
|
60
60
|
expect { matcher.matches?(event_proc) { 1 } }
|
61
61
|
.to raise_error(
|
62
62
|
SyntaxError, 'Block not received by the `add_class_method_to` matcher. ' \
|
63
|
-
|
63
|
+
'Perhaps you want to use `{ ... }` instead of do/end?'
|
64
64
|
)
|
65
65
|
end
|
66
66
|
end
|
@@ -25,7 +25,7 @@ describe Sinclair::Matchers::AddInstanceMethod do
|
|
25
25
|
expect { matcher.matches?(proc {}) }
|
26
26
|
.to raise_error(
|
27
27
|
SyntaxError, 'You should specify which instance the method is being added to' \
|
28
|
-
|
28
|
+
"add_method(:#{method}).to(instance)"
|
29
29
|
)
|
30
30
|
end
|
31
31
|
end
|
@@ -69,7 +69,7 @@ describe Sinclair::Matchers::AddInstanceMethodTo do
|
|
69
69
|
expect { matcher.matches?(event_proc) { 1 } }
|
70
70
|
.to raise_error(
|
71
71
|
SyntaxError, 'Block not received by the `add_instance_method_to` matcher. ' \
|
72
|
-
|
72
|
+
'Perhaps you want to use `{ ... }` instead of do/end?'
|
73
73
|
)
|
74
74
|
end
|
75
75
|
end
|
@@ -54,7 +54,7 @@ describe Sinclair::Matchers::ChangeClassMethodOn do
|
|
54
54
|
expect { matcher.matches?(event_proc) { 1 } }
|
55
55
|
.to raise_error(
|
56
56
|
SyntaxError, 'Block not received by the `change_class_method_on` matcher. ' \
|
57
|
-
|
57
|
+
'Perhaps you want to use `{ ... }` instead of do/end?'
|
58
58
|
)
|
59
59
|
end
|
60
60
|
end
|
@@ -25,7 +25,7 @@ describe Sinclair::Matchers::ChangeClassMethod do
|
|
25
25
|
expect { matcher.matches?(proc {}) }
|
26
26
|
.to raise_error(
|
27
27
|
SyntaxError, 'You should specify which class the method is being changed on' \
|
28
|
-
|
28
|
+
"change_class_method(:#{method}).on(klass)"
|
29
29
|
)
|
30
30
|
end
|
31
31
|
end
|
@@ -65,7 +65,7 @@ describe Sinclair::Matchers::ChangeInstanceMethodOn do
|
|
65
65
|
expect { matcher.matches?(event_proc) { 1 } }
|
66
66
|
.to raise_error(
|
67
67
|
SyntaxError, 'Block not received by the `change_instance_method_on` matcher. ' \
|
68
|
-
|
68
|
+
'Perhaps you want to use `{ ... }` instead of do/end?'
|
69
69
|
)
|
70
70
|
end
|
71
71
|
end
|
@@ -25,7 +25,7 @@ describe Sinclair::Matchers::ChangeInstanceMethod do
|
|
25
25
|
expect { matcher.matches?(proc {}) }
|
26
26
|
.to raise_error(
|
27
27
|
SyntaxError, 'You should specify which instance the method is being changed on' \
|
28
|
-
|
28
|
+
"change_method(:#{method}).on(instance)"
|
29
29
|
)
|
30
30
|
end
|
31
31
|
end
|
@@ -8,7 +8,7 @@ describe Sinclair::MethodBuilder::Base do
|
|
8
8
|
let(:type) { Sinclair::MethodBuilder::CLASS_METHOD }
|
9
9
|
|
10
10
|
it do
|
11
|
-
expect { described_class.build(klass, instance_of(described_class), type:
|
11
|
+
expect { described_class.build(klass, instance_of(described_class), type:) }
|
12
12
|
.to raise_error(NotImplementedError)
|
13
13
|
end
|
14
14
|
end
|
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
describe Sinclair::MethodBuilder::CallMethodBuilder do
|
6
6
|
describe '#build' do
|
7
7
|
subject(:builder) do
|
8
|
-
described_class.new(klass, definition, type:
|
8
|
+
described_class.new(klass, definition, type:)
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:call_name) { "attr_#{accessor_type}" }
|
@@ -48,22 +48,22 @@ describe Sinclair::MethodDefinitions do
|
|
48
48
|
let(:arguments) { %i[attr_reader some_attribute other_attribute] }
|
49
49
|
|
50
50
|
it do
|
51
|
-
expect(definitions.add(*arguments, type:
|
51
|
+
expect(definitions.add(*arguments, type:))
|
52
52
|
.to be_a(Array)
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'creates a new definition' do
|
56
|
-
expect(definitions.add(*arguments, type:
|
56
|
+
expect(definitions.add(*arguments, type:).last)
|
57
57
|
.to be_a(Sinclair::MethodDefinition)
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'creates a new definition of the chosen type' do
|
61
|
-
expect(definitions.add(*arguments, type:
|
61
|
+
expect(definitions.add(*arguments, type:).last)
|
62
62
|
.to be_a(Sinclair::MethodDefinition::CallDefinition)
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'initializes it correctly' do
|
66
|
-
expect { klass.module_eval(&definitions.add(*arguments, type:
|
66
|
+
expect { klass.module_eval(&definitions.add(*arguments, type:).last.code_block) }
|
67
67
|
.to add_method(:some_attribute).to(klass)
|
68
68
|
end
|
69
69
|
end
|
@@ -89,7 +89,7 @@ describe Sinclair::MethodDefinitions do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'initializes it correctly' do
|
92
|
-
expect(definitions.add(method_name, type
|
92
|
+
expect(definitions.add(method_name, type:, &block).last.name)
|
93
93
|
.to eq(method_name)
|
94
94
|
end
|
95
95
|
end
|
@@ -100,22 +100,22 @@ describe Sinclair::MethodDefinitions do
|
|
100
100
|
let(:code) { '10' }
|
101
101
|
|
102
102
|
it do
|
103
|
-
expect(definitions.add(method_name, code, type:
|
103
|
+
expect(definitions.add(method_name, code, type:))
|
104
104
|
.to be_a(Array)
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'creates a new definition' do
|
108
|
-
expect(definitions.add(method_name, code, type:
|
108
|
+
expect(definitions.add(method_name, code, type:).last)
|
109
109
|
.to be_a(Sinclair::MethodDefinition)
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'creates a new definition of the chosen type' do
|
113
|
-
expect(definitions.add(method_name, code, type:
|
113
|
+
expect(definitions.add(method_name, code, type:).last)
|
114
114
|
.to be_a(Sinclair::MethodDefinition::StringDefinition)
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'initializes it correctly' do
|
118
|
-
expect(definitions.add(method_name, code, type:
|
118
|
+
expect(definitions.add(method_name, code, type:).last.name)
|
119
119
|
.to eq(method_name)
|
120
120
|
end
|
121
121
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Sinclair::Model do
|
6
|
-
subject(:model) { klass.new(name:
|
6
|
+
subject(:model) { klass.new(name:) }
|
7
7
|
|
8
8
|
let(:name) { SecureRandom.hex(10) }
|
9
9
|
let(:attributes) { %i[name] }
|
@@ -55,7 +55,7 @@ describe Sinclair::Model do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'when class is subclass of another model' do
|
58
|
-
subject(:model) { klass.new(name
|
58
|
+
subject(:model) { klass.new(name:, age:) }
|
59
59
|
|
60
60
|
let(:age) { Random.rand(10..20) }
|
61
61
|
|
@@ -72,7 +72,7 @@ describe Sinclair::Model do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'is initialized with both attributes' do
|
75
|
-
expect { klass.new(name
|
75
|
+
expect { klass.new(name:, age:) }
|
76
76
|
.not_to raise_error
|
77
77
|
end
|
78
78
|
|
@@ -20,7 +20,7 @@ describe Sinclair::Options do
|
|
20
20
|
|
21
21
|
context 'when initializing with valid args' do
|
22
22
|
subject(:options) do
|
23
|
-
klass.new(timeout
|
23
|
+
klass.new(timeout:, protocol: 'http')
|
24
24
|
end
|
25
25
|
|
26
26
|
let(:timeout) { Random.rand(10..19) }
|
@@ -44,7 +44,7 @@ describe Sinclair::Options do
|
|
44
44
|
|
45
45
|
context 'when initializing subclass with valid args' do
|
46
46
|
subject(:options) do
|
47
|
-
klass.new(timeout
|
47
|
+
klass.new(timeout:, protocol: 'http')
|
48
48
|
end
|
49
49
|
|
50
50
|
let(:klass) { Class.new(ConnectionOptions) }
|
@@ -142,7 +142,7 @@ describe Sinclair::Options do
|
|
142
142
|
context 'when overriding values with false' do
|
143
143
|
let(:options) { klass.new(protocol: false) }
|
144
144
|
|
145
|
-
it { expect(options.protocol).to
|
145
|
+
it { expect(options.protocol).to be(false) }
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -16,7 +16,7 @@ describe Sinclair::Settable::Builder do
|
|
16
16
|
let(:username) { 'my_login' }
|
17
17
|
let(:password) { Random.rand(10_000).to_s }
|
18
18
|
let(:settings) { %i[username password] }
|
19
|
-
let(:options) { { prefix:
|
19
|
+
let(:options) { { prefix: } }
|
20
20
|
|
21
21
|
let(:builder) do
|
22
22
|
described_class.new(settable, *settings, **options)
|
data/spec/spec_helper.rb
CHANGED
@@ -14,7 +14,7 @@ require 'pry-nav'
|
|
14
14
|
|
15
15
|
support_files = File.expand_path('spec/support/**/*.rb')
|
16
16
|
|
17
|
-
Dir[support_files].
|
17
|
+
Dir[support_files].each { |file| require file }
|
18
18
|
|
19
19
|
RSpec.configure do |config|
|
20
20
|
config.run_all_when_everything_filtered = true
|
@@ -5,7 +5,7 @@ require './spec/support/models/default_value_builder'
|
|
5
5
|
module DefaultValueable
|
6
6
|
def default_reader(*methods, value:, accept_nil: false)
|
7
7
|
DefaultValueBuilder.new(
|
8
|
-
self, value
|
8
|
+
self, value:, accept_nil:
|
9
9
|
).add_default_values(*methods)
|
10
10
|
end
|
11
11
|
end
|
@@ -18,7 +18,7 @@ shared_examples 'sinclair model building' do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'returns a new class with a comparable that finds matches' do
|
21
|
-
expect(model).to eq(klass.new(name:
|
21
|
+
expect(model).to eq(klass.new(name:))
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'returns a new class with a comparable that find misses' do
|
@@ -48,7 +48,7 @@ shared_examples 'sinclair model building' do
|
|
48
48
|
let(:options) { { comparable: false } }
|
49
49
|
|
50
50
|
it 'returns a new class without comparable' do
|
51
|
-
expect(model).not_to eq(klass.new(name:
|
51
|
+
expect(model).not_to eq(klass.new(name:))
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -35,7 +35,7 @@ shared_examples 'settings reading' do
|
|
35
35
|
|
36
36
|
context 'when defining defaults' do
|
37
37
|
let(:settings) { %i[host] }
|
38
|
-
let(:options) { { prefix
|
38
|
+
let(:options) { { prefix:, default: 'my-host.com' } }
|
39
39
|
|
40
40
|
it 'returns default value' do
|
41
41
|
expect(settable.host).to eq('my-host.com')
|
@@ -60,7 +60,7 @@ shared_examples 'settings reading' do
|
|
60
60
|
|
61
61
|
context 'when defining a type' do
|
62
62
|
let(:settings) { %i[port] }
|
63
|
-
let(:options) { { prefix
|
63
|
+
let(:options) { { prefix:, type: :integer } }
|
64
64
|
let(:port) { Random.rand(10..100) }
|
65
65
|
|
66
66
|
context 'when the key is not set' do
|