defmastership 1.0.3 → 1.0.8

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.gitlab-ci.yml +0 -1
  4. data/.rubocop.yml +3 -2
  5. data/Gemfile +1 -0
  6. data/LICENSE +22 -0
  7. data/Rakefile +2 -2
  8. data/bin/defmastership +37 -24
  9. data/cucumber.yml +2 -0
  10. data/defmastership.gemspec +16 -9
  11. data/features/changeref.feature +82 -129
  12. data/features/definition_checksum.feature +244 -0
  13. data/features/definition_version.feature +24 -0
  14. data/features/export.feature +49 -31
  15. data/features/modify.feature +165 -0
  16. data/features/rename_included_files.feature +121 -0
  17. data/features/step_definitions/defmastership_steps.rb +1 -0
  18. data/features/support/env.rb +1 -0
  19. data/lib/defmastership.rb +15 -3
  20. data/lib/defmastership/batch_modifier.rb +35 -0
  21. data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +19 -35
  22. data/lib/defmastership/change_ref_modifier.rb +15 -0
  23. data/lib/defmastership/comment_filter.rb +1 -0
  24. data/lib/defmastership/constants.rb +15 -1
  25. data/lib/defmastership/csv_formatter.rb +26 -19
  26. data/lib/defmastership/csv_formatter_body.rb +20 -11
  27. data/lib/defmastership/csv_formatter_header.rb +16 -10
  28. data/lib/defmastership/definition.rb +15 -3
  29. data/lib/defmastership/definition_parser.rb +46 -0
  30. data/lib/defmastership/document.rb +60 -85
  31. data/lib/defmastership/filters.rb +30 -0
  32. data/lib/defmastership/line_modifier_base.rb +29 -0
  33. data/lib/defmastership/modifier_base.rb +29 -0
  34. data/lib/defmastership/rename_included_files_line_modifier.rb +126 -0
  35. data/lib/defmastership/rename_included_files_modifier.rb +15 -0
  36. data/lib/defmastership/update_def_checksum_line_modifier.rb +39 -0
  37. data/lib/defmastership/update_def_checksum_modifier.rb +21 -0
  38. data/lib/defmastership/version.rb +2 -1
  39. data/spec/spec_helper.rb +2 -0
  40. data/spec/unit/defmastership/batch_modifier_spec.rb +123 -0
  41. data/spec/unit/defmastership/{ref_changer_spec.rb → change_ref_line_modifier_spec.rb} +49 -26
  42. data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
  43. data/spec/unit/defmastership/comment_filter_spec.rb +9 -4
  44. data/spec/unit/defmastership/csv_formatter_body_spec.rb +89 -82
  45. data/spec/unit/defmastership/csv_formatter_header_spec.rb +69 -22
  46. data/spec/unit/defmastership/csv_formatter_spec.rb +209 -110
  47. data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
  48. data/spec/unit/defmastership/definition_spec.rb +46 -4
  49. data/spec/unit/defmastership/document_spec.rb +237 -35
  50. data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +203 -0
  51. data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +67 -0
  52. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +68 -0
  53. data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +75 -0
  54. data/spec/unit/defmastership_spec.rb +1 -0
  55. metadata +49 -17
  56. data/Gemfile.lock +0 -140
  57. data/lib/defmastership/batch_changer.rb +0 -40
  58. data/lib/defmastership/project_ref_changer.rb +0 -27
  59. data/spec/unit/defmastership/batch_changer_spec.rb +0 -108
  60. data/spec/unit/defmastership/project_ref_changer_spec.rb +0 -79
