defmastership 1.3.2 → 1.3.3
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.
- checksums.yaml +4 -4
- data/Guardfile +2 -5
- data/config/mutant.yml +2 -1
- data/config/rubocop.yml +20 -8
- data/defmastership.gemspec +4 -14
- data/features/changeref.feature +78 -0
- data/features/definition_checksum.feature +118 -0
- data/features/definition_version.feature +168 -0
- data/features/export.feature +67 -22
- data/features/external_ref_checksum.feature +169 -0
- data/features/external_ref_version.feature +173 -0
- data/features/internal_ref_checksum.feature +77 -0
- data/features/internal_ref_version.feature +81 -0
- data/features/rename_included_files.feature +28 -0
- data/lib/defmastership/app.rb +5 -6
- data/lib/defmastership/comment_filter.rb +2 -0
- data/lib/defmastership/def_type_list.rb +25 -0
- data/lib/defmastership/definition_parser.rb +2 -6
- data/lib/defmastership/document.rb +6 -9
- data/lib/defmastership/modifier/change_ref.rb +11 -34
- data/lib/defmastership/modifier/factory.rb +5 -1
- data/lib/defmastership/modifier/rename_included_files.rb +9 -0
- data/lib/defmastership/modifier/replacement_formatter.rb +37 -0
- data/lib/defmastership/modifier/update_def.rb +5 -1
- data/lib/defmastership/modifier/update_eref_checksum.rb +46 -0
- data/lib/defmastership/modifier/update_eref_common.rb +77 -0
- data/lib/defmastership/modifier/update_eref_version.rb +46 -0
- data/lib/defmastership/modifier/update_iref_checksum.rb +51 -0
- data/lib/defmastership/modifier/update_iref_common.rb +45 -0
- data/lib/defmastership/modifier/update_iref_version.rb +58 -0
- data/lib/defmastership/version.rb +1 -1
- data/spec/spec_helper.rb +11 -10
- data/spec/unit/defmastership/app_spec.rb +32 -19
- data/spec/unit/defmastership/batch_modifier_spec.rb +9 -7
- data/spec/unit/defmastership/def_type_list_spec.rb +22 -0
- data/spec/unit/defmastership/definition_spec.rb +8 -51
- data/spec/unit/defmastership/document_spec.rb +12 -36
- data/spec/unit/defmastership/export/body_formatter_spec.rb +5 -18
- data/spec/unit/defmastership/export/csv/formatter_spec.rb +1 -0
- data/spec/unit/defmastership/export/header_formatter_spec.rb +2 -6
- data/spec/unit/defmastership/hash_spec.rb +2 -0
- data/spec/unit/defmastership/modifier/change_ref_spec.rb +33 -70
- data/spec/unit/defmastership/modifier/factory_spec.rb +40 -17
- data/spec/unit/defmastership/modifier/modifier_common_spec.rb +2 -0
- data/spec/unit/defmastership/modifier/rename_included_files_spec.rb +62 -46
- data/spec/unit/defmastership/modifier/update_def_checksum_spec.rb +2 -9
- data/spec/unit/defmastership/modifier/update_def_spec.rb +76 -21
- data/spec/unit/defmastership/modifier/update_def_version_spec.rb +6 -32
- data/spec/unit/defmastership/modifier/update_eref_checksum_spec.rb +200 -0
- data/spec/unit/defmastership/modifier/update_eref_version_spec.rb +215 -0
- data/spec/unit/defmastership/modifier/update_iref_checksum_spec.rb +133 -0
- data/spec/unit/defmastership/modifier/update_iref_version_spec.rb +162 -0
- data/tasks/code_quality.rake +1 -8
- data/tasks/test.rake +15 -0
- metadata +34 -3
@@ -0,0 +1,45 @@
|
|
1
|
+
# Copyright (c) 2025 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/core/constants')
|
5
|
+
require('defmastership/document')
|
6
|
+
require('defmastership/modifier/modifier_common')
|
7
|
+
|
8
|
+
module Defmastership
|
9
|
+
module Modifier
|
10
|
+
# Update internal refs checksum
|
11
|
+
class UpdateIref
|
12
|
+
include ModifierCommon
|
13
|
+
|
14
|
+
# @return [Hash{Symbol => Object}] the default configuration
|
15
|
+
def self.default_config
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param config [YAML] the modifier's provided configurations
|
20
|
+
def initialize(config)
|
21
|
+
@document = Document.new
|
22
|
+
|
23
|
+
setup_modifier_module(config)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Apply the modifier on all provided asciidoc sources based on modifier's
|
27
|
+
# +self.replacement_methods+ list
|
28
|
+
#
|
29
|
+
# @param adoc_sources [Hash{String => String}] asciidoc sources
|
30
|
+
# * :key filename
|
31
|
+
# * :value file content
|
32
|
+
def do_modifications(adoc_sources)
|
33
|
+
adoc_sources.each_key do |adoc_file|
|
34
|
+
document.parse_file_with_preprocessor(adoc_file)
|
35
|
+
end
|
36
|
+
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
attr_reader :document
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright (c) 2025 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/core/constants')
|
5
|
+
require('defmastership/modifier/replacement_formatter')
|
6
|
+
require('defmastership/modifier/update_iref_common')
|
7
|
+
|
8
|
+
module Defmastership
|
9
|
+
module Modifier
|
10
|
+
# Update internal refs checksum
|
11
|
+
class UpdateIrefVersion < UpdateIref
|
12
|
+
include ModifierCommon
|
13
|
+
|
14
|
+
# Methods's symbols will be called in sequence to perform the document modifications
|
15
|
+
#
|
16
|
+
# @return [Array<Symbol>] the two symbols of replacement methods
|
17
|
+
def self.replacement_methods
|
18
|
+
%i[replace_irefs]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Replace the definition's internal ref in the line if relevant
|
22
|
+
#
|
23
|
+
# @param line [String] the current line
|
24
|
+
# @return [String] the modified line
|
25
|
+
def replace_irefs(line)
|
26
|
+
line.gsub(Core::DMRegexp::IREF_DEF) do
|
27
|
+
Helper::IrefReplacementFormatterVersion.new(Regexp.last_match, document).to_s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Helper functions/classes
|
32
|
+
module Helper
|
33
|
+
# A small, single-purpose class to format the iref replacement string.
|
34
|
+
class IrefReplacementFormatterVersion < ReplacementFormatter
|
35
|
+
# @param match_data [MatchData] of the ref statement
|
36
|
+
# @param document [Document] the overall parsed document
|
37
|
+
def initialize(match_data, document)
|
38
|
+
super(match_data, document, :intref)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [String] the formatted string or the original match if no definition is found.
|
42
|
+
def to_s
|
43
|
+
return match_data unless definition
|
44
|
+
|
45
|
+
explicit_version = definition.explicit_version
|
46
|
+
explicit_checksum = match_data[:explicit_checksum]
|
47
|
+
|
48
|
+
if explicit_version || explicit_checksum
|
49
|
+
"defs:iref[#{reference_string}(#{explicit_version}#{explicit_checksum})]"
|
50
|
+
else
|
51
|
+
"defs:iref[#{reference_string}]"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,19 +6,20 @@ require('aasm/rspec')
|
|
6
6
|
# formatter = [SimpleCov::Formatter::HTMLFormatter]
|
7
7
|
# SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(formatter)
|
8
8
|
|
9
|
-
|
9
|
+
unless ENV['CODE_COVERAGE_IN_RSPEC'] && ENV['DISABLE_CODE_COVERAGE_IN_RSPEC'] != 'disabled'
|
10
|
+
require 'simplecov'
|
11
|
+
SimpleCov.start do
|
12
|
+
command_name 'spec:unit'
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
add_group 'Libraries', 'lib'
|
15
|
+
add_group 'Unit test', 'spec/unit'
|
13
16
|
|
14
|
-
|
15
|
-
|
17
|
+
add_filter 'config'
|
18
|
+
add_filter 'vendor'
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
enable_coverage :branch
|
21
|
-
minimum_coverage line: 100, branch: 100
|
20
|
+
enable_coverage :branch
|
21
|
+
minimum_coverage line: 100, branch: 100
|
22
|
+
end
|
22
23
|
end
|
23
24
|
|
24
25
|
RSpec::Matchers.define(:matchdata_including) do |h|
|
@@ -19,7 +19,7 @@ RSpec.describe(Defmastership::App) do
|
|
19
19
|
context('when "--version" option') do
|
20
20
|
it {
|
21
21
|
expect { described_class.run(['--version']) }
|
22
|
-
.to(output(/version/).
|
22
|
+
.to(output(/version/).to_stdout_from_any_process)
|
23
23
|
}
|
24
24
|
end
|
25
25
|
|
@@ -28,10 +28,11 @@ RSpec.describe(Defmastership::App) do
|
|
28
28
|
|
29
29
|
[
|
30
30
|
/Export\s+the\s+definition\s+database\s+in\s+CSV$/,
|
31
|
-
/\bexport\b.*\basciidoctor_file\b
|
31
|
+
/\bexport\b.*\basciidoctor_file\b\s+\[asciidoctor_file\]\.\.\.$/,
|
32
32
|
/--separator, --sep, -s arg.*CSV\s+separator\s+\(default: ,\)$/,
|
33
33
|
/--\[no-\]no-fail.*Exit\s+success\s+even\s+in\s+
|
34
|
-
case\s+of\s+wrong\s+explicit\s+checksum$/mx
|
34
|
+
case\s+of\s+wrong\s+explicit\s+checksum$/mx,
|
35
|
+
/--output-file, -o arg.*CSV\s+output\s+filename\s+\(default:\s+none\)$/
|
35
36
|
].each do |content|
|
36
37
|
it do
|
37
38
|
expect { described_class.run(['export', '--help']) }
|
@@ -40,22 +41,6 @@ RSpec.describe(Defmastership::App) do
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
|
-
context('when "export" with more than one argument') do
|
44
|
-
it { expect(described_class.run(%w[export arg1 arg2])).to(be(64)) }
|
45
|
-
|
46
|
-
it do
|
47
|
-
expect { described_class.run(%w[export arg1 arg2]) }
|
48
|
-
.to(output(/error: export expected only 1 arguments, but received 2/).to_stderr_from_any_process)
|
49
|
-
end
|
50
|
-
|
51
|
-
it { expect(described_class.run(['export'])).to(be(64)) }
|
52
|
-
|
53
|
-
it do
|
54
|
-
expect { described_class.run(['export']) }
|
55
|
-
.to(output(/error: export expected at least 1 arguments, but was given only 0/).to_stderr_from_any_process)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
44
|
context('when "export toto.adoc" subcommand') do
|
60
45
|
let(:document) { instance_double(Defmastership::Document, 'document') }
|
61
46
|
let(:formatter) { instance_double(Defmastership::Export::CSV::Formatter, 'formatter') }
|
@@ -115,6 +100,34 @@ RSpec.describe(Defmastership::App) do
|
|
115
100
|
end
|
116
101
|
end
|
117
102
|
|
103
|
+
context('when "export" with more than one argument') do
|
104
|
+
let(:document) { instance_double(Defmastership::Document, 'document') }
|
105
|
+
let(:formatter) { instance_double(Defmastership::Export::CSV::Formatter, 'formatter') }
|
106
|
+
let(:defs) do
|
107
|
+
[
|
108
|
+
instance_double(Defmastership::Definition, 'def1'),
|
109
|
+
instance_double(Defmastership::Definition, 'def2')
|
110
|
+
]
|
111
|
+
end
|
112
|
+
|
113
|
+
before do
|
114
|
+
allow(Defmastership::Document).to(receive(:new).and_return(document))
|
115
|
+
allow(Defmastership::Export::CSV::Formatter).to(receive(:new).and_return(formatter))
|
116
|
+
allow(formatter).to(receive(:export_to).with(an_instance_of(String)))
|
117
|
+
allow(document).to(receive(:parse_file_with_preprocessor).with(an_instance_of(String)))
|
118
|
+
allow(document).to(receive_messages(definitions: defs, wrong_explicit_checksum?: nil))
|
119
|
+
|
120
|
+
described_class.run(['export', '--output-file=pouet.csv', 'toto.adoc', 'tutu.adoc'])
|
121
|
+
end
|
122
|
+
|
123
|
+
it { expect(Defmastership::Document).to(have_received(:new).with(no_args)) }
|
124
|
+
it { expect(document).to(have_received(:parse_file_with_preprocessor).once.with('toto.adoc')) }
|
125
|
+
it { expect(document).to(have_received(:parse_file_with_preprocessor).once.with('tutu.adoc')) }
|
126
|
+
it { expect(Defmastership::Export::CSV::Formatter).to(have_received(:new).with(document, ',')) }
|
127
|
+
it { expect(formatter).to(have_received(:export_to).once.with('pouet.csv')) }
|
128
|
+
it { expect(described_class.run(['export', '--output-file=pouet.csv', 'toto.adoc', 'tutu.adoc'])).to(be(0)) }
|
129
|
+
end
|
130
|
+
|
118
131
|
context('when "modify --help" subcommand') do
|
119
132
|
it { expect(described_class.run(['modify', '--help'])).to(be(0)) }
|
120
133
|
|
@@ -4,14 +4,16 @@
|
|
4
4
|
require('defmastership/batch_modifier')
|
5
5
|
|
6
6
|
module Defmastership
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
module Modifier
|
8
|
+
# Modifier example
|
9
|
+
class Toto
|
10
|
+
include ModifierCommon
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
# Modifier example
|
14
|
+
class TuTu
|
15
|
+
include ModifierCommon
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Copyright (c) 2025 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/def_type_list')
|
5
|
+
|
6
|
+
RSpec.describe(Defmastership::DefTypeList) do
|
7
|
+
subject(:def_type_list) { described_class.new('') }
|
8
|
+
|
9
|
+
describe '.new' do
|
10
|
+
it { is_expected.not_to(be_nil) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#include?' do
|
14
|
+
it { expect(described_class.new('').include?('whatever')).to(be(true)) }
|
15
|
+
it { expect(described_class.new('all').include?('whatever')).to(be(true)) }
|
16
|
+
it { expect(described_class.new('one_type').include?('whatever')).to(be(false)) }
|
17
|
+
it { expect(described_class.new('one_type').include?('one_type')).to(be(true)) }
|
18
|
+
it { expect(described_class.new('one_type_more').include?('one_type')).to(be(false)) }
|
19
|
+
it { expect(described_class.new(%w[one_type another_type]).include?('one_type')).to(be(true)) }
|
20
|
+
it { expect(described_class.new(%w[one_type another_type]).include?('whatever')).to(be(false)) }
|
21
|
+
end
|
22
|
+
end
|
@@ -6,12 +6,7 @@ require('defmastership/definition')
|
|
6
6
|
RSpec.describe(Defmastership::Definition) do
|
7
7
|
describe '.new' do
|
8
8
|
context 'when minimal' do
|
9
|
-
subject
|
10
|
-
described_class.new(
|
11
|
-
type: 'req',
|
12
|
-
reference: 'TUTU-001'
|
13
|
-
)
|
14
|
-
end
|
9
|
+
subject { described_class.new(type: 'req', reference: 'TUTU-001') }
|
15
10
|
|
16
11
|
it { is_expected.not_to(be_nil) }
|
17
12
|
it { is_expected.to(have_attributes(type: 'req')) }
|
@@ -27,25 +22,13 @@ RSpec.describe(Defmastership::Definition) do
|
|
27
22
|
end
|
28
23
|
|
29
24
|
context 'with labels' do
|
30
|
-
subject
|
31
|
-
described_class.new(
|
32
|
-
type: 'req',
|
33
|
-
reference: 'TUTU-001',
|
34
|
-
labels: 'something'
|
35
|
-
)
|
36
|
-
end
|
25
|
+
subject { described_class.new(type: 'req', reference: 'TUTU-001', labels: 'something') }
|
37
26
|
|
38
27
|
it { is_expected.to(have_attributes(labels: Set['something'])) }
|
39
28
|
end
|
40
29
|
|
41
30
|
context 'with explicit_checksum' do
|
42
|
-
subject(:definition)
|
43
|
-
described_class.new(
|
44
|
-
type: 'req',
|
45
|
-
reference: 'TUTU-001',
|
46
|
-
explicit_checksum: '~8cc259e6'
|
47
|
-
)
|
48
|
-
end
|
31
|
+
subject(:definition) { described_class.new(type: 'req', reference: 'TUTU-001', explicit_checksum: '~8cc259e6') }
|
49
32
|
|
50
33
|
it do
|
51
34
|
definition << 'def value with a checksum != ~8cc259e6'
|
@@ -59,13 +42,7 @@ RSpec.describe(Defmastership::Definition) do
|
|
59
42
|
end
|
60
43
|
|
61
44
|
context 'with explicit_version' do
|
62
|
-
subject(:definition)
|
63
|
-
described_class.new(
|
64
|
-
type: 'req',
|
65
|
-
reference: 'TUTU-001',
|
66
|
-
explicit_version: 'pouet'
|
67
|
-
)
|
68
|
-
end
|
45
|
+
subject(:definition) { described_class.new(type: 'req', reference: 'TUTU-001', explicit_version: 'pouet') }
|
69
46
|
|
70
47
|
it do
|
71
48
|
expect(definition).to(have_attributes(explicit_version: 'pouet'))
|
@@ -74,12 +51,7 @@ RSpec.describe(Defmastership::Definition) do
|
|
74
51
|
end
|
75
52
|
|
76
53
|
describe '#<<' do
|
77
|
-
subject(:definition)
|
78
|
-
described_class.new(
|
79
|
-
type: 'req',
|
80
|
-
reference: 'TUTU-001'
|
81
|
-
)
|
82
|
-
end
|
54
|
+
subject(:definition) { described_class.new(type: 'req', reference: 'TUTU-001') }
|
83
55
|
|
84
56
|
it 'has value when one line is added' do
|
85
57
|
definition << 'first line'
|
@@ -133,12 +105,7 @@ RSpec.describe(Defmastership::Definition) do
|
|
133
105
|
end
|
134
106
|
|
135
107
|
describe '#add_eref' do
|
136
|
-
subject(:definition)
|
137
|
-
described_class.new(
|
138
|
-
type: 'req',
|
139
|
-
reference: 'TUTU-001'
|
140
|
-
)
|
141
|
-
end
|
108
|
+
subject(:definition) { described_class.new(type: 'req', reference: 'TUTU-001') }
|
142
109
|
|
143
110
|
[
|
144
111
|
'tutu,titi,pouet',
|
@@ -152,12 +119,7 @@ RSpec.describe(Defmastership::Definition) do
|
|
152
119
|
end
|
153
120
|
|
154
121
|
describe '#add_iref' do
|
155
|
-
subject(:definition)
|
156
|
-
described_class.new(
|
157
|
-
type: 'req',
|
158
|
-
reference: 'TUTU-001'
|
159
|
-
)
|
160
|
-
end
|
122
|
+
subject(:definition) { described_class.new(type: 'req', reference: 'TUTU-001') }
|
161
123
|
|
162
124
|
it 'shall accept to add multiple iref' do
|
163
125
|
definition.add_iref('toto')
|
@@ -167,12 +129,7 @@ RSpec.describe(Defmastership::Definition) do
|
|
167
129
|
end
|
168
130
|
|
169
131
|
describe '#set_attribute' do
|
170
|
-
subject(:definition)
|
171
|
-
described_class.new(
|
172
|
-
type: 'req',
|
173
|
-
reference: 'TUTU-001'
|
174
|
-
)
|
175
|
-
end
|
132
|
+
subject(:definition) { described_class.new(type: 'req', reference: 'TUTU-001') }
|
176
133
|
|
177
134
|
it 'shall accept to set attribute' do
|
178
135
|
definition.set_attribute(:whatever, 'value')
|
@@ -297,8 +297,7 @@ RSpec.describe(Defmastership::Document) do
|
|
297
297
|
|
298
298
|
it do
|
299
299
|
document.__send__(:do_parse, input_lines)
|
300
|
-
expect(document.eref[:implements])
|
301
|
-
.to(eq(prefix: 'Participate to:'))
|
300
|
+
expect(document.eref[:implements]).to(eq(prefix: 'Participate to:'))
|
302
301
|
end
|
303
302
|
end
|
304
303
|
|
@@ -326,7 +325,8 @@ RSpec.describe(Defmastership::Document) do
|
|
326
325
|
let(:input_lines) do
|
327
326
|
[
|
328
327
|
'[define, requirement, TOTO-0001]',
|
329
|
-
'defs:iref[toto] defs:iref[tutu]',
|
328
|
+
'defs:iref[toto] defs:iref[tutu(a)]',
|
329
|
+
'defs:iref[titi(a)], defs:iref[tata(a~12345678)]',
|
330
330
|
'defs:iref[pouet]'
|
331
331
|
]
|
332
332
|
end
|
@@ -337,7 +337,9 @@ RSpec.describe(Defmastership::Document) do
|
|
337
337
|
end
|
338
338
|
|
339
339
|
it { expect(definition).to(have_received(:add_iref).with('toto')) }
|
340
|
-
it { expect(definition).to(have_received(:add_iref).with('tutu')) }
|
340
|
+
it { expect(definition).to(have_received(:add_iref).with('tutu(a)')) }
|
341
|
+
it { expect(definition).to(have_received(:add_iref).with('titi(a)')) }
|
342
|
+
it { expect(definition).to(have_received(:add_iref).with('tata(a~12345678)')) }
|
341
343
|
it { expect(definition).to(have_received(:add_iref).with('pouet')) }
|
342
344
|
it { expect(document.iref).to(be(true)) }
|
343
345
|
end
|
@@ -417,12 +419,7 @@ RSpec.describe(Defmastership::Document) do
|
|
417
419
|
|
418
420
|
before do
|
419
421
|
allow(Defmastership::Definition).to(receive(:new).and_return(definition))
|
420
|
-
allow(definition).to(
|
421
|
-
receive_messages(
|
422
|
-
labels: Set.new,
|
423
|
-
'<<': definition
|
424
|
-
)
|
425
|
-
)
|
422
|
+
allow(definition).to(receive_messages(labels: Set.new, '<<': definition))
|
426
423
|
document.__send__(:do_parse, input_lines)
|
427
424
|
end
|
428
425
|
|
@@ -522,9 +519,7 @@ RSpec.describe(Defmastership::Document) do
|
|
522
519
|
end
|
523
520
|
|
524
521
|
before do
|
525
|
-
allow(Defmastership::Definition).to(
|
526
|
-
receive(:new).and_raise('not a valide definition')
|
527
|
-
)
|
522
|
+
allow(Defmastership::Definition).to(receive(:new).and_raise('not a valide definition'))
|
528
523
|
end
|
529
524
|
|
530
525
|
it do
|
@@ -543,9 +538,7 @@ RSpec.describe(Defmastership::Document) do
|
|
543
538
|
end
|
544
539
|
|
545
540
|
before do
|
546
|
-
allow(Defmastership::Definition).to(
|
547
|
-
receive(:new).and_raise('not a valide definition')
|
548
|
-
)
|
541
|
+
allow(Defmastership::Definition).to(receive(:new).and_raise('not a valide definition'))
|
549
542
|
end
|
550
543
|
|
551
544
|
it do
|
@@ -569,12 +562,7 @@ RSpec.describe(Defmastership::Document) do
|
|
569
562
|
allow(adoc_doc).to(receive(:reader).and_return(adoc_reader))
|
570
563
|
allow(adoc_reader).to(receive(:read_lines).and_return(input_lines))
|
571
564
|
allow(Defmastership::Definition).to(receive(:new).and_return(definition))
|
572
|
-
allow(definition).to(
|
573
|
-
receive_messages(
|
574
|
-
'<<': definition,
|
575
|
-
labels: Set.new
|
576
|
-
)
|
577
|
-
)
|
565
|
+
allow(definition).to(receive_messages('<<': definition, labels: Set.new))
|
578
566
|
document.parse_file_with_preprocessor('the_file.adoc')
|
579
567
|
end
|
580
568
|
|
@@ -758,20 +746,8 @@ RSpec.describe(Defmastership::Document) do
|
|
758
746
|
|
759
747
|
before do
|
760
748
|
allow(Defmastership::Definition).to(receive(:new).twice.and_return(definitions.first, definitions[1]))
|
761
|
-
allow(definitions.first).to(
|
762
|
-
|
763
|
-
labels: [],
|
764
|
-
'<<': definitions.first,
|
765
|
-
reference: 'TOTO-0001'
|
766
|
-
)
|
767
|
-
)
|
768
|
-
allow(definitions[1]).to(
|
769
|
-
receive_messages(
|
770
|
-
labels: [],
|
771
|
-
'<<': definitions[1],
|
772
|
-
reference: 'TOTO-0002'
|
773
|
-
)
|
774
|
-
)
|
749
|
+
allow(definitions.first).to(receive_messages(labels: [], '<<': definitions.first, reference: 'TOTO-0001'))
|
750
|
+
allow(definitions[1]).to(receive_messages(labels: [], '<<': definitions[1], reference: 'TOTO-0002'))
|
775
751
|
document.__send__(:do_parse, input_lines)
|
776
752
|
end
|
777
753
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require('defmastership/document')
|
4
5
|
require('defmastership/export/body_formatter')
|
5
6
|
|
6
7
|
RSpec.describe(Defmastership::Export::BodyFormatter) do
|
@@ -142,11 +143,7 @@ RSpec.describe(Defmastership::Export::BodyFormatter) do
|
|
142
143
|
|
143
144
|
context 'when eref on the document' do
|
144
145
|
before do
|
145
|
-
allow(document).to(
|
146
|
-
receive(:eref).with(no_args).and_return(
|
147
|
-
a: 'whatever', b: 'whatever', c: 'whatever'
|
148
|
-
)
|
149
|
-
)
|
146
|
+
allow(document).to(receive(:eref).with(no_args).and_return(a: 'whatever', b: 'whatever', c: 'whatever'))
|
150
147
|
allow(definition).to(receive(:eref).with(no_args).and_return(a: %w[A B], b: [], c: ['C']))
|
151
148
|
formatter.eref
|
152
149
|
end
|
@@ -157,11 +154,7 @@ RSpec.describe(Defmastership::Export::BodyFormatter) do
|
|
157
154
|
|
158
155
|
context 'when missing eref on the definition' do
|
159
156
|
before do
|
160
|
-
allow(document).to(
|
161
|
-
receive(:eref).with(no_args).and_return(
|
162
|
-
a: 'whatever', b: 'whatever'
|
163
|
-
)
|
164
|
-
)
|
157
|
+
allow(document).to(receive(:eref).with(no_args).and_return(a: 'whatever', b: 'whatever'))
|
165
158
|
allow(definition).to(receive(:eref).with(no_args).and_return(b: ['B']))
|
166
159
|
formatter.eref
|
167
160
|
end
|
@@ -208,10 +201,7 @@ RSpec.describe(Defmastership::Export::BodyFormatter) do
|
|
208
201
|
|
209
202
|
context 'when attributes on the document' do
|
210
203
|
before do
|
211
|
-
allow(document).to(
|
212
|
-
receive(:attributes).with(no_args)
|
213
|
-
.and_return(a: 'whatever', b: 'whatever', c: 'whatever')
|
214
|
-
)
|
204
|
+
allow(document).to(receive(:attributes).with(no_args).and_return(a: 'whatever', b: 'whatever', c: 'whatever'))
|
215
205
|
allow(definition).to(receive(:attributes).and_return(a: 'X', b: '', c: 'Y'))
|
216
206
|
formatter.attributes
|
217
207
|
end
|
@@ -222,10 +212,7 @@ RSpec.describe(Defmastership::Export::BodyFormatter) do
|
|
222
212
|
|
223
213
|
context 'when miing attribute on the definition' do
|
224
214
|
before do
|
225
|
-
allow(document).to(
|
226
|
-
receive(:attributes).with(no_args)
|
227
|
-
.and_return(a: 'whatever', b: 'whatever', c: 'whatever')
|
228
|
-
)
|
215
|
+
allow(document).to(receive(:attributes).with(no_args).and_return(a: 'whatever', b: 'whatever', c: 'whatever'))
|
229
216
|
allow(definition).to(receive(:attributes).and_return(a: 'X', b: ''))
|
230
217
|
formatter.attributes
|
231
218
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require('defmastership/document')
|
4
5
|
require('defmastership/export/header_formatter')
|
5
6
|
|
6
7
|
RSpec.describe(Defmastership::Export::HeaderFormatter) do
|
@@ -110,12 +111,7 @@ RSpec.describe(Defmastership::Export::HeaderFormatter) do
|
|
110
111
|
|
111
112
|
context 'when eref' do
|
112
113
|
before do
|
113
|
-
allow(document).to(
|
114
|
-
receive(:eref).and_return(
|
115
|
-
whatever: { prefix: 'A' },
|
116
|
-
other: { prefix: 'C', url: 'D' }
|
117
|
-
)
|
118
|
-
)
|
114
|
+
allow(document).to(receive(:eref).and_return(whatever: { prefix: 'A' }, other: { prefix: 'C', url: 'D' }))
|
119
115
|
end
|
120
116
|
|
121
117
|
it { expect(formatter.eref).to(eq(%w[A C])) }
|