defmastership 1.0.17 → 1.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +22 -10
- data/Gemfile +51 -1
- data/Rakefile +16 -61
- data/bin/defmastership +9 -6
- data/config/mutant.yml +23 -3
- data/defmastership.gemspec +0 -10
- data/features/definition_checksum.feature +31 -1
- data/features/export.feature +43 -1
- data/features/rename_included_files.feature +28 -0
- data/lib/defmastership/batch_modifier.rb +17 -12
- data/lib/defmastership/change_ref_modifier.rb +88 -6
- data/lib/defmastership/comment_filter.rb +1 -1
- data/lib/defmastership/constants.rb +5 -4
- data/lib/defmastership/csv_formatter.rb +16 -12
- data/lib/defmastership/csv_formatter_body.rb +18 -15
- data/lib/defmastership/csv_formatter_header.rb +1 -1
- data/lib/defmastership/definition.rb +58 -19
- data/lib/defmastership/document.rb +109 -74
- data/lib/defmastership/matching_line.rb +17 -0
- data/lib/defmastership/modifier.rb +42 -0
- data/lib/defmastership/modifier_factory.rb +12 -0
- data/lib/defmastership/parsing_state.rb +15 -9
- data/lib/defmastership/rename_included_files_modifier.rb +172 -5
- data/lib/defmastership/set_join_hack.rb +11 -0
- data/lib/defmastership/update_def_checksum_modifier.rb +8 -13
- data/lib/defmastership/update_def_modifier.rb +49 -0
- data/lib/defmastership/update_def_version_modifier.rb +56 -15
- data/lib/defmastership/version.rb +1 -1
- data/lib/defmastership.rb +1 -6
- data/spec/spec_helper.rb +3 -1
- data/spec/unit/def_mastership/batch_modifier_spec.rb +38 -36
- data/spec/unit/def_mastership/change_ref_modifier_spec.rb +196 -51
- data/spec/unit/def_mastership/csv_formatter_body_spec.rb +60 -31
- data/spec/unit/def_mastership/csv_formatter_header_spec.rb +1 -1
- data/spec/unit/def_mastership/csv_formatter_spec.rb +79 -87
- data/spec/unit/def_mastership/definition_parser_spec.rb +1 -1
- data/spec/unit/def_mastership/definition_spec.rb +16 -6
- data/spec/unit/def_mastership/document_spec.rb +81 -38
- data/spec/unit/def_mastership/matching_line_spec.rb +37 -0
- data/spec/unit/def_mastership/modifier_factory_spec.rb +37 -0
- data/spec/unit/def_mastership/modifier_spec.rb +83 -0
- data/spec/unit/def_mastership/parsing_state_spec.rb +1 -1
- data/spec/unit/def_mastership/rename_included_files_modifier_spec.rb +219 -47
- data/spec/unit/def_mastership/string_spec.rb +1 -1
- data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +82 -50
- data/spec/unit/def_mastership/update_def_modifier_spec.rb +119 -0
- data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +135 -56
- data/tasks/console.rake +8 -0
- data/tasks/package.task +9 -0
- data/tasks/smelling_code.rake +38 -0
- data/tasks/test.rake +45 -0
- metadata +16 -153
- data/lib/defmastership/change_ref_line_modifier.rb +0 -85
- data/lib/defmastership/line_modifier_base.rb +0 -29
- data/lib/defmastership/modifier_base.rb +0 -36
- data/lib/defmastership/rename_included_files_line_modifier.rb +0 -126
- data/lib/defmastership/update_def_checksum_line_modifier.rb +0 -38
- data/lib/defmastership/update_def_version_line_modifier.rb +0 -58
- data/spec/unit/def_mastership/change_ref_line_modifier_spec.rb +0 -250
- data/spec/unit/def_mastership/rename_included_files_line_modifier_spec.rb +0 -207
- data/spec/unit/def_mastership/update_def_checksum_line_modifier_spec.rb +0 -82
- data/spec/unit/def_mastership/update_def_version_line_modifier_spec.rb +0 -131
@@ -1,15 +1,182 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'defmastership/constants'
|
5
|
+
require('defmastership/matching_line')
|
6
|
+
require 'defmastership/modifier'
|
7
|
+
|
8
|
+
# defintion of the Rename Included Files Modifier
|
4
9
|
module DefMastership
|
5
|
-
|
6
|
-
|
7
|
-
|
10
|
+
LOCAL_FILTERS = [
|
11
|
+
Filter.new(DMRegexp::VARIABLE_DEF, :new_variable_def),
|
12
|
+
Filter.new(DMRegexp::DEFINITION, :new_definition),
|
13
|
+
Filter.new(DMRegexp::BLOCK, :block_delimiter),
|
14
|
+
Filter.new(DMRegexp::EMPTY_LINE, :empty_line),
|
15
|
+
Filter.new(DMRegexp::WHATEVER, :new_line)
|
16
|
+
].freeze
|
17
|
+
private_constant :LOCAL_FILTERS
|
18
|
+
|
19
|
+
# Change included filenames on one line at a time
|
20
|
+
class RenameIncludedFilesModifier
|
21
|
+
include Modifier
|
22
|
+
|
23
|
+
PARSER_ACTIONS = {
|
24
|
+
new_variable_def: lambda { |matching_line|
|
25
|
+
@variables.merge!(Helper.variable_def_hash(matching_line.match))
|
26
|
+
},
|
27
|
+
add_line: proc { |_| },
|
28
|
+
add_new_definition: lambda { |matching_line|
|
29
|
+
config[:reference] = matching_line.match[:reference]
|
30
|
+
}
|
31
|
+
}.freeze
|
32
|
+
|
33
|
+
private_constant :PARSER_ACTIONS
|
34
|
+
|
35
|
+
def self.replacement_methods
|
8
36
|
%i[replace]
|
9
37
|
end
|
10
38
|
|
11
|
-
def
|
12
|
-
|
39
|
+
def self.default_config
|
40
|
+
{
|
41
|
+
from_regexp: '',
|
42
|
+
to_template: ''
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialize(config)
|
47
|
+
@variables = {}
|
48
|
+
@definition_parser = DefinitionParser.new(self)
|
49
|
+
|
50
|
+
setup_modifier_module(config)
|
51
|
+
end
|
52
|
+
|
53
|
+
def method_missing(method_name, *args)
|
54
|
+
action = PARSER_ACTIONS[method_name]
|
55
|
+
return instance_exec(*args, &action) if action
|
56
|
+
|
57
|
+
super
|
58
|
+
end
|
59
|
+
|
60
|
+
def respond_to_missing?(method_name, *args)
|
61
|
+
PARSER_ACTIONS.key?(method_name) || super
|
62
|
+
end
|
63
|
+
|
64
|
+
def replace(line)
|
65
|
+
match = matched?(line)
|
66
|
+
|
67
|
+
return line unless match
|
68
|
+
|
69
|
+
new_line = build_new_include_line(match, line)
|
70
|
+
|
71
|
+
rename_file(line, new_line)
|
72
|
+
|
73
|
+
new_line
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def build_new_include_line(match, line)
|
79
|
+
line.sub(Helper.complete_regexp_from(from_regexp)) do
|
80
|
+
Helper.text_with(match, to_template % Helper.hmerge(config, match))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def matched?(line)
|
85
|
+
return false unless concerned_line?(line)
|
86
|
+
return false unless line =~ Helper.complete_regexp_from(from_regexp)
|
87
|
+
|
88
|
+
match = Regexp.last_match
|
89
|
+
|
90
|
+
return false if config.key?(:cancel_if_match) && match[:filename].match?(cancel_if_match)
|
91
|
+
|
92
|
+
match
|
93
|
+
end
|
94
|
+
|
95
|
+
def concerned_line?(line)
|
96
|
+
return false if line.commented?
|
97
|
+
|
98
|
+
parse(line)
|
99
|
+
|
100
|
+
return false if @definition_parser.idle?
|
101
|
+
|
102
|
+
true
|
103
|
+
end
|
104
|
+
|
105
|
+
def parse(line)
|
106
|
+
Helper.apply_filters_until_consumed(line) do |event, match|
|
107
|
+
generate_event(event, MatchingLine.new(match))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def rename_file(from, to)
|
112
|
+
filename_from = Helper.extract_filename(from, @variables)
|
113
|
+
filename_to = Helper.extract_filename(to, @variables)
|
114
|
+
changes << [filename_from, filename_to]
|
115
|
+
File.rename(filename_from, filename_to)
|
116
|
+
end
|
117
|
+
|
118
|
+
def generate_event(event, matching_line)
|
119
|
+
if PARSER_ACTIONS.key?(event)
|
120
|
+
public_send(event, matching_line)
|
121
|
+
else
|
122
|
+
@definition_parser.public_send(event, matching_line)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Helper functions
|
127
|
+
module Helper
|
128
|
+
def self.extract_filename(include_statement, variables)
|
129
|
+
filename = filename_from_include_statement(include_statement)
|
130
|
+
|
131
|
+
filename_replace_all_variables(filename, variables).chomp
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.filename_from_include_statement(include_statement)
|
135
|
+
include_statement
|
136
|
+
.sub(Regexp.new(DMRegexp::INCLUDE_KEYWORD), '')
|
137
|
+
.sub(Regexp.new(DMRegexp::INCLUDE_OPTIONS), '')
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.filename_replace_all_variables(filename, variables)
|
141
|
+
filename.scan(DMRegexp::VARIABLE_USE) do
|
142
|
+
varname = Regexp.last_match[:varname]
|
143
|
+
value = variables.fetch(varname.to_sym)
|
144
|
+
filename = filename_replace_one_variable(filename, varname, value)
|
145
|
+
end
|
146
|
+
filename
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.filename_replace_one_variable(filename, varname, value)
|
150
|
+
filename.sub("{#{varname}}", value)
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.complete_regexp_from(from)
|
154
|
+
Regexp.new(
|
155
|
+
DMRegexp::INCLUDE_KEYWORD + DMRegexp::INCLUDE_PATH +
|
156
|
+
"(?<filename>#{from})" + DMRegexp::INCLUDE_OPTIONS
|
157
|
+
)
|
158
|
+
end
|
159
|
+
|
160
|
+
def self.text_with(match, to)
|
161
|
+
"include::#{match[:path]}#{to}[#{match[:options]}]"
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.hmerge(config, match)
|
165
|
+
config.merge(match.names.map(&:to_sym).zip(match.captures).to_h)
|
166
|
+
end
|
167
|
+
|
168
|
+
def self.variable_def_hash(match)
|
169
|
+
{ match[:varname].to_sym => match[:value] }
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.apply_filters_until_consumed(line)
|
173
|
+
LOCAL_FILTERS.each do |filter|
|
174
|
+
next unless line.match(filter.regexp)
|
175
|
+
|
176
|
+
yield(filter.event, Regexp.last_match)
|
177
|
+
break
|
178
|
+
end
|
179
|
+
end
|
13
180
|
end
|
14
181
|
end
|
15
182
|
end
|
@@ -1,21 +1,16 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'defmastership/constants'
|
5
|
+
require 'defmastership/update_def_modifier'
|
6
|
+
|
4
7
|
module DefMastership
|
5
|
-
#
|
6
|
-
class UpdateDefChecksumModifier <
|
7
|
-
|
8
|
-
%i[replace]
|
9
|
-
end
|
8
|
+
# modify one line after another
|
9
|
+
class UpdateDefChecksumModifier < UpdateDefModifier
|
10
|
+
private
|
10
11
|
|
11
|
-
def
|
12
|
-
document
|
13
|
-
adoc_texts.each do |adoc_file, _|
|
14
|
-
document.parse_file_with_preprocessor(adoc_file)
|
15
|
-
end
|
16
|
-
line_modifier = UpdateDefChecksumLineModifier.from_config(config)
|
17
|
-
line_modifier.document = document
|
18
|
-
line_modifier
|
12
|
+
def reference_replacement(reference, match)
|
13
|
+
"#{reference}(#{match[:explicit_version]}#{document.ref_to_def(reference).sha256_short})"
|
19
14
|
end
|
20
15
|
end
|
21
16
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Copyright (c) 2024 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module DefMastership
|
5
|
+
# absttrac class for modififier that need o update defintion references
|
6
|
+
class UpdateDefModifier
|
7
|
+
include Modifier
|
8
|
+
|
9
|
+
attr_reader :document
|
10
|
+
|
11
|
+
def self.default_config
|
12
|
+
{
|
13
|
+
def_type: ''
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.replacement_methods
|
18
|
+
%i[replace_reference]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.reference_regexp(reference)
|
22
|
+
Regexp.new("#{reference}#{DMRegexp::DEF_VERSION_AND_CHECKSUM}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(config)
|
26
|
+
@document = Document.new
|
27
|
+
|
28
|
+
setup_modifier_module(config)
|
29
|
+
end
|
30
|
+
|
31
|
+
def do_modifications(adoc_sources)
|
32
|
+
adoc_sources.each_key do |adoc_file|
|
33
|
+
document.parse_file_with_preprocessor(adoc_file)
|
34
|
+
end
|
35
|
+
|
36
|
+
super(adoc_sources)
|
37
|
+
end
|
38
|
+
|
39
|
+
def replace_reference(line)
|
40
|
+
match = line.match(DMRegexp::DEFINITION)
|
41
|
+
|
42
|
+
return line unless match
|
43
|
+
return line unless match[:type] == def_type
|
44
|
+
|
45
|
+
reference = match[:reference]
|
46
|
+
line.sub(self.class.reference_regexp(reference), reference_replacement(reference, match))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,25 +1,66 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'defmastership/constants'
|
5
|
+
require 'defmastership/update_def_modifier'
|
6
|
+
|
4
7
|
module DefMastership
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
# modify one line after another
|
9
|
+
class UpdateDefVersionModifier < UpdateDefModifier
|
10
|
+
def self.default_config
|
11
|
+
{
|
12
|
+
def_type: '',
|
13
|
+
ref_document: '',
|
14
|
+
first_version: ''
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(config)
|
19
|
+
@ref_document = Document.new
|
20
|
+
|
21
|
+
super(config)
|
22
|
+
end
|
23
|
+
|
24
|
+
def do_modifications(adoc_sources)
|
25
|
+
@ref_document.parse_file_with_preprocessor(config.fetch(:ref_document))
|
26
|
+
|
27
|
+
super(adoc_sources)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def reference_replacement(reference, match)
|
33
|
+
"#{reference}#{version_and_checksum_str(match)}"
|
10
34
|
end
|
11
35
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
36
|
+
def version_and_checksum_str(match)
|
37
|
+
explicit_checksum = match[:explicit_checksum]
|
38
|
+
version = version_string(match)
|
39
|
+
return unless explicit_checksum || version
|
40
|
+
|
41
|
+
"(#{version}#{explicit_checksum})"
|
42
|
+
end
|
43
|
+
|
44
|
+
def version_string(match)
|
45
|
+
ref_definition = Helper.def_from_match(@ref_document, match)
|
46
|
+
definition = Helper.def_from_match(document, match)
|
47
|
+
return unless ref_definition
|
48
|
+
|
49
|
+
Helper.ref_version(ref_definition, definition, config.fetch(:first_version))
|
50
|
+
end
|
51
|
+
|
52
|
+
# Helper functions
|
53
|
+
module Helper
|
54
|
+
def self.def_from_match(doc, match)
|
55
|
+
doc.ref_to_def(match[:reference])
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.ref_version(ref_definition, definition, first_version)
|
59
|
+
new_ref_version = ref_definition.explicit_version
|
60
|
+
return new_ref_version if definition.sha256_short == ref_definition.sha256_short
|
61
|
+
|
62
|
+
new_ref_version ? new_ref_version.next : first_version
|
16
63
|
end
|
17
|
-
ref_document = Document.new
|
18
|
-
ref_document.parse_file_with_preprocessor(config[:ref_document])
|
19
|
-
line_modifier = UpdateDefVersionLineModifier.from_config(config)
|
20
|
-
line_modifier.document = document
|
21
|
-
line_modifier.ref_document = ref_document
|
22
|
-
line_modifier
|
23
64
|
end
|
24
65
|
end
|
25
66
|
end
|
data/lib/defmastership.rb
CHANGED
@@ -6,7 +6,6 @@ require('defmastership/version')
|
|
6
6
|
# Add requires for other files you add to your project here, so
|
7
7
|
# you just need to require this one file in your bin file
|
8
8
|
require('defmastership/batch_modifier')
|
9
|
-
require('defmastership/change_ref_line_modifier')
|
10
9
|
require('defmastership/change_ref_modifier')
|
11
10
|
require('defmastership/comment_filter')
|
12
11
|
require('defmastership/constants')
|
@@ -15,12 +14,8 @@ require('defmastership/definition')
|
|
15
14
|
require('defmastership/definition_parser')
|
16
15
|
require('defmastership/document')
|
17
16
|
require('defmastership/filters')
|
18
|
-
require('defmastership/
|
19
|
-
require('defmastership/modifier_base')
|
17
|
+
require('defmastership/modifier_factory')
|
20
18
|
require('defmastership/parsing_state')
|
21
|
-
require('defmastership/rename_included_files_line_modifier')
|
22
19
|
require('defmastership/rename_included_files_modifier')
|
23
|
-
require('defmastership/update_def_checksum_line_modifier')
|
24
20
|
require('defmastership/update_def_checksum_modifier')
|
25
|
-
require('defmastership/update_def_version_line_modifier')
|
26
21
|
require('defmastership/update_def_version_modifier')
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
require('aasm/rspec')
|
5
5
|
require('aruba/rspec')
|
6
|
-
require('bundler/setup')
|
7
6
|
|
8
7
|
# formatter = [SimpleCov::Formatter::HTMLFormatter]
|
9
8
|
# SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(formatter)
|
@@ -18,8 +17,11 @@ SimpleCov.start do
|
|
18
17
|
|
19
18
|
add_filter 'config'
|
20
19
|
add_filter 'vendor'
|
20
|
+
add_filter 'set_join_hack'
|
21
21
|
|
22
22
|
minimum_coverage 100
|
23
|
+
|
24
|
+
enable_coverage :branch
|
23
25
|
end
|
24
26
|
|
25
27
|
RSpec.configure do |config|
|
@@ -1,29 +1,31 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require('defmastership')
|
4
|
+
require('defmastership/batch_modifier')
|
5
5
|
|
6
6
|
module DefMastership
|
7
|
-
class
|
7
|
+
class TotoModifier
|
8
|
+
include Modifier
|
8
9
|
end
|
9
10
|
|
10
|
-
class
|
11
|
+
class TuTuModifier
|
12
|
+
include Modifier
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
16
|
RSpec.describe(DefMastership::BatchModifier) do
|
15
17
|
subject(:batchmodifier) do
|
16
|
-
described_class.new(config,
|
18
|
+
described_class.new(config, adoc_sources)
|
17
19
|
end
|
18
20
|
|
19
21
|
let(:config) do
|
20
22
|
{
|
21
|
-
modifier1: { type: '
|
22
|
-
modifier2: { type: '
|
23
|
-
modifier3: { type: '
|
23
|
+
modifier1: { type: 'toto', config: { p: 1 } },
|
24
|
+
modifier2: { type: 'toto', config: { p: 'whatever1' } },
|
25
|
+
modifier3: { type: 'tu_tu', config: { p1: 'whatever2', p2: 'whatever3' } }
|
24
26
|
}
|
25
27
|
end
|
26
|
-
let(:
|
28
|
+
let(:adoc_sources) do
|
27
29
|
{
|
28
30
|
'file1.adoc' => 'some text',
|
29
31
|
'file2.adoc' => 'another text'
|
@@ -35,14 +37,14 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
35
37
|
it { is_expected.to(have_attributes(config: config)) }
|
36
38
|
|
37
39
|
it do
|
38
|
-
expect(batchmodifier).to(have_attributes(
|
40
|
+
expect(batchmodifier).to(have_attributes(adoc_sources: adoc_sources))
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
describe '#apply' do
|
43
45
|
context 'with only one modification' do
|
44
|
-
let(:toto1) { instance_double(DefMastership::
|
45
|
-
let(:
|
46
|
+
let(:toto1) { instance_double(DefMastership::TotoModifier, 'toto1') }
|
47
|
+
let(:adoc_sources_modified) do
|
46
48
|
{
|
47
49
|
'file1.adoc' => 'some text modified',
|
48
50
|
'file2.adoc' => 'another text'
|
@@ -51,26 +53,26 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
51
53
|
|
52
54
|
let(:config_modified) do
|
53
55
|
{
|
54
|
-
modifier1: { type: '
|
55
|
-
modifier2: { type: '
|
56
|
-
modifier3: { type: '
|
56
|
+
modifier1: { type: 'toto', config: { p: 'modified_param' } },
|
57
|
+
modifier2: { type: 'toto', config: { p: 'whatever1' } },
|
58
|
+
modifier3: { type: 'tu_tu', config: { p1: 'whatever2', p2: 'whatever3' } }
|
57
59
|
}
|
58
60
|
end
|
59
61
|
|
60
62
|
before do
|
61
|
-
allow(DefMastership::
|
62
|
-
allow(toto1).to(receive(:do_modifications).once.and_return(
|
63
|
+
allow(DefMastership::TotoModifier).to(receive(:new).once.and_return(toto1))
|
64
|
+
allow(toto1).to(receive(:do_modifications).once.and_return(adoc_sources_modified))
|
63
65
|
allow(toto1).to(receive(:config).once.and_return(p: 'modified_param'))
|
64
66
|
allow(toto1).to(receive(:changes).once.and_return([%w[from1 to1], %w[from2 to2]]))
|
65
|
-
batchmodifier.apply(
|
67
|
+
batchmodifier.apply(%i[modifier1])
|
66
68
|
end
|
67
69
|
|
68
70
|
it do
|
69
|
-
expect(DefMastership::
|
71
|
+
expect(DefMastership::TotoModifier).to(have_received(:new).with(p: 1))
|
70
72
|
end
|
71
73
|
|
72
|
-
it { expect(toto1).to(have_received(:do_modifications).with(
|
73
|
-
it { is_expected.to(have_attributes(
|
74
|
+
it { expect(toto1).to(have_received(:do_modifications).with(adoc_sources)) }
|
75
|
+
it { is_expected.to(have_attributes(adoc_sources: adoc_sources_modified)) }
|
74
76
|
it { expect(toto1).to(have_received(:config).with(no_args)) }
|
75
77
|
|
76
78
|
it { is_expected.to(have_attributes(config: config_modified)) }
|
@@ -78,43 +80,43 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
78
80
|
end
|
79
81
|
|
80
82
|
context 'with two modifications' do
|
81
|
-
let(:toto2) { instance_double(DefMastership::
|
82
|
-
let(:tutu3) { instance_double(DefMastership::
|
83
|
+
let(:toto2) { instance_double(DefMastership::TotoModifier, 'toto2') }
|
84
|
+
let(:tutu3) { instance_double(DefMastership::TuTuModifier, 'tutu3') }
|
83
85
|
|
84
86
|
let(:config_modified) do
|
85
87
|
{
|
86
|
-
modifier1: { type: '
|
87
|
-
modifier2: { type: '
|
88
|
-
modifier3: { type: '
|
88
|
+
modifier1: { type: 'toto', config: { p: 1 } },
|
89
|
+
modifier2: { type: 'toto', config: :whatever },
|
90
|
+
modifier3: { type: 'tu_tu', config: :pouet }
|
89
91
|
}
|
90
92
|
end
|
91
93
|
|
92
94
|
before do
|
93
|
-
allow(DefMastership::
|
94
|
-
allow(toto2).to(receive(:do_modifications).once.and_return(:
|
95
|
+
allow(DefMastership::TotoModifier).to(receive(:new).once.and_return(toto2))
|
96
|
+
allow(toto2).to(receive(:do_modifications).once.and_return(:adoc_sources_modified_mod2))
|
95
97
|
allow(toto2).to(receive(:config).once.and_return(:whatever))
|
96
|
-
allow(DefMastership::
|
97
|
-
allow(tutu3).to(receive(:do_modifications).once.and_return(:
|
98
|
+
allow(DefMastership::TuTuModifier).to(receive(:new).once.and_return(tutu3))
|
99
|
+
allow(tutu3).to(receive(:do_modifications).once.and_return(:adoc_sources_modified_mod3))
|
98
100
|
allow(tutu3).to(receive(:config).once.and_return(:pouet))
|
99
101
|
allow(toto2).to(receive(:changes).once.and_return([%w[from1 to1]]))
|
100
102
|
allow(tutu3).to(receive(:changes).once.and_return([%w[from2 to2]]))
|
101
|
-
batchmodifier.apply(
|
103
|
+
batchmodifier.apply(%i[modifier2 modifier3])
|
102
104
|
end
|
103
105
|
|
104
|
-
it { expect(DefMastership::
|
105
|
-
it { expect(DefMastership::
|
106
|
-
it { expect(toto2).to(have_received(:do_modifications).with(
|
106
|
+
it { expect(DefMastership::TotoModifier).to(have_received(:new).with(p: 'whatever1')) }
|
107
|
+
it { expect(DefMastership::TuTuModifier).to(have_received(:new).with(p1: 'whatever2', p2: 'whatever3')) }
|
108
|
+
it { expect(toto2).to(have_received(:do_modifications).with(adoc_sources)) }
|
107
109
|
it { expect(toto2).to(have_received(:config).with(no_args)) }
|
108
|
-
it { expect(tutu3).to(have_received(:do_modifications).with(:
|
110
|
+
it { expect(tutu3).to(have_received(:do_modifications).with(:adoc_sources_modified_mod2)) }
|
109
111
|
it { expect(tutu3).to(have_received(:config).with(no_args)) }
|
110
|
-
it { is_expected.to(have_attributes(
|
112
|
+
it { is_expected.to(have_attributes(adoc_sources: :adoc_sources_modified_mod3)) }
|
111
113
|
it { is_expected.to(have_attributes(config: config_modified)) }
|
112
114
|
it { is_expected.to(have_attributes(changes: [%w[modifier2 from1 to1], %w[modifier3 from2 to2]])) }
|
113
115
|
end
|
114
116
|
|
115
117
|
context 'with wrong modification' do
|
116
118
|
it do
|
117
|
-
expect { batchmodifier.apply(
|
119
|
+
expect { batchmodifier.apply(%i[wrong-modification]) }
|
118
120
|
.to(
|
119
121
|
raise_error(ArgumentError, 'wrong-modification is not a known modification')
|
120
122
|
)
|