defmastership 1.0.17 → 1.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +37 -11
- data/Gemfile +71 -1
- data/Guardfile +44 -0
- data/Rakefile +16 -61
- data/bin/defmastership +9 -6
- data/config/cucumber.yml +3 -0
- data/config/mutant.yml +27 -3
- data/config/reek.yml +129 -105
- data/config/rubocop.yml +72 -28
- data/defmastership.gemspec +5 -13
- data/features/changeref.feature +0 -8
- data/features/definition_checksum.feature +30 -10
- data/features/definition_version.feature +168 -10
- data/features/export.feature +64 -17
- data/features/modify.feature +1 -5
- data/features/rename_included_files.feature +27 -4
- data/features/step_definitions/git_steps.rb +19 -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 +10 -7
- 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 +59 -20
- data/lib/defmastership/document.rb +101 -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 +81 -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 +40 -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 +38 -0
- data/spec/unit/def_mastership/modifier_spec.rb +85 -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 +121 -0
- data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +327 -56
- data/tasks/code_quality.rake +74 -0
- data/tasks/console.rake +8 -0
- data/tasks/package.task +9 -0
- data/tasks/test.rake +30 -0
- metadata +33 -145
- data/.rubocop.yml +0 -76
- data/config/devtools.yml +0 -2
- data/config/flay.yml +0 -3
- data/config/flog.yml +0 -2
- data/config/yardstick.yml +0 -2
- data/cucumber.yml +0 -2
- 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
- /data/{.rspec → config/rspec} +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require('defmastership')
|
4
|
+
require('defmastership/document')
|
5
5
|
|
6
6
|
RSpec.describe(DefMastership::Document) do
|
7
7
|
subject(:document) { described_class.new }
|
@@ -15,16 +15,32 @@ RSpec.describe(DefMastership::Document) do
|
|
15
15
|
it { is_expected.to(have_attributes(variables: {})) }
|
16
16
|
end
|
17
17
|
|
18
|
+
describe '.method_missing' do
|
19
|
+
it do
|
20
|
+
expect { document.not_implemented_random_method }
|
21
|
+
.to(raise_error(NoMethodError))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.respond_to_missing?' do
|
26
|
+
it { expect(document.respond_to?(:add_new_definition)).to(be(true)) }
|
27
|
+
it { expect(document.respond_to?(:not_implemented_random_method)).to(be(false)) }
|
28
|
+
end
|
29
|
+
|
18
30
|
describe '#parse' do
|
19
31
|
context 'with valid definitions' do
|
20
32
|
let(:definition) { instance_double(DefMastership::Definition, 'definition') }
|
21
33
|
|
22
34
|
before do
|
23
35
|
allow(DefMastership::Definition).to(receive(:new).and_return(definition))
|
24
|
-
allow(definition).to(
|
25
|
-
|
26
|
-
|
27
|
-
|
36
|
+
allow(definition).to(
|
37
|
+
receive_messages(
|
38
|
+
labels: Set.new,
|
39
|
+
'<<': definition,
|
40
|
+
add_eref: definition,
|
41
|
+
add_iref: definition
|
42
|
+
)
|
43
|
+
)
|
28
44
|
end
|
29
45
|
|
30
46
|
context 'when simple definition line' do
|
@@ -401,8 +417,12 @@ RSpec.describe(DefMastership::Document) do
|
|
401
417
|
|
402
418
|
before do
|
403
419
|
allow(DefMastership::Definition).to(receive(:new).and_return(definition))
|
404
|
-
allow(definition).to(
|
405
|
-
|
420
|
+
allow(definition).to(
|
421
|
+
receive_messages(
|
422
|
+
labels: Set.new,
|
423
|
+
'<<': definition
|
424
|
+
)
|
425
|
+
)
|
406
426
|
document.parse(input_lines)
|
407
427
|
end
|
408
428
|
|
@@ -431,6 +451,18 @@ RSpec.describe(DefMastership::Document) do
|
|
431
451
|
it { expect(definition).to(have_received(:<<).with('bef {variable} aft')) }
|
432
452
|
end
|
433
453
|
|
454
|
+
context 'when badly defined variable' do
|
455
|
+
let(:input_lines) do
|
456
|
+
[
|
457
|
+
':variable:one value',
|
458
|
+
'[define, requirement, TOTO-0001]',
|
459
|
+
'bef {variable} aft'
|
460
|
+
]
|
461
|
+
end
|
462
|
+
|
463
|
+
it { expect(definition).to(have_received(:<<).with('bef {variable} aft')) }
|
464
|
+
end
|
465
|
+
|
434
466
|
context 'when multiple defined variables' do
|
435
467
|
let(:input_lines) do
|
436
468
|
[
|
@@ -503,8 +535,12 @@ RSpec.describe(DefMastership::Document) do
|
|
503
535
|
allow(adoc_doc).to(receive(:reader).and_return(adoc_reader))
|
504
536
|
allow(adoc_reader).to(receive(:read_lines).and_return(input_lines))
|
505
537
|
allow(DefMastership::Definition).to(receive(:new).and_return(definition))
|
506
|
-
allow(definition).to(
|
507
|
-
|
538
|
+
allow(definition).to(
|
539
|
+
receive_messages(
|
540
|
+
'<<': definition,
|
541
|
+
labels: Set.new
|
542
|
+
)
|
543
|
+
)
|
508
544
|
document.parse_file_with_preprocessor('the_file.adoc')
|
509
545
|
end
|
510
546
|
|
@@ -539,30 +575,29 @@ RSpec.describe(DefMastership::Document) do
|
|
539
575
|
end
|
540
576
|
|
541
577
|
before do
|
542
|
-
allow(DefMastership::Definition).to(receive(:new).twice.and_return(defs
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
578
|
+
allow(DefMastership::Definition).to(receive(:new).twice.and_return(defs.first, defs[1]))
|
579
|
+
defs.each do |definition|
|
580
|
+
allow(definition).to(receive(:labels)).and_return([])
|
581
|
+
allow(definition).to(receive(:<<)).and_return(definition)
|
582
|
+
end
|
547
583
|
end
|
548
584
|
|
549
585
|
context 'when no wrong explicit checksum' do
|
550
586
|
before do
|
551
|
-
allow(
|
552
|
-
allow(defs[1]).to(receive(:wrong_explicit_checksum)).and_return(nil)
|
587
|
+
defs.each { |definition| allow(definition).to(receive(:wrong_explicit_checksum)).and_return(nil) }
|
553
588
|
document.parse(input_lines)
|
554
589
|
document.wrong_explicit_checksum?
|
555
590
|
end
|
556
591
|
|
557
|
-
it { expect(defs
|
592
|
+
it { expect(defs.first).to(have_received(:wrong_explicit_checksum)) }
|
558
593
|
it { expect(defs[1]).to(have_received(:wrong_explicit_checksum)) }
|
559
594
|
it { expect(document.wrong_explicit_checksum?).to(be(false)) }
|
560
595
|
end
|
561
596
|
|
562
597
|
context 'when one req has wrong explicit checksum' do
|
563
598
|
before do
|
564
|
-
allow(defs
|
565
|
-
allow(defs[1]).to(receive(:wrong_explicit_checksum)).and_return(
|
599
|
+
allow(defs.first).to(receive(:wrong_explicit_checksum)).and_return('toto')
|
600
|
+
allow(defs[1]).to(receive(:wrong_explicit_checksum)).and_return(nil)
|
566
601
|
document.parse(input_lines)
|
567
602
|
document.wrong_explicit_checksum?
|
568
603
|
end
|
@@ -589,30 +624,30 @@ RSpec.describe(DefMastership::Document) do
|
|
589
624
|
end
|
590
625
|
|
591
626
|
before do
|
592
|
-
allow(DefMastership::Definition).to(receive(:new).twice.and_return(defs
|
593
|
-
allow(defs
|
627
|
+
allow(DefMastership::Definition).to(receive(:new).twice.and_return(defs.first, defs[1]))
|
628
|
+
allow(defs.first).to(receive(:labels)).and_return([])
|
594
629
|
allow(defs[1]).to(receive(:labels)).and_return([])
|
595
|
-
allow(defs
|
630
|
+
allow(defs.first).to(receive(:<<).and_return(defs.first))
|
596
631
|
allow(defs[1]).to(receive(:<<).and_return(defs[1]))
|
597
632
|
end
|
598
633
|
|
599
634
|
context 'when no explicit version' do
|
600
635
|
before do
|
601
|
-
allow(defs
|
636
|
+
allow(defs.first).to(receive(:explicit_version)).and_return(nil)
|
602
637
|
allow(defs[1]).to(receive(:explicit_version)).and_return(nil)
|
603
638
|
document.parse(input_lines)
|
604
639
|
document.explicit_version?
|
605
640
|
end
|
606
641
|
|
607
|
-
it { expect(defs
|
642
|
+
it { expect(defs.first).to(have_received(:explicit_version)) }
|
608
643
|
it { expect(defs[1]).to(have_received(:explicit_version)) }
|
609
644
|
it { expect(document.explicit_version?).to(be(false)) }
|
610
645
|
end
|
611
646
|
|
612
647
|
context 'when one req has explicit version' do
|
613
648
|
before do
|
614
|
-
allow(defs
|
615
|
-
allow(defs[1]).to(receive(:explicit_version)).and_return(
|
649
|
+
allow(defs.first).to(receive(:explicit_version)).and_return('toto')
|
650
|
+
allow(defs[1]).to(receive(:explicit_version)).and_return(nil)
|
616
651
|
document.parse(input_lines)
|
617
652
|
document.explicit_version?
|
618
653
|
end
|
@@ -622,10 +657,10 @@ RSpec.describe(DefMastership::Document) do
|
|
622
657
|
end
|
623
658
|
|
624
659
|
describe '#ref_to_def?' do
|
625
|
-
let(:
|
660
|
+
let(:definitions) do
|
626
661
|
[
|
627
|
-
instance_double(DefMastership::Definition, '
|
628
|
-
instance_double(DefMastership::Definition, '
|
662
|
+
instance_double(DefMastership::Definition, 'def1'),
|
663
|
+
instance_double(DefMastership::Definition, 'def2')
|
629
664
|
]
|
630
665
|
end
|
631
666
|
let(:input_lines) do
|
@@ -639,17 +674,25 @@ RSpec.describe(DefMastership::Document) do
|
|
639
674
|
end
|
640
675
|
|
641
676
|
before do
|
642
|
-
allow(DefMastership::Definition).to(receive(:new).twice.and_return(
|
643
|
-
allow(
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
677
|
+
allow(DefMastership::Definition).to(receive(:new).twice.and_return(definitions.first, definitions[1]))
|
678
|
+
allow(definitions.first).to(
|
679
|
+
receive_messages(
|
680
|
+
labels: [],
|
681
|
+
'<<': definitions.first,
|
682
|
+
reference: 'TOTO-0001'
|
683
|
+
)
|
684
|
+
)
|
685
|
+
allow(definitions[1]).to(
|
686
|
+
receive_messages(
|
687
|
+
labels: [],
|
688
|
+
'<<': definitions[1],
|
689
|
+
reference: 'TOTO-0002'
|
690
|
+
)
|
691
|
+
)
|
649
692
|
document.parse(input_lines)
|
650
693
|
end
|
651
694
|
|
652
|
-
it { expect(document.ref_to_def('TOTO-0001')).to(eq(
|
653
|
-
it { expect(document.ref_to_def('TOTO-0002')).to(eq(
|
695
|
+
it { expect(document.ref_to_def('TOTO-0001')).to(eq(definitions.first)) }
|
696
|
+
it { expect(document.ref_to_def('TOTO-0002')).to(eq(definitions[1])) }
|
654
697
|
end
|
655
698
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright (c) 2024 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/matching_line')
|
5
|
+
|
6
|
+
RSpec.describe(DefMastership::MatchingLine) do
|
7
|
+
describe '.new' do
|
8
|
+
subject(:matching_line) do
|
9
|
+
described_class.new(:a_match, :a_line)
|
10
|
+
end
|
11
|
+
|
12
|
+
it { is_expected.not_to(be_nil) }
|
13
|
+
it { is_expected.to(have_attributes(match: :a_match)) }
|
14
|
+
it { is_expected.to(have_attributes(line: :a_line)) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#[]' do
|
18
|
+
subject(:matching_line) do
|
19
|
+
described_class.new(match, :a_line)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:match) { instance_double(Hash, 'match') }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(match).to(receive(:[]).with(:whatever).and_return('Whatever'))
|
26
|
+
allow(match).to(receive(:[]).with(:line).and_return(nil))
|
27
|
+
end
|
28
|
+
|
29
|
+
it do
|
30
|
+
matching_line[:whatever]
|
31
|
+
expect(match).to(have_received(:[]).with(:whatever))
|
32
|
+
end
|
33
|
+
|
34
|
+
it { expect(matching_line[:whatever]).to(eq('Whatever')) }
|
35
|
+
it { expect(matching_line[:line]).to(eq(:a_line)) }
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright (c) 2023 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/modifier_factory')
|
5
|
+
|
6
|
+
module DefMastership
|
7
|
+
# Modifier example
|
8
|
+
class TotoModifier
|
9
|
+
include Modifier
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.describe(DefMastership::ModifierFactory) do
|
14
|
+
describe('.from_config') do
|
15
|
+
let(:toto) { instance_double(DefMastership::TotoModifier, 'toto') }
|
16
|
+
let(:toto_config) { { type: 'toto', config: { p: 'whatever' } } }
|
17
|
+
let(:tutu) { instance_double(DefMastership::TotoModifier, 'tutu') }
|
18
|
+
let(:tutu_config) { { type: 'tu_tu', config: { p: 'whatever' } } }
|
19
|
+
|
20
|
+
before do
|
21
|
+
allow(DefMastership::TotoModifier).to(receive(:new).with(toto_config[:config]).and_return(toto))
|
22
|
+
allow(DefMastership::TuTuModifier).to(receive(:new).with(tutu_config[:config]).and_return(tutu))
|
23
|
+
end
|
24
|
+
|
25
|
+
it { expect(described_class.from_config(toto_config)).to(be(toto)) }
|
26
|
+
it { expect(described_class.from_config(tutu_config)).to(be(tutu)) }
|
27
|
+
|
28
|
+
it do
|
29
|
+
described_class.from_config(toto_config)
|
30
|
+
expect(DefMastership::TotoModifier).to(have_received(:new).with(toto_config[:config]))
|
31
|
+
end
|
32
|
+
|
33
|
+
it do
|
34
|
+
described_class.from_config(tutu_config)
|
35
|
+
expect(DefMastership::TuTuModifier).to(have_received(:new).with(tutu_config[:config]))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# Copyright (c) 2023 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/modifier')
|
5
|
+
|
6
|
+
# just a class for test
|
7
|
+
class DummyClassParent
|
8
|
+
# This method smells of :reek:ControlParameter
|
9
|
+
# This method smells of :reek:UtilityFunction
|
10
|
+
def respond_to_missing?(method_name, *_)
|
11
|
+
return true if method_name == :ploup
|
12
|
+
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# just a class for test
|
18
|
+
class DummyClass < DummyClassParent
|
19
|
+
include DefMastership::Modifier
|
20
|
+
|
21
|
+
def self.replacement_methods
|
22
|
+
%i[replace_pouet_by_foo replace_foo_by_zoo]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.default_config
|
26
|
+
{ something: :default }
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(config)
|
30
|
+
setup_modifier_module(config)
|
31
|
+
super()
|
32
|
+
end
|
33
|
+
|
34
|
+
# This method smells of :reek:UtilityFunction
|
35
|
+
def replace_pouet_by_foo(line)
|
36
|
+
line.gsub('pouet', 'foo')
|
37
|
+
end
|
38
|
+
|
39
|
+
# This method smells of :reek:UtilityFunction
|
40
|
+
def replace_foo_by_zoo(line)
|
41
|
+
line.gsub('foo', 'zoo')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
RSpec.describe(DefMastership::Modifier) do
|
46
|
+
subject(:modifier) { DummyClass.new({}) }
|
47
|
+
|
48
|
+
describe '.new' do
|
49
|
+
it { is_expected.not_to(be_nil) }
|
50
|
+
it { is_expected.to(have_attributes(config: { something: :default })) }
|
51
|
+
it { is_expected.to(have_attributes(changes: [])) }
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when want to use config smoothly' do
|
55
|
+
subject(:modifier) { DummyClass.new(plop: 'Whatever', something: :not_default) }
|
56
|
+
|
57
|
+
it { is_expected.to(have_attributes(config: { plop: 'Whatever', something: :not_default })) }
|
58
|
+
it { is_expected.to(have_attributes(plop: 'Whatever')) }
|
59
|
+
it { is_expected.not_to(respond_to(:pleeep)) }
|
60
|
+
it { is_expected.to(respond_to(:ploup)) }
|
61
|
+
|
62
|
+
it do
|
63
|
+
expect { modifier.plooooop }
|
64
|
+
.to(raise_error(NoMethodError))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#apply_to_all' do
|
69
|
+
it do
|
70
|
+
texts = { first: "pouet\ntoto\npouet", second: "toto\npouet\ntoto" }
|
71
|
+
|
72
|
+
expect(modifier.apply_to_all(texts, :replace_pouet_by_foo))
|
73
|
+
.to(eq({ first: "foo\ntoto\nfoo", second: "toto\nfoo\ntoto" }))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#do_modifications' do
|
78
|
+
it do
|
79
|
+
adoc_sources = { first: "pouet\ntoto\npouet", second: "toto\npouet\ntoto" }
|
80
|
+
|
81
|
+
expect(modifier.do_modifications(adoc_sources))
|
82
|
+
.to(eq({ first: "zoo\ntoto\nzoo", second: "toto\nzoo\ntoto" }))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -1,67 +1,239 @@
|
|
1
1
|
# Copyright (c) 2021 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require('defmastership')
|
4
|
+
require('defmastership/rename_included_files_modifier')
|
5
5
|
|
6
6
|
RSpec.describe(DefMastership::RenameIncludedFilesModifier) do
|
7
|
-
subject(:
|
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
|
7
|
+
subject(:includeschanger) { described_class.new({}) }
|
19
8
|
|
20
9
|
describe '.new' do
|
10
|
+
it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
|
21
11
|
it { is_expected.not_to(be_nil) }
|
22
|
-
it { is_expected.to(have_attributes(
|
23
|
-
it { is_expected.to(have_attributes(
|
12
|
+
it { is_expected.to(have_attributes(from_regexp: '')) }
|
13
|
+
it { is_expected.to(have_attributes(to_template: '')) }
|
24
14
|
end
|
25
15
|
|
26
|
-
describe '
|
27
|
-
|
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
|
16
|
+
describe '.replacement_methods' do
|
17
|
+
it { expect(described_class.replacement_methods).to(eq(%i[replace])) }
|
18
|
+
end
|
40
19
|
|
41
|
-
|
42
|
-
|
20
|
+
describe '.respond_to_missing?' do
|
21
|
+
it { expect(includeschanger.respond_to?(:add_new_definition)).to(be(true)) }
|
22
|
+
it { expect(includeschanger.respond_to?(:not_implemented_random_method)).to(be(false)) }
|
23
|
+
end
|
43
24
|
|
44
|
-
|
45
|
-
|
46
|
-
|
25
|
+
describe '#replace' do
|
26
|
+
context 'when NOT valid include' do
|
27
|
+
subject(:includeschanger) do
|
28
|
+
described_class.new(
|
29
|
+
from_regexp: 'orig',
|
30
|
+
to_template: 'dest'
|
47
31
|
)
|
48
32
|
end
|
49
33
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
34
|
+
before do
|
35
|
+
allow(File).to(receive(:rename))
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when the include statement do not match' do
|
39
|
+
before do
|
40
|
+
['[define,requirement,REFERENCE]', '--'].each do |line|
|
41
|
+
includeschanger.replace(line)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it do
|
46
|
+
expect(includeschanger.replace('badinclude::orig[]'))
|
47
|
+
.to(eq('badinclude::orig[]'))
|
48
|
+
end
|
49
|
+
|
50
|
+
it do
|
51
|
+
includeschanger.replace('badinclude::orig[]')
|
52
|
+
expect(includeschanger).to(have_attributes(changes: []))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when the include is not in a definition' do
|
57
|
+
before do
|
58
|
+
['[define,requirement,REFERENCE]', '--', 'text', '--'].each do |line|
|
59
|
+
includeschanger.replace(line)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it do
|
64
|
+
expect(includeschanger.replace('include::orig[]'))
|
65
|
+
.to(eq('include::orig[]'))
|
66
|
+
end
|
67
|
+
|
68
|
+
it do
|
69
|
+
includeschanger.replace('include::orig[]')
|
70
|
+
expect(includeschanger).to(have_attributes(changes: []))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when the line is commented' do
|
75
|
+
before do
|
76
|
+
includeschanger.replace('[define,requirement,REFERENCE]')
|
77
|
+
includeschanger.replace('--')
|
78
|
+
end
|
79
|
+
|
80
|
+
it do
|
81
|
+
expect(includeschanger.replace('// include::orig[]'))
|
82
|
+
.to(eq('// include::orig[]'))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when the cancel regexp is met' do
|
87
|
+
subject(:includeschanger) do
|
88
|
+
described_class.new(
|
89
|
+
from_regexp: 'orig',
|
90
|
+
cancel_if_match: 'orig',
|
91
|
+
to_template: 'dest'
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
before do
|
96
|
+
includeschanger.replace('[define,requirement,REFERENCE]')
|
97
|
+
includeschanger.replace('--')
|
98
|
+
end
|
99
|
+
|
100
|
+
it do
|
101
|
+
expect(includeschanger.replace("include::orig[]\n"))
|
102
|
+
.to(eq("include::orig[]\n"))
|
103
|
+
end
|
104
|
+
end
|
57
105
|
end
|
58
106
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
107
|
+
context 'when valid include' do
|
108
|
+
before do
|
109
|
+
allow(File).to(receive(:rename))
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'when really simple rule' do
|
113
|
+
subject(:includeschanger) do
|
114
|
+
described_class.new(
|
115
|
+
from_regexp: 'orig',
|
116
|
+
cancel_if_match: '_no_cancel_',
|
117
|
+
to_template: 'dest'
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
before do
|
122
|
+
includeschanger.replace('[define,requirement,REFERENCE]')
|
123
|
+
includeschanger.replace('--')
|
124
|
+
end
|
125
|
+
|
126
|
+
it do
|
127
|
+
expect(includeschanger.replace("include::orig[]\n"))
|
128
|
+
.to(eq("include::dest[]\n"))
|
129
|
+
end
|
130
|
+
|
131
|
+
it do
|
132
|
+
includeschanger.replace("include::orig[]\n")
|
133
|
+
expect(File).to(have_received(:rename).with('orig', 'dest'))
|
134
|
+
end
|
135
|
+
|
136
|
+
it do
|
137
|
+
expect(includeschanger.replace("include::orig[leveloffset=offset,lines=ranges]\n"))
|
138
|
+
.to(eq("include::dest[leveloffset=offset,lines=ranges]\n"))
|
139
|
+
end
|
140
|
+
|
141
|
+
it do
|
142
|
+
includeschanger.replace("include::orig[leveloffset=offset,lines=ranges]\n")
|
143
|
+
expect(File).to(have_received(:rename).with('orig', 'dest'))
|
144
|
+
end
|
145
|
+
|
146
|
+
it do
|
147
|
+
includeschanger.replace("include::orig[]\n")
|
148
|
+
expect(includeschanger).to(have_attributes(changes: [%w[orig dest]]))
|
149
|
+
end
|
150
|
+
|
151
|
+
it do
|
152
|
+
expect(includeschanger.replace("include::toto/orig[]\n"))
|
153
|
+
.to(eq("include::toto/dest[]\n"))
|
154
|
+
end
|
155
|
+
|
156
|
+
it do
|
157
|
+
includeschanger.replace("include::toto/orig[]\n")
|
158
|
+
expect(File).to(have_received(:rename).with('toto/orig', 'toto/dest'))
|
159
|
+
end
|
160
|
+
|
161
|
+
it do
|
162
|
+
includeschanger.replace("include::toto/orig[]\n")
|
163
|
+
expect(includeschanger).to(have_attributes(changes: [%w[toto/orig toto/dest]]))
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
context 'when complex from_regexp' do
|
168
|
+
subject(:includeschanger) do
|
169
|
+
described_class.new(
|
170
|
+
from_regexp: '(?<origin>.*\.extension)',
|
171
|
+
to_template: '%<reference>s_%<origin>s'
|
172
|
+
)
|
173
|
+
end
|
174
|
+
|
175
|
+
before do
|
176
|
+
includeschanger.replace('[define,requirement,REF]')
|
177
|
+
end
|
178
|
+
|
179
|
+
it do
|
180
|
+
expect(includeschanger.replace('include::any_path/one_file.extension[]'))
|
181
|
+
.to(eq('include::any_path/REF_one_file.extension[]'))
|
182
|
+
end
|
183
|
+
|
184
|
+
it do
|
185
|
+
includeschanger.replace('include::any_path/one_file.extension[]')
|
186
|
+
expect(File).to(have_received(:rename).with('any_path/one_file.extension', 'any_path/REF_one_file.extension'))
|
187
|
+
end
|
188
|
+
|
189
|
+
it do
|
190
|
+
changes = [%w[any_path/one_file.extension any_path/REF_one_file.extension]]
|
191
|
+
includeschanger.replace('include::any_path/one_file.extension[]')
|
192
|
+
expect(includeschanger).to(have_attributes(changes: changes))
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context 'when path with variable' do
|
197
|
+
subject(:includeschanger) do
|
198
|
+
described_class.new(
|
199
|
+
from_regexp: 'orig',
|
200
|
+
to_template: 'dest'
|
201
|
+
)
|
202
|
+
end
|
203
|
+
|
204
|
+
before do
|
205
|
+
includeschanger.replace(':any: one')
|
206
|
+
includeschanger.replace(':path: two')
|
207
|
+
includeschanger.replace(':var: three')
|
208
|
+
includeschanger.replace('[define,requirement,REFERENCE]')
|
209
|
+
includeschanger.replace('--')
|
210
|
+
end
|
211
|
+
|
212
|
+
it do
|
213
|
+
expect(includeschanger.replace('include::{any}/orig[]'))
|
214
|
+
.to(eq('include::{any}/dest[]'))
|
215
|
+
end
|
216
|
+
|
217
|
+
it do
|
218
|
+
includeschanger.replace('include::{any}{var}/orig[]')
|
219
|
+
expect(File).to(have_received(:rename).with('onethree/orig', 'onethree/dest'))
|
220
|
+
end
|
221
|
+
|
222
|
+
it do
|
223
|
+
includeschanger.replace('include::{any}_{path}/orig[]')
|
224
|
+
expect(File).to(have_received(:rename).with('one_two/orig', 'one_two/dest'))
|
225
|
+
end
|
226
|
+
|
227
|
+
it do
|
228
|
+
expect { includeschanger.replace('include::{bad_variable}/orig[]') }
|
229
|
+
.to(raise_error(KeyError, 'key not found: :bad_variable'))
|
230
|
+
end
|
231
|
+
|
232
|
+
it do
|
233
|
+
includeschanger.replace('include::{any}_{path}/orig[]')
|
234
|
+
expect(includeschanger).to(have_attributes(changes: [%w[one_two/orig one_two/dest]]))
|
235
|
+
end
|
236
|
+
end
|
65
237
|
end
|
66
238
|
end
|
67
239
|
end
|