sinclair 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +2 -2
- data/config/yardstick.yml +7 -1
- data/lib/sinclair/configurable.rb +2 -0
- data/lib/sinclair/equals_checker.rb +2 -0
- data/lib/sinclair/matchers/add_class_method.rb +27 -36
- data/lib/sinclair/matchers/add_instance_method.rb +59 -59
- data/lib/sinclair/matchers/add_method.rb +33 -35
- data/lib/sinclair/matchers/change_class_method.rb +22 -16
- data/lib/sinclair/matchers/change_instance_method.rb +46 -16
- data/lib/sinclair/matchers.rb +2 -8
- data/lib/sinclair/method_builder/call_method_builder.rb +49 -0
- data/lib/sinclair/method_builder.rb +4 -1
- data/lib/sinclair/method_definition/call_definition.rb +52 -0
- data/lib/sinclair/method_definition/string_definition.rb +0 -2
- data/lib/sinclair/method_definition.rb +40 -24
- data/lib/sinclair/method_definitions.rb +21 -1
- data/lib/sinclair/options/builder.rb +8 -0
- data/lib/sinclair/options.rb +1 -13
- data/lib/sinclair/version.rb +1 -1
- data/spec/integration/yard/sinclair/matchers/change_class_method_spec.rb +24 -0
- data/spec/integration/yard/sinclair/matchers/change_instance_method_spec.rb +40 -0
- data/spec/lib/sinclair/method_builder/call_method_builder_spec.rb +76 -0
- data/spec/lib/sinclair/method_builder_spec.rb +63 -20
- data/spec/lib/sinclair/method_definition/call_definition_spec.rb +36 -0
- data/spec/lib/sinclair/method_definition_spec.rb +64 -0
- data/spec/lib/sinclair/method_definitions_spec.rb +79 -0
- data/spec/lib/sinclair/options/builder_spec.rb +13 -0
- data/spec/lib/sinclair/options/class_methods_spec.rb +23 -8
- data/spec/support/shared_examples/attribute_accessor.rb +103 -0
- metadata +9 -2
@@ -27,11 +27,26 @@ describe Sinclair::Options::ClassMethods do
|
|
27
27
|
.to([:invalid])
|
28
28
|
end
|
29
29
|
|
30
|
+
context 'when the added fild makes an object different' do
|
31
|
+
let(:options1_hash) { { timeout: 10 } }
|
32
|
+
let(:options2_hash) { { timeout: 11 } }
|
33
|
+
|
34
|
+
before do
|
35
|
+
klass.skip_validation
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'adds the field to == check' do
|
39
|
+
expect { klass.send(:with_options, :timeout) }
|
40
|
+
.to change { klass.new(options1_hash) == klass.new(options2_hash) }
|
41
|
+
.from(true).to(false)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
30
45
|
it do
|
31
46
|
expect { klass.send(:with_options, :timeout, 'retries') }
|
32
47
|
.not_to change {
|
33
|
-
|
34
|
-
|
48
|
+
Sinclair::Options.invalid_options_in(%i[timeout retries invalid])
|
49
|
+
}
|
35
50
|
end
|
36
51
|
|
37
52
|
context 'when when calling method after building' do
|
@@ -46,8 +61,8 @@ describe Sinclair::Options::ClassMethods do
|
|
46
61
|
it do
|
47
62
|
expect { klass.send(:with_options, :timeout, :retries) }
|
48
63
|
.not_to change {
|
49
|
-
|
50
|
-
|
64
|
+
klass.invalid_options_in(%i[timeout retries invalid])
|
65
|
+
}
|
51
66
|
end
|
52
67
|
end
|
53
68
|
end
|
@@ -90,16 +105,16 @@ describe Sinclair::Options::ClassMethods do
|
|
90
105
|
it do
|
91
106
|
expect { klass.send(:with_options, 'protocol', port: 443) }
|
92
107
|
.to change {
|
93
|
-
|
94
|
-
|
108
|
+
klass.invalid_options_in(test_keys)
|
109
|
+
}.from(%i[protocol port invalid])
|
95
110
|
.to([:invalid])
|
96
111
|
end
|
97
112
|
|
98
113
|
it do
|
99
114
|
expect { klass.send(:with_options, 'protocol', port: 443) }
|
100
115
|
.not_to change {
|
101
|
-
|
102
|
-
|
116
|
+
super_class.invalid_options_in(%i[protocol port])
|
117
|
+
}
|
103
118
|
end
|
104
119
|
|
105
120
|
context 'when overriding a method' do
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
shared_examples 'a method builder that adds attribute reader' do
|
4
|
+
let(:klass) { Class.new }
|
5
|
+
let(:instance) { klass.new }
|
6
|
+
let(:value) { Random.rand(10..20) }
|
7
|
+
let(:method_name) { :the_method }
|
8
|
+
let(:attributes) { [method_name] }
|
9
|
+
|
10
|
+
context 'when type is instance' do
|
11
|
+
let(:type) { Sinclair::MethodBuilder::INSTANCE_METHOD }
|
12
|
+
|
13
|
+
it do
|
14
|
+
expect { builder.build }
|
15
|
+
.to add_method(method_name).to(instance)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when the method is built' do
|
19
|
+
before do
|
20
|
+
builder.build
|
21
|
+
instance.instance_variable_set("@#{method_name}", value)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns the value of the instance variable' do
|
25
|
+
expect(instance.the_method).to eq(value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when type is class' do
|
31
|
+
let(:type) { Sinclair::MethodBuilder::CLASS_METHOD }
|
32
|
+
|
33
|
+
it do
|
34
|
+
expect { builder.build }
|
35
|
+
.to add_class_method(method_name).to(klass)
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when the method is built' do
|
39
|
+
before do
|
40
|
+
builder.build
|
41
|
+
klass.instance_variable_set("@#{method_name}", value)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns the value of the instance variable' do
|
45
|
+
expect(klass.the_method).to eq(value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
shared_examples 'a method builder that adds attribute writer' do
|
52
|
+
let(:klass) { Class.new }
|
53
|
+
let(:instance) { klass.new }
|
54
|
+
let(:value) { Random.rand }
|
55
|
+
let(:method_name) { :the_method }
|
56
|
+
let(:attributes) { [method_name] }
|
57
|
+
|
58
|
+
context 'when type is instance' do
|
59
|
+
let(:type) { Sinclair::MethodBuilder::INSTANCE_METHOD }
|
60
|
+
|
61
|
+
it do
|
62
|
+
expect { builder.build }
|
63
|
+
.to add_method("#{method_name}=").to(instance)
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when the method is built' do
|
67
|
+
let(:value) { Random.rand(10..20) }
|
68
|
+
|
69
|
+
before do
|
70
|
+
builder.build
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'change the instance variable' do
|
74
|
+
expect { instance.the_method = value }
|
75
|
+
.to change { instance.instance_variable_get("@#{method_name}") }
|
76
|
+
.from(nil).to(value)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when type is class' do
|
82
|
+
let(:type) { Sinclair::MethodBuilder::CLASS_METHOD }
|
83
|
+
|
84
|
+
it do
|
85
|
+
expect { builder.build }
|
86
|
+
.to add_class_method("#{method_name}=").to(klass)
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when the method is built' do
|
90
|
+
let(:value) { Random.rand(10..20) }
|
91
|
+
|
92
|
+
before do
|
93
|
+
builder.build
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'change the instance variable' do
|
97
|
+
expect { klass.the_method = value }
|
98
|
+
.to change { klass.instance_variable_get("@#{method_name}") }
|
99
|
+
.from(nil).to(value)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinclair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DarthJee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -302,10 +302,12 @@ files:
|
|
302
302
|
- lib/sinclair/method_builder.rb
|
303
303
|
- lib/sinclair/method_builder/base.rb
|
304
304
|
- lib/sinclair/method_builder/block_method_builder.rb
|
305
|
+
- lib/sinclair/method_builder/call_method_builder.rb
|
305
306
|
- lib/sinclair/method_builder/string_method_builder.rb
|
306
307
|
- lib/sinclair/method_definition.rb
|
307
308
|
- lib/sinclair/method_definition/block_definition.rb
|
308
309
|
- lib/sinclair/method_definition/block_helper.rb
|
310
|
+
- lib/sinclair/method_definition/call_definition.rb
|
309
311
|
- lib/sinclair/method_definition/string_definition.rb
|
310
312
|
- lib/sinclair/method_definitions.rb
|
311
313
|
- lib/sinclair/options.rb
|
@@ -337,6 +339,8 @@ files:
|
|
337
339
|
- spec/integration/yard/sinclair/matchers/add_class_method_to_spec.rb
|
338
340
|
- spec/integration/yard/sinclair/matchers/add_instance_method_spec.rb
|
339
341
|
- spec/integration/yard/sinclair/matchers/add_instance_method_to_spec.rb
|
342
|
+
- spec/integration/yard/sinclair/matchers/change_class_method_spec.rb
|
343
|
+
- spec/integration/yard/sinclair/matchers/change_instance_method_spec.rb
|
340
344
|
- spec/integration/yard/sinclair/options_parser_spec.rb
|
341
345
|
- spec/integration/yard/sinclair/options_spec.rb
|
342
346
|
- spec/integration/yard/sinclair_spec.rb
|
@@ -362,10 +366,12 @@ files:
|
|
362
366
|
- spec/lib/sinclair/matchers/change_instance_method_spec.rb
|
363
367
|
- spec/lib/sinclair/matchers_spec.rb
|
364
368
|
- spec/lib/sinclair/method_builder/block_method_builder_spec.rb
|
369
|
+
- spec/lib/sinclair/method_builder/call_method_builder_spec.rb
|
365
370
|
- spec/lib/sinclair/method_builder/string_method_builder_spec.rb
|
366
371
|
- spec/lib/sinclair/method_builder_spec.rb
|
367
372
|
- spec/lib/sinclair/method_definition/block_definition_spec.rb
|
368
373
|
- spec/lib/sinclair/method_definition/block_helper_spec.rb
|
374
|
+
- spec/lib/sinclair/method_definition/call_definition_spec.rb
|
369
375
|
- spec/lib/sinclair/method_definition/string_definition_spec.rb
|
370
376
|
- spec/lib/sinclair/method_definition_spec.rb
|
371
377
|
- spec/lib/sinclair/method_definitions_spec.rb
|
@@ -413,6 +419,7 @@ files:
|
|
413
419
|
- spec/support/models/service_client.rb
|
414
420
|
- spec/support/models/validator_builder.rb
|
415
421
|
- spec/support/sample_model.rb
|
422
|
+
- spec/support/shared_examples/attribute_accessor.rb
|
416
423
|
- spec/support/shared_examples/class_method_definition.rb
|
417
424
|
- spec/support/shared_examples/config.rb
|
418
425
|
- spec/support/shared_examples/config_factory.rb
|