@@ -0,0 +1,30 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # Contains regexp / action couples
6
+ Filter = Struct.new(:regexp, :event, :consumed_line)
7
+ private_constant :Filter
8
+
9
+ FILTERS_IN_LITERAL = [
10
+ Filter.new(DMRegexp::LITERAL_BLOCK, :code_block_delimiter, false),
11
+ Filter.new(DMRegexp::WHATEVER, :new_line, true)
12
+ ].freeze
13
+ private_constant :FILTERS_IN_LITERAL
14
+
15
+ FILTERS = [
16
+ Filter.new(DMRegexp::VARIABLE_DEF, :new_variable_def, false),
17
+ Filter.new(DMRegexp::VARIABLE_USE, :new_variable_use, false),
18
+ Filter.new(DMRegexp::DEFINITION, :new_definition, true),
19
+ Filter.new(DMRegexp::EREF_CONFIG, :new_eref_setup, true),
20
+ Filter.new(DMRegexp::EREF_DEF, :new_eref_def, false),
21
+ Filter.new(DMRegexp::IREF_DEF, :new_iref_def, false),
22
+ Filter.new(DMRegexp::ATTR_CONFIG, :new_attribute_conf, true),
23
+ Filter.new(DMRegexp::ATTR_SET, :new_attribute_value, false),
24
+ Filter.new(DMRegexp::BLOCK, :block_delimiter, true),
25
+ Filter.new(DMRegexp::LITERAL_BLOCK, :code_block_delimiter, true),
26
+ Filter.new(DMRegexp::EMPTY_LINE, :empty_line, false),
27
+ Filter.new(DMRegexp::WHATEVER, :new_line, true)
28
+ ].freeze
29
+ private_constant :FILTERS
30
+ end
@@ -0,0 +1,29 @@
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 LineModifierBase
7
+ attr_reader :changes, :config
8
+
9
+ def initialize
10
+ @config = {}
11
+ @changes = []
12
+ end
13
+
14
+ def method_missing(method_name, *args, &block)
15
+ return @config[method_name] if @config[method_name]
16
+
17
+ super
18
+ end
19
+
20
+ def respond_to_missing?(method_name, *args)
21
+ @config[method_name] || super
22
+ end
23
+
24
+ def from_config(config)
25
+ @config.merge!(config)
26
+ self
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
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 ModifierBase
7
+ attr_reader :config, :changes
8
+
9
+ def initialize(config)
10
+ @config = config
11
+ @changes = []
12
+ end
13
+
14
+ def do_modifications(adoc_texts)
15
+ line_modifier = new_line_modifier(@config, adoc_texts)
16
+
17
+ adoc_texts =
18
+ replacements.reduce(adoc_texts) do |texts, method|
19
+ texts.transform_values do |text|
20
+ text.lines.map { |line| line_modifier.public_send(method, line) }.join
21
+ end
22
+ end
23
+
24
+ @config = line_modifier.config
25
+ @changes = line_modifier.changes
26
+ adoc_texts
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,126 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # Change included filenames on one line at a time
6
+ class RenameIncludedFilesLineModifier < LineModifierBase
7
+ LOCAL_FILTERS = [
8
+ Filter.new(DMRegexp::VARIABLE_DEF, :new_variable_def, false),
9
+ Filter.new(DMRegexp::DEFINITION, :new_definition, true),
10
+ Filter.new(DMRegexp::BLOCK, :block_delimiter, true),
11
+ Filter.new(DMRegexp::EMPTY_LINE, :empty_line, false),
12
+ Filter.new(DMRegexp::WHATEVER, :new_line, true)
13
+ ].freeze
14
+ private_constant :LOCAL_FILTERS
15
+
16
+ def self.from_config(config)
17
+ new.from_config(config)
18
+ end
19
+
20
+ def initialize
21
+ super
22
+ @config = {
23
+ from_regexp: '',
24
+ to_template: ''
25
+ }
26
+ @variables = {}
27
+ @definition_parser = DefinitionParser.new(self)
28
+ end
29
+
30
+ def replace(line)
31
+ match = matched?(line)
32
+
33
+ return line unless match
34
+
35
+ new_line =
36
+ line.gsub(complete_regexp_from(from_regexp)) do
37
+ text_with(match, to_template % hmerge(match))
38
+ end
39
+
40
+ rename_file(line, new_line)
41
+
42
+ new_line
43
+ end
44
+
45
+ def add_new_definition(match, _line)
46
+ @config[:reference] = match[:reference]
47
+ end
48
+
49
+ def add_line(_match, _line) end
50
+
51
+ def new_variable_def(match, line)
52
+ @variables[match[:varname].to_sym] = match[:value]
53
+ line
54
+ end
55
+
56
+ private
57
+
58
+ def matched?(line)
59
+ return if line.commented?
60
+
61
+ parse(line)
62
+
63
+ return if @definition_parser.idle?
64
+ return unless line =~ complete_regexp_from(from_regexp)
65
+
66
+ match = Regexp.last_match
67
+
68
+ return if @config[:cancel_if_match] && match[:filename] =~ Regexp.new(cancel_if_match)
69
+
70
+ match
71
+ end
72
+
73
+ def parse(line)
74
+ LOCAL_FILTERS.each do |filter|
75
+ next unless line.match(filter.regexp)
76
+
77
+ line = generate_event(filter.event, Regexp.last_match, line)
78
+
79
+ break if filter.consumed_line
80
+ end
81
+ end
82
+
83
+ def rename_file(from, to)
84
+ @changes << [extract_filename(from), extract_filename(to)]
85
+ File.rename(extract_filename(from), extract_filename(to))
86
+ end
87
+
88
+ def extract_filename(include_statement)
89
+ filename = include_statement
90
+ .gsub(Regexp.new(DMRegexp::INCLUDE_KEYWORD), '')
91
+ .gsub(Regexp.new(DMRegexp::INCLUDE_OPTIONS), '')
92
+
93
+ filename.dup.scan(DMRegexp::VARIABLE_USE) do |_|
94
+ varname = Regexp.last_match[:varname]
95
+ next if @variables[varname.to_sym].nil?
96
+
97
+ filename.gsub!("{#{varname}}", @variables[varname.to_sym])
98
+ end
99
+ filename
100
+ end
101
+
102
+ def complete_regexp_from(from)
103
+ Regexp.new(
104
+ DMRegexp::INCLUDE_KEYWORD + DMRegexp::INCLUDE_PATH +
105
+ "(?<filename>#{from})" + DMRegexp::INCLUDE_OPTIONS
106
+ )
107
+ end
108
+
109
+ def text_with(match, to)
110
+ "include::#{match[:path] || ''}#{to}[#{match[:options]}]"
111
+ end
112
+
113
+ def hmerge(match)
114
+ @config.merge(match.names.map(&:to_sym).zip(match.captures).to_h)
115
+ end
116
+
117
+ def generate_event(event, match, line)
118
+ if respond_to?(event)
119
+ public_send(event, match, line)
120
+ else
121
+ @definition_parser.public_send(event, match, line)
122
+ end
123
+ line
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,15 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # Change included filenames
6
+ class RenameIncludedFilesModifier < ModifierBase
7
+ def replacements
8
+ %i[replace]
9
+ end
10
+
11
+ def new_line_modifier(config, _adoc_texts)
12
+ RenameIncludedFilesLineModifier.from_config(config)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # modify one line after another
6
+ class UpdateDefChecksumLineModifier < LineModifierBase
7
+ attr_accessor :document
8
+
9
+ def self.from_config(hash)
10
+ new.from_config(hash)
11
+ end
12
+
13
+ def initialize
14
+ super
15
+ @config = {
16
+ def_type: ''
17
+ }
18
+ end
19
+
20
+ def replace(line)
21
+ match = matched?(line)
22
+
23
+ return line unless match
24
+ return line unless match[:type] == def_type
25
+
26
+ explicit_checksum_str = match[:explicit_checksum].nil? ? '' : "(#{match[:explicit_checksum]})"
27
+ line.gsub("#{match[:reference]}#{explicit_checksum_str}") do
28
+ "#{match[:reference]}(#{@document.ref_to_def(match[:reference]).sha256})"
29
+ end
30
+ end
31
+
32
+ def matched?(line)
33
+ return if line.commented?
34
+ return unless line =~ DMRegexp::DEFINITION
35
+
36
+ Regexp.last_match
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # Update definition checksum wih calculated one
6
+ class UpdateDefChecksumModifier < ModifierBase
7
+ def replacements
8
+ %i[replace]
9
+ end
10
+
11
+ def new_line_modifier(config, adoc_texts)
12
+ document = Document.new
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
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,7 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  module DefMastership
4
- VERSION = '1.0.3'
5
+ VERSION = '1.0.8'
5
6
  public_constant :VERSION
