defmastership 1.0.5 → 1.0.6
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/bin/defmastership +21 -15
- data/cucumber.yml +1 -1
- data/defmastership.gemspec +12 -6
- data/features/changeref.feature +82 -129
- data/features/export.feature +88 -34
- data/features/modify.feature +143 -0
- data/features/rename_included_files.feature +121 -0
- data/lib/defmastership.rb +11 -3
- data/lib/defmastership/batch_modifier.rb +33 -0
- data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +18 -35
- data/lib/defmastership/change_ref_modifier.rb +15 -0
- data/lib/defmastership/constants.rb +14 -1
- data/lib/defmastership/csv_formatter.rb +15 -16
- data/lib/defmastership/csv_formatter_body.rb +11 -6
- data/lib/defmastership/csv_formatter_header.rb +11 -10
- data/lib/defmastership/definition.rb +11 -0
- data/lib/defmastership/definition_parser.rb +46 -0
- data/lib/defmastership/document.rb +43 -75
- data/lib/defmastership/filters.rb +30 -0
- data/lib/defmastership/line_modifier_base.rb +29 -0
- data/lib/defmastership/modifier_base.rb +29 -0
- data/lib/defmastership/rename_included_files_line_modifier.rb +126 -0
- data/lib/defmastership/rename_included_files_modifier.rb +30 -0
- data/lib/defmastership/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/defmastership/batch_modifier_spec.rb +115 -0
- data/spec/unit/defmastership/{ref_changer_spec.rb → change_ref_line_modifier_spec.rb} +48 -26
- data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
- data/spec/unit/defmastership/comment_filter_spec.rb +8 -4
- data/spec/unit/defmastership/csv_formatter_body_spec.rb +61 -37
- data/spec/unit/defmastership/csv_formatter_header_spec.rb +46 -22
- data/spec/unit/defmastership/csv_formatter_spec.rb +65 -104
- data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
- data/spec/unit/defmastership/definition_spec.rb +30 -4
- data/spec/unit/defmastership/document_spec.rb +112 -35
- data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +203 -0
- data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +67 -0
- metadata +34 -9
- data/lib/defmastership/batch_changer.rb +0 -41
- data/lib/defmastership/project_ref_changer.rb +0 -28
- data/spec/unit/defmastership/batch_changer_spec.rb +0 -109
- data/spec/unit/defmastership/project_ref_changer_spec.rb +0 -80
@@ -0,0 +1,203 @@
|
|
1
|
+
# Copyright (c) 2021 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership')
|
5
|
+
|
6
|
+
RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
|
7
|
+
subject(:includeschanger) { described_class.new }
|
8
|
+
|
9
|
+
describe '.new' do
|
10
|
+
it { is_expected.not_to(be(nil)) }
|
11
|
+
it { is_expected.to(have_attributes(from_regexp: '')) }
|
12
|
+
it { is_expected.to(have_attributes(to_template: '')) }
|
13
|
+
it { is_expected.to(have_attributes(changes: [])) }
|
14
|
+
it { expect { includeschanger.user_defined_attribute }.to(raise_error(NoMethodError)) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.from_config' do
|
18
|
+
subject(:includeschanger) do
|
19
|
+
described_class.from_config(
|
20
|
+
from_regexp: 'Whatever.+',
|
21
|
+
to_template: 'Whatever'
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
it { is_expected.not_to(be(nil)) }
|
26
|
+
it { is_expected.to(have_attributes(from_regexp: 'Whatever.+')) }
|
27
|
+
it { is_expected.to(have_attributes(to_template: 'Whatever')) }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#replace' do
|
31
|
+
context 'when NOT valid include' do
|
32
|
+
before do
|
33
|
+
includeschanger.from_config(
|
34
|
+
from_regexp: 'orig',
|
35
|
+
cancel_if_match: 'REF',
|
36
|
+
to_template: 'dest'
|
37
|
+
)
|
38
|
+
allow(File).to(receive(:rename))
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when the include statement do not match' do
|
42
|
+
before do
|
43
|
+
['[define,requirement,REFERENCE]', '--'].each do |line|
|
44
|
+
includeschanger.replace(line)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it do
|
49
|
+
expect(includeschanger.replace('badinclude::orig[]'))
|
50
|
+
.to(eq('badinclude::orig[]'))
|
51
|
+
end
|
52
|
+
|
53
|
+
it do
|
54
|
+
includeschanger.replace('badinclude::orig[]')
|
55
|
+
expect(includeschanger).to(have_attributes(changes: []))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when the include is not in a definition' do
|
60
|
+
before do
|
61
|
+
['[define,requirement,REFERENCE]', '--', 'text', '--'].each do |line|
|
62
|
+
includeschanger.replace(line)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it do
|
67
|
+
expect(includeschanger.replace('include::orig[]'))
|
68
|
+
.to(eq('include::orig[]'))
|
69
|
+
end
|
70
|
+
|
71
|
+
it do
|
72
|
+
includeschanger.replace('include::orig[]')
|
73
|
+
expect(includeschanger).to(have_attributes(changes: []))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when the cancel regexp is met' do
|
78
|
+
before do
|
79
|
+
['[define,requirement,REFERENCE]', '--'].each do |line|
|
80
|
+
includeschanger.replace(line)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it do
|
85
|
+
expect(includeschanger.replace('include::REFERENCE_orig[]'))
|
86
|
+
.to(eq('include::REFERENCE_orig[]'))
|
87
|
+
end
|
88
|
+
|
89
|
+
it do
|
90
|
+
includeschanger.replace('include::REFERENCE_orig[]')
|
91
|
+
expect(includeschanger).to(have_attributes(changes: []))
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when valid include' do
|
97
|
+
before do
|
98
|
+
allow(File).to(receive(:rename))
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when really simple rule' do
|
102
|
+
before do
|
103
|
+
includeschanger.from_config(
|
104
|
+
from_regexp: 'orig',
|
105
|
+
cancel_if_match: 'REF',
|
106
|
+
to_template: 'dest'
|
107
|
+
)
|
108
|
+
includeschanger.replace('[define,requirement,REFERENCE]')
|
109
|
+
includeschanger.replace('--')
|
110
|
+
end
|
111
|
+
|
112
|
+
it do
|
113
|
+
expect(includeschanger.replace('include::orig[]'))
|
114
|
+
.to(eq('include::dest[]'))
|
115
|
+
end
|
116
|
+
|
117
|
+
it do
|
118
|
+
includeschanger.replace('include::orig[]')
|
119
|
+
expect(File).to(have_received(:rename).with('orig', 'dest'))
|
120
|
+
end
|
121
|
+
|
122
|
+
it do
|
123
|
+
includeschanger.replace('include::orig[]')
|
124
|
+
expect(includeschanger).to(have_attributes(changes: [%w[orig dest]]))
|
125
|
+
end
|
126
|
+
|
127
|
+
it do
|
128
|
+
expect(includeschanger.replace('include::toto/orig[]'))
|
129
|
+
.to(eq('include::toto/dest[]'))
|
130
|
+
end
|
131
|
+
|
132
|
+
it do
|
133
|
+
includeschanger.replace('include::toto/orig[]')
|
134
|
+
expect(File).to(have_received(:rename).with('toto/orig', 'toto/dest'))
|
135
|
+
end
|
136
|
+
|
137
|
+
it do
|
138
|
+
includeschanger.replace('include::toto/orig[]')
|
139
|
+
expect(includeschanger).to(have_attributes(changes: [%w[toto/orig toto/dest]]))
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'when complex from_regexp' do
|
144
|
+
before do
|
145
|
+
includeschanger.from_config(
|
146
|
+
from_regexp: '(?<origin>.*\.extension)',
|
147
|
+
to_template: '%<reference>s_%<origin>s'
|
148
|
+
)
|
149
|
+
includeschanger.replace('[define,requirement,REF]')
|
150
|
+
end
|
151
|
+
|
152
|
+
it do
|
153
|
+
expect(includeschanger.replace('include::any_path/one_file.extension[]'))
|
154
|
+
.to(eq('include::any_path/REF_one_file.extension[]'))
|
155
|
+
end
|
156
|
+
|
157
|
+
it do
|
158
|
+
includeschanger.replace('include::any_path/one_file.extension[]')
|
159
|
+
expect(File).to(have_received(:rename).with('any_path/one_file.extension', 'any_path/REF_one_file.extension'))
|
160
|
+
end
|
161
|
+
|
162
|
+
it do
|
163
|
+
changes = [%w[any_path/one_file.extension any_path/REF_one_file.extension]]
|
164
|
+
includeschanger.replace('include::any_path/one_file.extension[]')
|
165
|
+
expect(includeschanger).to(have_attributes(changes: changes))
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'when path with variable' do
|
170
|
+
before do
|
171
|
+
includeschanger.from_config(
|
172
|
+
from_regexp: 'orig',
|
173
|
+
to_template: 'dest'
|
174
|
+
)
|
175
|
+
includeschanger.replace(':any: one')
|
176
|
+
includeschanger.replace(':path: two')
|
177
|
+
includeschanger.replace('[define,requirement,REFERENCE]')
|
178
|
+
includeschanger.replace('--')
|
179
|
+
end
|
180
|
+
|
181
|
+
it do
|
182
|
+
expect(includeschanger.replace('include::{any}/orig[]'))
|
183
|
+
.to(eq('include::{any}/dest[]'))
|
184
|
+
end
|
185
|
+
|
186
|
+
it do
|
187
|
+
includeschanger.replace('include::{any}/orig[]')
|
188
|
+
expect(File).to(have_received(:rename).with('one/orig', 'one/dest'))
|
189
|
+
end
|
190
|
+
|
191
|
+
it do
|
192
|
+
includeschanger.replace('include::{any}_{path}/orig[]')
|
193
|
+
expect(File).to(have_received(:rename).with('one_two/orig', 'one_two/dest'))
|
194
|
+
end
|
195
|
+
|
196
|
+
it do
|
197
|
+
includeschanger.replace('include::{any}_{path}/orig[]')
|
198
|
+
expect(includeschanger).to(have_attributes(changes: [%w[one_two/orig one_two/dest]]))
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Copyright (c) 2021 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership')
|
5
|
+
|
6
|
+
RSpec.describe(DefMastership::RenameIncludedFilesModifier) do
|
7
|
+
subject(:modifier) do
|
8
|
+
described_class.new(
|
9
|
+
'fake config'
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:adoc_texts) do
|
14
|
+
{
|
15
|
+
'file1.adoc' => "file1 line1\nfile1 line2",
|
16
|
+
'file2.adoc' => "file2 line1\nfile2 line2"
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.new' do
|
21
|
+
it { is_expected.not_to(be(nil)) }
|
22
|
+
it { is_expected.to(have_attributes(config: 'fake config')) }
|
23
|
+
it { is_expected.to(have_attributes(changes: [])) }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#do_modifications' do
|
27
|
+
let(:line_modifier) { instance_double(DefMastership::RenameIncludedFilesLineModifier, 'lineModifier') }
|
28
|
+
|
29
|
+
before do
|
30
|
+
allow(DefMastership::RenameIncludedFilesLineModifier).to(
|
31
|
+
receive(:from_config).with('fake config').and_return(line_modifier)
|
32
|
+
)
|
33
|
+
allow(line_modifier).to(receive(:replace).with("file1 line1\n").and_return("new file1 line1\n"))
|
34
|
+
allow(line_modifier).to(receive(:replace).with('file1 line2').and_return('new file1 line2'))
|
35
|
+
allow(line_modifier).to(receive(:replace).with("file2 line1\n").and_return("new file2 line1\n"))
|
36
|
+
allow(line_modifier).to(receive(:replace).with('file2 line2').and_return('new file2 line2'))
|
37
|
+
allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
|
38
|
+
allow(line_modifier).to(receive(:config).and_return('fake config'))
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when detailed expectations' do
|
42
|
+
before { modifier.do_modifications(adoc_texts) }
|
43
|
+
|
44
|
+
it do
|
45
|
+
expect(DefMastership::RenameIncludedFilesLineModifier).to(
|
46
|
+
have_received(:from_config).with('fake config')
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
it { expect(line_modifier).to(have_received(:replace).with("file1 line1\n")) }
|
51
|
+
it { expect(line_modifier).to(have_received(:replace).with('file1 line2')) }
|
52
|
+
it { expect(line_modifier).to(have_received(:replace).with("file2 line1\n")) }
|
53
|
+
it { expect(line_modifier).to(have_received(:replace).with('file2 line2')) }
|
54
|
+
it { expect(line_modifier).to(have_received(:changes)) }
|
55
|
+
it { is_expected.to(have_attributes(config: 'fake config')) }
|
56
|
+
it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
|
57
|
+
end
|
58
|
+
|
59
|
+
it do
|
60
|
+
expected_adoc = {
|
61
|
+
'file1.adoc' => "new file1 line1\nnew file1 line2",
|
62
|
+
'file2.adoc' => "new file2 line1\nnew file2 line2"
|
63
|
+
}
|
64
|
+
expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defmastership
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jérôme Arbez-Gindre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aruba
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.5'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rubocop-rspec
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -181,30 +195,41 @@ files:
|
|
181
195
|
- features/changeref.feature
|
182
196
|
- features/defmastership.feature
|
183
197
|
- features/export.feature
|
198
|
+
- features/modify.feature
|
199
|
+
- features/rename_included_files.feature
|
184
200
|
- features/step_definitions/defmastership_steps.rb
|
185
201
|
- features/support/env.rb
|
186
202
|
- lib/defmastership.rb
|
187
|
-
- lib/defmastership/
|
203
|
+
- lib/defmastership/batch_modifier.rb
|
204
|
+
- lib/defmastership/change_ref_line_modifier.rb
|
205
|
+
- lib/defmastership/change_ref_modifier.rb
|
188
206
|
- lib/defmastership/comment_filter.rb
|
189
207
|
- lib/defmastership/constants.rb
|
190
208
|
- lib/defmastership/csv_formatter.rb
|
191
209
|
- lib/defmastership/csv_formatter_body.rb
|
192
210
|
- lib/defmastership/csv_formatter_header.rb
|
193
211
|
- lib/defmastership/definition.rb
|
212
|
+
- lib/defmastership/definition_parser.rb
|
194
213
|
- lib/defmastership/document.rb
|
195
|
-
- lib/defmastership/
|
196
|
-
- lib/defmastership/
|
214
|
+
- lib/defmastership/filters.rb
|
215
|
+
- lib/defmastership/line_modifier_base.rb
|
216
|
+
- lib/defmastership/modifier_base.rb
|
217
|
+
- lib/defmastership/rename_included_files_line_modifier.rb
|
218
|
+
- lib/defmastership/rename_included_files_modifier.rb
|
197
219
|
- lib/defmastership/version.rb
|
198
220
|
- spec/spec_helper.rb
|
199
|
-
- spec/unit/defmastership/
|
221
|
+
- spec/unit/defmastership/batch_modifier_spec.rb
|
222
|
+
- spec/unit/defmastership/change_ref_line_modifier_spec.rb
|
223
|
+
- spec/unit/defmastership/change_ref_modifier_spec.rb
|
200
224
|
- spec/unit/defmastership/comment_filter_spec.rb
|
201
225
|
- spec/unit/defmastership/csv_formatter_body_spec.rb
|
202
226
|
- spec/unit/defmastership/csv_formatter_header_spec.rb
|
203
227
|
- spec/unit/defmastership/csv_formatter_spec.rb
|
228
|
+
- spec/unit/defmastership/definition_parser_spec.rb
|
204
229
|
- spec/unit/defmastership/definition_spec.rb
|
205
230
|
- spec/unit/defmastership/document_spec.rb
|
206
|
-
- spec/unit/defmastership/
|
207
|
-
- spec/unit/defmastership/
|
231
|
+
- spec/unit/defmastership/rename_included_files_line_modifier_spec.rb
|
232
|
+
- spec/unit/defmastership/rename_included_files_modifier_spec.rb
|
208
233
|
- spec/unit/defmastership_spec.rb
|
209
234
|
homepage: https://gitlab.com/jjag/defmastership/
|
210
235
|
licenses:
|
@@ -229,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
254
|
- !ruby/object:Gem::Version
|
230
255
|
version: '0'
|
231
256
|
requirements: []
|
232
|
-
rubygems_version: 3.2.
|
257
|
+
rubygems_version: 3.2.5
|
233
258
|
signing_key:
|
234
259
|
specification_version: 4
|
235
260
|
summary: Handling of references and definitions with asciidoctor
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module DefMastership
|
5
|
-
# Change references from temporary to definitive with multiple RefChangers
|
6
|
-
class BatchChanger
|
7
|
-
attr_reader :refchangers
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@refchangers = {}
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.from_h(hash)
|
14
|
-
new.from_h(hash)
|
15
|
-
end
|
16
|
-
|
17
|
-
def from_h(hash)
|
18
|
-
@refchangers =
|
19
|
-
hash.transform_values do |value|
|
20
|
-
DefMastership::RefChanger.from_h(value)
|
21
|
-
end
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_h
|
26
|
-
@refchangers.transform_values(&:to_h)
|
27
|
-
end
|
28
|
-
|
29
|
-
def replace(symb, line)
|
30
|
-
@refchangers.reduce(line) do |res_line, (_, refchanger)|
|
31
|
-
refchanger.public_send("replace_#{symb}".to_sym, res_line)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def changes
|
36
|
-
@refchangers.reduce([]) do |all_changes, (_, refchanger)|
|
37
|
-
all_changes + refchanger.changes
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module DefMastership
|
5
|
-
# Change all refs of a given project
|
6
|
-
class ProjectRefChanger
|
7
|
-
attr_reader :yaml_config, :adoc_texts, :changes
|
8
|
-
|
9
|
-
def initialize(yaml_config, adoc_texts)
|
10
|
-
@yaml_config = yaml_config
|
11
|
-
@adoc_texts = adoc_texts
|
12
|
-
end
|
13
|
-
|
14
|
-
def replace_all
|
15
|
-
batch = BatchChanger.from_h(@yaml_config)
|
16
|
-
|
17
|
-
@adoc_texts =
|
18
|
-
%i[refdef irefs].reduce(@adoc_texts) do |texts, method|
|
19
|
-
texts.transform_values do |text|
|
20
|
-
text.lines.map { |line| batch.replace(method, line) }.join
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
@yaml_config = batch.to_h.to_yaml
|
25
|
-
@changes = batch.changes
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require('defmastership')
|
5
|
-
|
6
|
-
RSpec.describe(DefMastership::BatchChanger) do
|
7
|
-
subject(:batchchanger) { described_class.new }
|
8
|
-
|
9
|
-
describe '.new' do
|
10
|
-
it { is_expected.not_to(be(nil)) }
|
11
|
-
it { is_expected.to(have_attributes(refchangers: {})) }
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '.from_h' do
|
15
|
-
before do
|
16
|
-
allow(DefMastership::RefChanger).to(receive(:from_h).once
|
17
|
-
.with(:whatever_a).and_return(:toto_a))
|
18
|
-
end
|
19
|
-
|
20
|
-
it { expect(described_class.from_h(a: :whatever_a)).not_to(be(nil)) }
|
21
|
-
|
22
|
-
it {
|
23
|
-
batchchanger = described_class.from_h(a: :whatever_a)
|
24
|
-
expect(batchchanger).to(have_attributes(refchangers: { a: :toto_a }))
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#from_h' do
|
29
|
-
before do
|
30
|
-
allow(DefMastership::RefChanger).to(receive(:from_h).with(:whatever_a).and_return(:one))
|
31
|
-
allow(DefMastership::RefChanger).to(receive(:from_h).with(:whatever_b).and_return(:two))
|
32
|
-
batchchanger.from_h(a: :whatever_a, b: :whatever_b)
|
33
|
-
end
|
34
|
-
|
35
|
-
it { expect(DefMastership::RefChanger).to(have_received(:from_h).with(:whatever_a)) }
|
36
|
-
|
37
|
-
it { expect(DefMastership::RefChanger).to(have_received(:from_h).with(:whatever_b)) }
|
38
|
-
|
39
|
-
it { expect(batchchanger).to(have_attributes(refchangers: { a: :one, b: :two })) }
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#to_h' do
|
43
|
-
subject(:batchchanger) { described_class.from_h(a: :a, b: :b) }
|
44
|
-
|
45
|
-
let(:refchanger_a) { instance_double(DefMastership::RefChanger, 'refchanger_a') }
|
46
|
-
let(:refchanger_b) { instance_double(DefMastership::RefChanger, 'refchanger_b') }
|
47
|
-
|
48
|
-
before do
|
49
|
-
allow(DefMastership::RefChanger).to(receive(:from_h).with(:a).and_return(refchanger_a))
|
50
|
-
allow(DefMastership::RefChanger).to(receive(:from_h).with(:b).and_return(refchanger_b))
|
51
|
-
allow(refchanger_a).to(receive(:to_h).and_return(a_a: :a_a))
|
52
|
-
allow(refchanger_b).to(receive(:to_h).and_return(b_b: :b_b))
|
53
|
-
batchchanger.to_h
|
54
|
-
end
|
55
|
-
|
56
|
-
it { expect(refchanger_a).to(have_received(:to_h)) }
|
57
|
-
|
58
|
-
it { expect(refchanger_b).to(have_received(:to_h)) }
|
59
|
-
|
60
|
-
it do
|
61
|
-
expect(batchchanger.to_h).to(eq(
|
62
|
-
a: { a_a: :a_a },
|
63
|
-
b: { b_b: :b_b }
|
64
|
-
))
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe 'replace' do
|
69
|
-
subject(:batchchanger) { described_class.from_h(a: :a, b: :b) }
|
70
|
-
|
71
|
-
let(:refchanger_a) { instance_double(DefMastership::RefChanger, 'refchanger_a') }
|
72
|
-
let(:refchanger_b) { instance_double(DefMastership::RefChanger, 'refchanger_b') }
|
73
|
-
|
74
|
-
before do
|
75
|
-
allow(DefMastership::RefChanger).to(receive(:from_h).with(:a).and_return(refchanger_a))
|
76
|
-
allow(DefMastership::RefChanger).to(receive(:from_h).with(:b).and_return(refchanger_b))
|
77
|
-
allow(refchanger_a).to(receive(:public_send).with(:replace_toto, 'a line').and_return('b line'))
|
78
|
-
allow(refchanger_b).to(receive(:public_send).with(:replace_toto, 'b line').and_return('c line'))
|
79
|
-
batchchanger.replace(:toto, 'a line')
|
80
|
-
end
|
81
|
-
|
82
|
-
it { expect(refchanger_a).to(have_received(:public_send).with(:replace_toto, 'a line')) }
|
83
|
-
|
84
|
-
it { expect(refchanger_b).to(have_received(:public_send).with(:replace_toto, 'b line')) }
|
85
|
-
|
86
|
-
it { expect(batchchanger.replace(:toto, 'a line')).to(eq('c line')) }
|
87
|
-
end
|
88
|
-
|
89
|
-
describe 'changes' do
|
90
|
-
subject(:batchchanger) { described_class.from_h(a: :a, b: :b) }
|
91
|
-
|
92
|
-
let(:refchanger_a) { instance_double(DefMastership::RefChanger, 'refchanger_a') }
|
93
|
-
let(:refchanger_b) { instance_double(DefMastership::RefChanger, 'refchanger_b') }
|
94
|
-
|
95
|
-
before do
|
96
|
-
allow(DefMastership::RefChanger).to(receive(:from_h).with(:a).and_return(refchanger_a))
|
97
|
-
allow(DefMastership::RefChanger).to(receive(:from_h).with(:b).and_return(refchanger_b))
|
98
|
-
allow(refchanger_a).to(receive(:changes).and_return([%w[a1 a2]]))
|
99
|
-
allow(refchanger_b).to(receive(:changes).and_return([%w[b1 b2]]))
|
100
|
-
end
|
101
|
-
|
102
|
-
it do
|
103
|
-
expect(batchchanger.changes).to(eq([
|
104
|
-
%w[a1 a2],
|
105
|
-
%w[b1 b2]
|
106
|
-
]))
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|