defmastership 1.0.16 → 1.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +50 -7
  4. data/.rubocop.yml +14 -6
  5. data/Gemfile +51 -1
  6. data/Rakefile +16 -47
  7. data/bin/defmastership +12 -9
  8. data/config/mutant.yml +23 -3
  9. data/defmastership.gemspec +22 -27
  10. data/features/definition_checksum.feature +31 -1
  11. data/features/export.feature +43 -1
  12. data/features/rename_included_files.feature +28 -0
  13. data/lib/defmastership/batch_modifier.rb +17 -12
  14. data/lib/defmastership/change_ref_modifier.rb +89 -5
  15. data/lib/defmastership/comment_filter.rb +1 -1
  16. data/lib/defmastership/constants.rb +5 -4
  17. data/lib/defmastership/csv_formatter.rb +20 -16
  18. data/lib/defmastership/csv_formatter_body.rb +18 -15
  19. data/lib/defmastership/csv_formatter_header.rb +1 -1
  20. data/lib/defmastership/definition.rb +58 -19
  21. data/lib/defmastership/document.rb +109 -74
  22. data/lib/defmastership/matching_line.rb +17 -0
  23. data/lib/defmastership/modifier.rb +42 -0
  24. data/lib/defmastership/modifier_factory.rb +12 -0
  25. data/lib/defmastership/parsing_state.rb +15 -9
  26. data/lib/defmastership/rename_included_files_modifier.rb +172 -5
  27. data/lib/defmastership/set_join_hack.rb +11 -0
  28. data/lib/defmastership/update_def_checksum_modifier.rb +8 -13
  29. data/lib/defmastership/update_def_modifier.rb +49 -0
  30. data/lib/defmastership/update_def_version_modifier.rb +56 -15
  31. data/lib/defmastership/version.rb +1 -1
  32. data/lib/defmastership.rb +7 -17
  33. data/spec/spec_helper.rb +4 -2
  34. data/spec/unit/{defmastership → def_mastership}/batch_modifier_spec.rb +42 -39
  35. data/spec/unit/{defmastership/change_ref_line_modifier_spec.rb → def_mastership/change_ref_modifier_spec.rb} +44 -66
  36. data/spec/unit/{defmastership → def_mastership}/csv_formatter_body_spec.rb +61 -32
  37. data/spec/unit/{defmastership → def_mastership}/csv_formatter_header_spec.rb +2 -2
  38. data/spec/unit/{defmastership → def_mastership}/csv_formatter_spec.rb +81 -86
  39. data/spec/unit/{defmastership → def_mastership}/definition_parser_spec.rb +2 -2
  40. data/spec/unit/{defmastership → def_mastership}/definition_spec.rb +17 -7
  41. data/spec/unit/{defmastership → def_mastership}/document_spec.rb +108 -53
  42. data/spec/unit/def_mastership/matching_line_spec.rb +37 -0
  43. data/spec/unit/def_mastership/modifier_factory_spec.rb +37 -0
  44. data/spec/unit/def_mastership/modifier_spec.rb +83 -0
  45. data/spec/unit/{defmastership → def_mastership}/parsing_state_spec.rb +16 -16
  46. data/spec/unit/{defmastership/rename_included_files_line_modifier_spec.rb → def_mastership/rename_included_files_modifier_spec.rb} +72 -36
  47. data/spec/unit/{defmastership/comment_filter_spec.rb → def_mastership/string_spec.rb} +1 -1
  48. data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +107 -0
  49. data/spec/unit/def_mastership/update_def_modifier_spec.rb +119 -0
  50. data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +159 -0
  51. data/spec/unit/{defmastership_spec.rb → def_mastership_spec.rb} +1 -1
  52. data/tasks/console.rake +8 -0
  53. data/tasks/package.task +9 -0
  54. data/tasks/smelling_code.rake +38 -0
  55. data/tasks/test.rake +45 -0
  56. metadata +37 -145
  57. data/lib/defmastership/change_ref_line_modifier.rb +0 -82
  58. data/lib/defmastership/line_modifier_base.rb +0 -29
  59. data/lib/defmastership/modifier_base.rb +0 -29
  60. data/lib/defmastership/rename_included_files_line_modifier.rb +0 -126
  61. data/lib/defmastership/update_def_checksum_line_modifier.rb +0 -38
  62. data/lib/defmastership/update_def_version_line_modifier.rb +0 -58
  63. data/spec/unit/defmastership/change_ref_modifier_spec.rb +0 -76
  64. data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +0 -67
  65. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +0 -78
  66. data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +0 -75
  67. data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +0 -127
  68. data/spec/unit/defmastership/update_def_version_modifier_spec.rb +0 -80