6
7
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('bundler/setup')
4
5
  require('aruba/rspec')
6
+ require('aasm/rspec')
5
7
 
6
8
  # formatter = [SimpleCov::Formatter::HTMLFormatter]
7
9
  # SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(formatter)
@@ -0,0 +1,123 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ module DefMastership
7
+ class TotoClassModifier < ModifierBase
8
+ end
9
+
10
+ class TutuClassModifier < ModifierBase
11
+ end
12
+ end
13
+
14
+ RSpec.describe(DefMastership::BatchModifier) do
15
+ subject(:batchmodifier) do
16
+ described_class.new(config, adoc_texts)
17
+ end
18
+
19
+ let(:config) do
20
+ {
21
+ modifier1: { type: 'toto_class', config: { p: 1 } },
22
+ modifier2: { type: 'toto_class', config: { p: 'whatever1' } },
23
+ modifier3: { type: 'tutu_class', config: { p1: 'whatever2', p2: 'whatever3' } }
24
+ }
25
+ end
26
+ let(:adoc_texts) do
27
+ {
28
+ 'file1.adoc' => 'some text',
29
+ 'file2.adoc' => 'another text'
30
+ }
31
+ end
32
+
33
+ describe '.new' do
34
+ it { is_expected.not_to(be(nil)) }
35
+ it { is_expected.to(have_attributes(config: config)) }
36
+
37
+ it do
38
+ expect(batchmodifier).to(have_attributes(adoc_texts: adoc_texts))
39
+ end
40
+ end
41
+
42
+ describe '#apply' do
43
+ context 'with only one modification' do
44
+ let(:toto1) { instance_double(DefMastership::TotoClassModifier, 'toto1') }
45
+ let(:adoc_texts_modified) do
46
+ {
47
+ 'file1.adoc' => 'some text modified',
48
+ 'file2.adoc' => 'another text'
49
+ }
50
+ end
51
+
52
+ let(:config_modified) do
53
+ {
54
+ modifier1: { type: 'toto_class', config: { p: 'modified_param' } },
55
+ modifier2: { type: 'toto_class', config: { p: 'whatever1' } },
56
+ modifier3: { type: 'tutu_class', config: { p1: 'whatever2', p2: 'whatever3' } }
57
+ }
58
+ end
59
+
60
+ before do
61
+ allow(DefMastership::TotoClassModifier).to(receive(:new).once.and_return(toto1))
62
+ allow(toto1).to(receive(:do_modifications).once.and_return(adoc_texts_modified))
63
+ allow(toto1).to(receive(:config).once.and_return(p: 'modified_param'))
64
+ allow(toto1).to(receive(:changes).once.and_return([%w[from1 to1], %w[from2 to2]]))
65
+ batchmodifier.apply('modifier1')
66
+ end
67
+
68
+ it do
69
+ expect(DefMastership::TotoClassModifier).to(have_received(:new).with(p: 1))
70
+ end
71
+
72
+ it { expect(toto1).to(have_received(:do_modifications).with(adoc_texts)) }
73
+ it { is_expected.to(have_attributes(adoc_texts: adoc_texts_modified)) }
74
+ it { expect(toto1).to(have_received(:config).with(no_args)) }
75
+
76
+ it { is_expected.to(have_attributes(config: config_modified)) }
77
+ it { is_expected.to(have_attributes(changes: [%w[modifier1 from1 to1], %w[modifier1 from2 to2]])) }
78
+ end
79
+
80
+ context 'with two modifications' do
81
+ let(:toto2) { instance_double(DefMastership::TotoClassModifier, 'toto2') }
82
+ let(:tutu3) { instance_double(DefMastership::TutuClassModifier, 'tutu3') }
83
+
84
+ let(:config_modified) do
85
+ {
86
+ modifier1: { type: 'toto_class', config: { p: 1 } },
87
+ modifier2: { type: 'toto_class', config: :whatever },
88
+ modifier3: { type: 'tutu_class', config: :pouet }
89
+ }
90
+ end
91
+
92
+ before do
93
+ allow(DefMastership::TotoClassModifier).to(receive(:new).once.and_return(toto2))
94
+ allow(toto2).to(receive(:do_modifications).once.and_return(:adoc_texts_modified_mod2))
95
+ allow(toto2).to(receive(:config).once.and_return(:whatever))
96
+ allow(DefMastership::TutuClassModifier).to(receive(:new).once.and_return(tutu3))
97
+ allow(tutu3).to(receive(:do_modifications).once.and_return(:adoc_texts_modified_mod3))
98
+ allow(tutu3).to(receive(:config).once.and_return(:pouet))
99
+ allow(toto2).to(receive(:changes).once.and_return([%w[from1 to1]]))
100
+ allow(tutu3).to(receive(:changes).once.and_return([%w[from2 to2]]))
101
+ batchmodifier.apply('modifier2, modifier3')
102
+ end
103
+
104
+ it { expect(DefMastership::TotoClassModifier).to(have_received(:new).with(p: 'whatever1')) }
105
+ it { expect(DefMastership::TutuClassModifier).to(have_received(:new).with(p1: 'whatever2', p2: 'whatever3')) }
106
+ it { expect(toto2).to(have_received(:do_modifications).with(adoc_texts)) }
107
+ it { expect(toto2).to(have_received(:config).with(no_args)) }
108
+ it { expect(tutu3).to(have_received(:do_modifications).with(:adoc_texts_modified_mod2)) }
109
+ it { expect(tutu3).to(have_received(:config).with(no_args)) }
110
+ it { is_expected.to(have_attributes(adoc_texts: :adoc_texts_modified_mod3)) }
111
+ it { is_expected.to(have_attributes(config: config_modified)) }
112
+ it { is_expected.to(have_attributes(changes: [%w[modifier2 from1 to1], %w[modifier3 from2 to2]])) }
113
+ end
114
+
115
+ context 'with wrong modification' do
116
+ it do
117
+ expect { batchmodifier.apply('wrong-modification') }.to(
118
+ raise_error(ArgumentError, 'wrong-modification is not a known modification')
119
+ )
120
+ end
121
+ end
122
+ end
123
+ end
@@ -1,8 +1,9 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('defmastership')
4
5
 
5
- RSpec.describe(DefMastership::RefChanger) do
6
+ RSpec.describe(DefMastership::ChangeRefLineModifier) do
6
7
  subject(:refchanger) { described_class.new }
7
8
 
8
9
  describe '.new' do
@@ -14,9 +15,9 @@ RSpec.describe(DefMastership::RefChanger) do
14
15
  it { expect { refchanger.user_defined_attribute }.to(raise_error(NoMethodError)) }
15
16
  end
16
17
 
17
- describe '.from_h' do
18
+ describe '.from_config' do
18
19
  subject(:refchanger) do
19
- described_class.from_h(
20
+ described_class.from_config(
20
21
  from_regexp: 'Whatever.+',
21
22
  to_template: 'Whatever',
22
23
  next_ref: 17
@@ -29,9 +30,9 @@ RSpec.describe(DefMastership::RefChanger) do
29
30
  it { is_expected.to(have_attributes(next_ref: 17)) }
30
31
  end
31
32
 
32
- describe '#from_h' do
33
+ describe '#from_config' do
33
34
  before do
34
- refchanger.from_h(
35
+ refchanger.from_config(
35
36
  from_regexp: 'Whatever.+',
36
37
  to_template: 'Whatever',
37
38
  next_ref: 17,
@@ -45,36 +46,34 @@ RSpec.describe(DefMastership::RefChanger) do
45
46
  it { is_expected.to(have_attributes(user_defined_attribute: 'Tadaam')) }
46
47
  end
47
48
 
48
- describe '#to_h' do
49
+ describe '#config' do
49
50
  context 'when not initalized' do
50
51
  it do
51
- expect(refchanger.to_h).to(include(
52
- from_regexp: '',
53
- to_template: '',
54
- next_ref: 0
55
- ))
52
+ expect(refchanger.config).to(
53
+ include(from_regexp: '', to_template: '', next_ref: 0)
54
+ )
56
55
  end
57
56
  end
58
57
 
59
58
  context 'when initalized with additionnal keys' do
60
59
  before do
61
- refchanger.from_h(
60
+ refchanger.from_config(
62
61
  next_ref: 1256,
63
62
  user_defined_attribute: 'Tadaam'
64
63
  )
65
64
  end
66
65
 
67
- it { expect(refchanger.to_h).to(include(from_regexp: '')) }
68
- it { expect(refchanger.to_h).to(include(to_template: '')) }
69
- it { expect(refchanger.to_h).to(include(next_ref: 1256)) }
70
- it { expect(refchanger.to_h).to(include(user_defined_attribute: 'Tadaam')) }
66
+ it { expect(refchanger.config).to(include(from_regexp: '')) }
67
+ it { expect(refchanger.config).to(include(to_template: '')) }
68
+ it { expect(refchanger.config).to(include(next_ref: 1256)) }
69
+ it { expect(refchanger.config).to(include(user_defined_attribute: 'Tadaam')) }
71
70
  end
72
71
  end
73
72
 
74
- describe '#replace_definitions' do
73
+ describe '#replace_def' do
75
74
  context 'when really simple rule' do
76
75
  before do
77
- refchanger.from_h(
76
+ refchanger.from_config(
78
77
  from_regexp: 'TEMP',
79
78
  to_template: 'TUTU'
80
79
  )
@@ -97,7 +96,7 @@ RSpec.describe(DefMastership::RefChanger) do
97
96
 
98
97
  context 'when template is variable' do
99
98
  before do
100
- refchanger.from_h(
99
+ refchanger.from_config(
101
100
  from_regexp: 'TEMP',
102
101
  to_template: 'TOTO-%<next_ref>04d',
103
102
  next_ref: 124
@@ -117,7 +116,7 @@ RSpec.describe(DefMastership::RefChanger) do
117
116
 
118
117
  context 'when capture group in regexp' do
119
118
  before do
120
- refchanger.from_h(
119
+ refchanger.from_config(
121
120
  from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
122
121
  to_template: '%<cg>s-%<next_ref>04d',
123
122
  next_ref: 132
@@ -144,7 +143,7 @@ RSpec.describe(DefMastership::RefChanger) do
144
143
 
145
144
  context 'when definition is in literal block' do
146
145
  before do
147
- refchanger.from_h(
146
+ refchanger.from_config(
148
147
  from_regexp: 'TEMP',
149
148
  to_template: 'TUTU'
150
149
  )
@@ -159,7 +158,7 @@ RSpec.describe(DefMastership::RefChanger) do
159
158
 
160
159
  context 'when defintion is after literal block' do
161
160
  before do
162
- refchanger.from_h(
161
+ refchanger.from_config(
163
162
  from_regexp: 'TEMP',
164
163
  to_template: 'TUTU'
165
164
  )
@@ -177,7 +176,7 @@ RSpec.describe(DefMastership::RefChanger) do
177
176
 
178
177
  describe '#replace_irefs' do
179
178
  before do
180
- refchanger.from_h(
179
+ refchanger.from_config(
181
180
  from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
182
181
  to_template: '%<cg>s-%<next_ref>04d',
183
182
  next_ref: 132
@@ -197,9 +196,33 @@ RSpec.describe(DefMastership::RefChanger) do
197
196
  end
198
197
 
199
198
  it do
200
- expect(refchanger.replace_irefs('defs:iref[TOTO-TEMP123] ' \
201
- 'defs:iref[TITI-TEMP421] bla'))
202
- .to(eq('defs:iref[TOTO-0132] defs:iref[TITI-0133] bla'))
199
+ expect(
200
+ refchanger.replace_irefs(
201
+ 'defs:iref[TOTO-TEMP123] defs:iref[TITI-TEMP421] bla'
202
+ )
203
+ ).to(eq('defs:iref[TOTO-0132] defs:iref[TITI-0133] bla'))
204
+ end
205
+ end
206
+
207
+ describe '#replace' do
208
+ before do
209
+ refchanger.from_config(
210
+ from_regexp: 'TEMP',
211
+ to_template: 'TUTU'
212
+ )
213
+ end
214
+
215
+ it do
216
+ expect(refchanger.replace(:refdef, '[define, whatever, TEMP]'))
217
+ .to(eq('[define, whatever, TUTU]'))
203
218
  end
219
+
220
+ it do
221
+ refchanger.replace(:refdef, '[define, whatever, TEMP]')
222
+ expect(refchanger.replace(:irefs, 'defs:iref[TEMP]'))
223
+ .to(eq('defs:iref[TUTU]'))
224
+ end
225
+
226
+ it { expect { refchanger.replace(:pouet, 'whatever') }.to(raise_error(NoMethodError)) }
204
227
  end
205
228
  end