@@ -1,76 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require('defmastership')
5
-
6
- RSpec.describe(DefMastership::ChangeRefModifier) 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::ChangeRefLineModifier, 'lineModifier') }
28
-
29
- before do
30
- allow(DefMastership::ChangeRefLineModifier).to(
31
- receive(:from_config).with('fake config').and_return(line_modifier)
32
- )
33
- allow(line_modifier).to(receive(:replace_refdef).with("file1 line1\n").and_return("new file1 line1\n"))
34
- allow(line_modifier).to(receive(:replace_refdef).with('file1 line2').and_return('new file1 line2'))
35
- allow(line_modifier).to(receive(:replace_refdef).with("file2 line1\n").and_return("new file2 line1\n"))
36
- allow(line_modifier).to(receive(:replace_refdef).with('file2 line2').and_return('new file2 line2'))
37
- allow(line_modifier).to(receive(:replace_irefs).with("new file1 line1\n").and_return("new2 file1 line1\n"))
38
- allow(line_modifier).to(receive(:replace_irefs).with('new file1 line2').and_return('new2 file1 line2'))
39
- allow(line_modifier).to(receive(:replace_irefs).with("new file2 line1\n").and_return("new2 file2 line1\n"))
40
- allow(line_modifier).to(receive(:replace_irefs).with('new file2 line2').and_return('new2 file2 line2'))
41
- allow(line_modifier).to(receive(:config).and_return('new fake config'))
42
- allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
43
- end
44
-
45
- context 'when detailed expectations' do
46
- before { modifier.do_modifications(adoc_texts) }
47
-
48
- it do
49
- expect(DefMastership::ChangeRefLineModifier).to(
50
- have_received(:from_config).with('fake config')
51
- )
52
- end
53
-
54
- it { expect(line_modifier).to(have_received(:replace_refdef).with("file1 line1\n")) }
55
- it { expect(line_modifier).to(have_received(:replace_refdef).with('file1 line2')) }
56
- it { expect(line_modifier).to(have_received(:replace_refdef).with("file2 line1\n")) }
57
- it { expect(line_modifier).to(have_received(:replace_refdef).with('file2 line2')) }
58
- it { expect(line_modifier).to(have_received(:replace_irefs).with("new file1 line1\n")) }
59
- it { expect(line_modifier).to(have_received(:replace_irefs).with('new file1 line2')) }
60
- it { expect(line_modifier).to(have_received(:replace_irefs).with("new file2 line1\n")) }
61
- it { expect(line_modifier).to(have_received(:replace_irefs).with('new file2 line2')) }
62
- it { expect(line_modifier).to(have_received(:config)) }
63
- it { expect(line_modifier).to(have_received(:changes)) }
64
- it { is_expected.to(have_attributes(config: 'new fake config')) }
65
- it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
66
- end
67
-
68
- it do
69
- expected_adoc = {
70
- 'file1.adoc' => "new2 file1 line1\nnew2 file1 line2",
71
- 'file2.adoc' => "new2 file2 line1\nnew2 file2 line2"
72
- }
73
- expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
74
- end
75
- end
76
- end
@@ -1,67 +0,0 @@
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
@@ -1,78 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require('defmastership')
5
-
6
- RSpec.describe(DefMastership::UpdateDefChecksumLineModifier) do
7
- subject(:linemodifier) { described_class.new }
8
-
9
- describe '.new' do
10
- it { is_expected.not_to(be(nil)) }
11
- it { is_expected.to(have_attributes(def_type: '')) }
12
- it { is_expected.to(have_attributes(changes: [])) }
13
- it { expect { linemodifier.user_defined_attribute }.to(raise_error(NoMethodError)) }
14
- end
15
-
16
- describe '.from_config' do
17
- subject(:linemodifier) do
18
- described_class.from_config(
19
- def_type: 'requirement'
20
- )
21
- end
22
-
23
- it { is_expected.not_to(be(nil)) }
24
- it { is_expected.to(have_attributes(def_type: 'requirement')) }
25
- it { is_expected.to(have_attributes(document: nil)) }
26
- end
27
-
28
- describe '#replace' do
29
- subject(:linemodifier) do
30
- described_class.from_config(
31
- def_type: 'requirement'
32
- )
33
- end
34
-
35
- let(:definition) { instance_double(DefMastership::Definition, 'definition') }
36
- let(:document) { instance_double(DefMastership::Document, 'document') }
37
- let(:definitions) { { 'REFERENCE' => definition } }
38
-
39
- before do
40
- linemodifier.document = document
41
- allow(File).to(receive(:rename))
42
- end
43
-
44
- context 'when definition has not the good type' do
45
- it do
46
- expect(linemodifier.replace('[define,req,REFERENCE]'))
47
- .to(eq('[define,req,REFERENCE]'))
48
- end
49
- end
50
-
51
- context 'when definition has the good type' do
52
- before do
53
- allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
54
- allow(definition).to(receive(:sha256).and_return('~abcd1234'))
55
- end
56
-
57
- it do
58
- expect(linemodifier.replace('[define,requirement,REFERENCE]'))
59
- .to(eq('[define,requirement,REFERENCE(~abcd1234)]'))
60
- end
61
-
62
- it do
63
- expect(linemodifier.replace('[define,requirement,REFERENCE(~bad)]'))
64
- .to(eq('[define,requirement,REFERENCE(~abcd1234)]'))
65
- end
66
-
67
- it do
68
- expect(linemodifier.replace('[define,requirement,REFERENCE(toto~bad)]'))
69
- .to(eq('[define,requirement,REFERENCE(toto~abcd1234)]'))
70
- end
71
-
72
- it do
73
- expect(linemodifier.replace('[define,requirement,REFERENCE(toto)]'))
74
- .to(eq('[define,requirement,REFERENCE(toto~abcd1234)]'))
75
- end
76
- end
77
- end
78
- end
@@ -1,75 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require('defmastership')
5
-
6
- RSpec.describe(DefMastership::UpdateDefChecksumModifier) 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::UpdateDefChecksumLineModifier, 'lineModifier') }
28
- let(:document) { instance_double(DefMastership::Document, 'document') }
29
-
30
- before do
31
- allow(DefMastership::UpdateDefChecksumLineModifier).to(
32
- receive(:from_config).with('fake config').and_return(line_modifier)
33
- )
34
- allow(DefMastership::Document).to(receive(:new).and_return(document))
35
- allow(document).to(receive(:parse_file_with_preprocessor))
36
- allow(line_modifier).to(receive(:'document=').with(document))
37
- allow(line_modifier).to(receive(:replace).with("file1 line1\n").and_return("new file1 line1\n"))
38
- allow(line_modifier).to(receive(:replace).with('file1 line2').and_return('new file1 line2'))
39
- allow(line_modifier).to(receive(:replace).with("file2 line1\n").and_return("new file2 line1\n"))
40
- allow(line_modifier).to(receive(:replace).with('file2 line2').and_return('new file2 line2'))
41
- allow(line_modifier).to(receive(:config).and_return('new fake config'))
42
- allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
43
- end
44
-
45
- context 'when detailed expectations' do
46
- before { modifier.do_modifications(adoc_texts) }
47
-
48
- it do
49
- expect(DefMastership::UpdateDefChecksumLineModifier).to(
50
- have_received(:from_config).with('fake config')
51
- )
52
- end
53
-
54
- it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file1.adoc')) }
55
- it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file2.adoc')) }
56
- it { expect(line_modifier).to(have_received(:'document=').with(document)) }
57
- it { expect(line_modifier).to(have_received(:replace).with("file1 line1\n")) }
58
- it { expect(line_modifier).to(have_received(:replace).with('file1 line2')) }
59
- it { expect(line_modifier).to(have_received(:replace).with("file2 line1\n")) }
60
- it { expect(line_modifier).to(have_received(:replace).with('file2 line2')) }
61
- it { expect(line_modifier).to(have_received(:config)) }
62
- it { expect(line_modifier).to(have_received(:changes)) }
63
- it { is_expected.to(have_attributes(config: 'new fake config')) }
64
- it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
65
- end
66
-
67
- it do
68
- expected_adoc = {
69
- 'file1.adoc' => "new file1 line1\nnew file1 line2",
70
- 'file2.adoc' => "new file2 line1\nnew file2 line2"
71
- }
72
- expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
73
- end
74
- end
75
- end
@@ -1,127 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require('defmastership')
5
-
6
- RSpec.describe(DefMastership::UpdateDefVersionLineModifier) do
7
- subject(:linemodifier) { described_class.new }
8
-
9
- describe '.new' do
10
- it { is_expected.not_to(be(nil)) }
11
- it { is_expected.to(have_attributes(def_type: '')) }
12
- it { is_expected.to(have_attributes(changes: [])) }
13
- it { expect { linemodifier.user_defined_attribute }.to(raise_error(NoMethodError)) }
14
- end
15
-
16
- describe '.from_config' do
17
- subject(:linemodifier) do
18
- described_class.from_config(
19
- def_type: 'requirement',
20
- first_version: 'a'
21
- )
22
- end
23
-
24
- it { is_expected.not_to(be(nil)) }
25
- it { is_expected.to(have_attributes(def_type: 'requirement')) }
26
- it { is_expected.to(have_attributes(first_version: 'a')) }
27
- it { is_expected.to(have_attributes(document: nil)) }
28
- it { is_expected.to(have_attributes(ref_document: nil)) }
29
- end
30
-
31
- describe '#replace' do
32
- subject(:linemodifier) do
33
- described_class.from_config(
34
- def_type: 'requirement',
35
- first_version: 'a'
36
- )
37
- end
38
-
39
- let(:document) { instance_double(DefMastership::Document, 'document') }
40
- let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
41
- let(:definition) { instance_double(DefMastership::Definition, 'definition') }
42
- let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
43
-
44
- before do
45
- linemodifier.document = document
46
- linemodifier.ref_document = ref_document
47
- allow(File).to(receive(:rename))
48
- end
49
-
50
- context 'when definition has not the good type' do
51
- it do
52
- expect(linemodifier.replace('[define,req,REFERENCE]'))
53
- .to(eq('[define,req,REFERENCE]'))
54
- end
55
- end
56
-
57
- context 'when definition has the good type' do
58
- before do
59
- allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
60
- allow(definition).to(receive(:sha256).and_return('~abcd1234'))
61
- end
62
-
63
- context 'when definition has NOT changed' do
64
- before do
65
- allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
66
- allow(ref_definition).to(receive(:sha256).and_return('~abcd1234'))
67
- end
68
-
69
- it do
70
- allow(ref_definition).to(receive(:explicit_version).and_return(nil))
71
- expect(linemodifier.replace('[define,requirement,REFERENCE]'))
72
- .to(eq('[define,requirement,REFERENCE]'))
73
- end
74
-
75
- it do
76
- allow(ref_definition).to(receive(:explicit_version).and_return('c'))
77
- expect(linemodifier.replace('[define,requirement,REFERENCE]'))
78
- .to(eq('[define,requirement,REFERENCE(c)]'))
79
- end
80
-
81
- it do
82
- allow(ref_definition).to(receive(:explicit_version).and_return('c'))
83
- expect(linemodifier.replace('[define,requirement,REFERENCE(tyty~1234)]'))
84
- .to(eq('[define,requirement,REFERENCE(c~1234)]'))
85
- end
86
- end
87
-
88
- context 'when definition has changed' do
89
- before do
90
- allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
91
- allow(ref_definition).to(receive(:sha256).and_return('~4321aaaa'))
92
- end
93
-
94
- [
95
- [nil, '', '(a)'],
96
- ['c', '', '(d)'],
97
- ['c', '(tyty~1234)', '(d~1234)'],
98
- ['2', '', '(3)'],
99
- ['1222', '', '(1223)'],
100
- ['abb', '', '(abc)']
101
- ].each do |ref, from, to|
102
- it do
103
- allow(ref_definition).to(receive(:explicit_version).and_return(ref))
104
- expect(linemodifier.replace("[define,requirement,REFERENCE#{from}]"))
105
- .to(eq("[define,requirement,REFERENCE#{to}]"))
106
- end
107
- end
108
- end
109
-
110
- context 'when definition is new' do
111
- before do
112
- allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(nil))
113
- end
114
-
115
- it do
116
- expect(linemodifier.replace('[define,requirement,REFERENCE(whatever)]'))
117
- .to(eq('[define,requirement,REFERENCE]'))
118
- end
119
-
120
- it do
121
- expect(linemodifier.replace('[define,requirement,REFERENCE(~1234)]'))
122
- .to(eq('[define,requirement,REFERENCE(~1234)]'))
123
- end
124
- end
125
- end
126
- end
127
- end
@@ -1,80 +0,0 @@
1
- # Copyright (c) 2020 Jerome Arbez-Gindre
2
- # frozen_string_literal: true
3
-
4
- require('defmastership')
5
-
6
- RSpec.describe(DefMastership::UpdateDefVersionModifier) do
7
- subject(:modifier) do
8
- described_class.new(
9
- ref_document: 'ref.adoc'
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: { ref_document: 'ref.adoc' })) }
23
- it { is_expected.to(have_attributes(changes: [])) }
24
- end
25
-
26
- describe '#do_modifications' do
27
- let(:line_modifier) { instance_double(DefMastership::UpdateDefVersionLineModifier, 'lineModifier') }
28
- let(:document) { instance_double(DefMastership::Document, 'document') }
29
- let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
30
-
31
- before do
32
- allow(DefMastership::UpdateDefVersionLineModifier).to(
33
- receive(:from_config).with(ref_document: 'ref.adoc').and_return(line_modifier)
34
- )
35
- allow(DefMastership::Document).to(receive(:new).and_return(document, ref_document))
36
- allow(document).to(receive(:parse_file_with_preprocessor))
37
- allow(ref_document).to(receive(:parse_file_with_preprocessor))
38
- allow(line_modifier).to(receive(:'document=').with(document))
39
- allow(line_modifier).to(receive(:'ref_document=').with(ref_document))
40
- allow(line_modifier).to(receive(:replace).with("file1 line1\n").and_return("new file1 line1\n"))
41
- allow(line_modifier).to(receive(:replace).with('file1 line2').and_return('new file1 line2'))
42
- allow(line_modifier).to(receive(:replace).with("file2 line1\n").and_return("new file2 line1\n"))
43
- allow(line_modifier).to(receive(:replace).with('file2 line2').and_return('new file2 line2'))
44
- allow(line_modifier).to(receive(:config).and_return(ref_document: 'ref.adoc'))
45
- allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
46
- end
47
-
48
- context 'when detailed expectations' do
49
- before { modifier.do_modifications(adoc_texts) }
50
-
51
- it do
52
- expect(DefMastership::UpdateDefVersionLineModifier).to(
53
- have_received(:from_config).with(ref_document: 'ref.adoc')
54
- )
55
- end
56
-
57
- it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file1.adoc')) }
58
- it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file2.adoc')) }
59
- it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('ref.adoc')) }
60
- it { expect(line_modifier).to(have_received(:'document=').with(document)) }
61
- it { expect(line_modifier).to(have_received(:'ref_document=').with(ref_document)) }
62
- it { expect(line_modifier).to(have_received(:replace).with("file1 line1\n")) }
63
- it { expect(line_modifier).to(have_received(:replace).with('file1 line2')) }
64
- it { expect(line_modifier).to(have_received(:replace).with("file2 line1\n")) }
65
- it { expect(line_modifier).to(have_received(:replace).with('file2 line2')) }
66
- it { expect(line_modifier).to(have_received(:config)) }
67
- it { expect(line_modifier).to(have_received(:changes)) }
68
- it { is_expected.to(have_attributes(config: { ref_document: 'ref.adoc' })) }
69
- it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
70
- end
71
-
72
- it do
73
- expected_adoc = {
74
- 'file1.adoc' => "new file1 line1\nnew file1 line2",
75
- 'file2.adoc' => "new file2 line1\nnew file2 line2"
76
- }
77
- expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
78
- end
79
- end
80
- end