defmastership 1.0.16 → 1.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +50 -7
- data/.rubocop.yml +14 -6
- data/Gemfile +51 -1
- data/Rakefile +16 -47
- data/bin/defmastership +12 -9
- data/config/mutant.yml +23 -3
- data/defmastership.gemspec +22 -27
- data/features/definition_checksum.feature +31 -1
- data/features/export.feature +43 -1
- data/features/rename_included_files.feature +28 -0
- data/lib/defmastership/batch_modifier.rb +17 -12
- data/lib/defmastership/change_ref_modifier.rb +89 -5
- data/lib/defmastership/comment_filter.rb +1 -1
- data/lib/defmastership/constants.rb +5 -4
- data/lib/defmastership/csv_formatter.rb +20 -16
- data/lib/defmastership/csv_formatter_body.rb +18 -15
- data/lib/defmastership/csv_formatter_header.rb +1 -1
- data/lib/defmastership/definition.rb +58 -19
- data/lib/defmastership/document.rb +109 -74
- data/lib/defmastership/matching_line.rb +17 -0
- data/lib/defmastership/modifier.rb +42 -0
- data/lib/defmastership/modifier_factory.rb +12 -0
- data/lib/defmastership/parsing_state.rb +15 -9
- data/lib/defmastership/rename_included_files_modifier.rb +172 -5
- data/lib/defmastership/set_join_hack.rb +11 -0
- data/lib/defmastership/update_def_checksum_modifier.rb +8 -13
- data/lib/defmastership/update_def_modifier.rb +49 -0
- data/lib/defmastership/update_def_version_modifier.rb +56 -15
- data/lib/defmastership/version.rb +1 -1
- data/lib/defmastership.rb +7 -17
- data/spec/spec_helper.rb +4 -2
- data/spec/unit/{defmastership → def_mastership}/batch_modifier_spec.rb +42 -39
- data/spec/unit/{defmastership/change_ref_line_modifier_spec.rb → def_mastership/change_ref_modifier_spec.rb} +44 -66
- data/spec/unit/{defmastership → def_mastership}/csv_formatter_body_spec.rb +61 -32
- data/spec/unit/{defmastership → def_mastership}/csv_formatter_header_spec.rb +2 -2
- data/spec/unit/{defmastership → def_mastership}/csv_formatter_spec.rb +81 -86
- data/spec/unit/{defmastership → def_mastership}/definition_parser_spec.rb +2 -2
- data/spec/unit/{defmastership → def_mastership}/definition_spec.rb +17 -7
- data/spec/unit/{defmastership → def_mastership}/document_spec.rb +108 -53
- data/spec/unit/def_mastership/matching_line_spec.rb +37 -0
- data/spec/unit/def_mastership/modifier_factory_spec.rb +37 -0
- data/spec/unit/def_mastership/modifier_spec.rb +83 -0
- data/spec/unit/{defmastership → def_mastership}/parsing_state_spec.rb +16 -16
- data/spec/unit/{defmastership/rename_included_files_line_modifier_spec.rb → def_mastership/rename_included_files_modifier_spec.rb} +72 -36
- data/spec/unit/{defmastership/comment_filter_spec.rb → def_mastership/string_spec.rb} +1 -1
- data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +107 -0
- data/spec/unit/def_mastership/update_def_modifier_spec.rb +119 -0
- data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +159 -0
- data/spec/unit/{defmastership_spec.rb → def_mastership_spec.rb} +1 -1
- data/tasks/console.rake +8 -0
- data/tasks/package.task +9 -0
- data/tasks/smelling_code.rake +38 -0
- data/tasks/test.rake +45 -0
- metadata +37 -145
- data/lib/defmastership/change_ref_line_modifier.rb +0 -82
- data/lib/defmastership/line_modifier_base.rb +0 -29
- data/lib/defmastership/modifier_base.rb +0 -29
- 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/defmastership/change_ref_modifier_spec.rb +0 -76
- data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +0 -67
- data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +0 -78
- data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +0 -75
- data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +0 -127
- data/spec/unit/defmastership/update_def_version_modifier_spec.rb +0 -80
@@ -1,13 +1,13 @@
|
|
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 }
|
8
8
|
|
9
9
|
describe '.new' do
|
10
|
-
it { is_expected.not_to(
|
10
|
+
it { is_expected.not_to(be_nil) }
|
11
11
|
it { is_expected.to(have_attributes(definitions: [])) }
|
12
12
|
it { is_expected.to(have_attributes(eref: {})) }
|
13
13
|
it { is_expected.to(have_attributes(iref: false)) }
|
@@ -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
|
@@ -323,7 +339,7 @@ RSpec.describe(DefMastership::Document) do
|
|
323
339
|
it { expect(definition).to(have_received(:add_iref).with('toto')) }
|
324
340
|
it { expect(definition).to(have_received(:add_iref).with('tutu')) }
|
325
341
|
it { expect(definition).to(have_received(:add_iref).with('pouet')) }
|
326
|
-
it { expect(document.iref).to(
|
342
|
+
it { expect(document.iref).to(be(true)) }
|
327
343
|
end
|
328
344
|
|
329
345
|
context 'when configure attributes' do
|
@@ -365,7 +381,7 @@ RSpec.describe(DefMastership::Document) do
|
|
365
381
|
|
366
382
|
it do
|
367
383
|
document.parse(input_lines)
|
368
|
-
expect(document.iref).to(
|
384
|
+
expect(document.iref).to(be(false))
|
369
385
|
end
|
370
386
|
end
|
371
387
|
|
@@ -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
|
|
@@ -522,8 +558,12 @@ RSpec.describe(DefMastership::Document) do
|
|
522
558
|
end
|
523
559
|
|
524
560
|
describe '#wrong_explicit_checksum?' do
|
525
|
-
let(:
|
526
|
-
|
561
|
+
let(:defs) do
|
562
|
+
[
|
563
|
+
instance_double(DefMastership::Definition, 'definition'),
|
564
|
+
instance_double(DefMastership::Definition, 'definition')
|
565
|
+
]
|
566
|
+
end
|
527
567
|
let(:input_lines) do
|
528
568
|
[
|
529
569
|
'[define, requirement, TOTO-0001]',
|
@@ -535,41 +575,44 @@ RSpec.describe(DefMastership::Document) do
|
|
535
575
|
end
|
536
576
|
|
537
577
|
before do
|
538
|
-
allow(DefMastership::Definition).to(receive(:new).twice.and_return(
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
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
|
543
583
|
end
|
544
584
|
|
545
585
|
context 'when no wrong explicit checksum' do
|
546
586
|
before do
|
547
|
-
allow(
|
548
|
-
allow(def2).to(receive(:wrong_explicit_checksum)).and_return(nil)
|
587
|
+
defs.each { |definition| allow(definition).to(receive(:wrong_explicit_checksum)).and_return(nil) }
|
549
588
|
document.parse(input_lines)
|
550
589
|
document.wrong_explicit_checksum?
|
551
590
|
end
|
552
591
|
|
553
|
-
it { expect(
|
554
|
-
it { expect(
|
555
|
-
it { expect(document.wrong_explicit_checksum?).to(
|
592
|
+
it { expect(defs.first).to(have_received(:wrong_explicit_checksum)) }
|
593
|
+
it { expect(defs[1]).to(have_received(:wrong_explicit_checksum)) }
|
594
|
+
it { expect(document.wrong_explicit_checksum?).to(be(false)) }
|
556
595
|
end
|
557
596
|
|
558
597
|
context 'when one req has wrong explicit checksum' do
|
559
598
|
before do
|
560
|
-
allow(
|
561
|
-
allow(
|
599
|
+
allow(defs.first).to(receive(:wrong_explicit_checksum)).and_return('toto')
|
600
|
+
allow(defs[1]).to(receive(:wrong_explicit_checksum)).and_return(nil)
|
562
601
|
document.parse(input_lines)
|
563
602
|
document.wrong_explicit_checksum?
|
564
603
|
end
|
565
604
|
|
566
|
-
it { expect(document.wrong_explicit_checksum?).to(
|
605
|
+
it { expect(document.wrong_explicit_checksum?).to(be(true)) }
|
567
606
|
end
|
568
607
|
end
|
569
608
|
|
570
609
|
describe '#explicit_version?' do
|
571
|
-
let(:
|
572
|
-
|
610
|
+
let(:defs) do
|
611
|
+
[
|
612
|
+
instance_double(DefMastership::Definition, 'definition'),
|
613
|
+
instance_double(DefMastership::Definition, 'definition')
|
614
|
+
]
|
615
|
+
end
|
573
616
|
let(:input_lines) do
|
574
617
|
[
|
575
618
|
'[define, requirement, TOTO-0001]',
|
@@ -581,41 +624,45 @@ RSpec.describe(DefMastership::Document) do
|
|
581
624
|
end
|
582
625
|
|
583
626
|
before do
|
584
|
-
allow(DefMastership::Definition).to(receive(:new).twice.and_return(
|
585
|
-
allow(
|
586
|
-
allow(
|
587
|
-
allow(
|
588
|
-
allow(
|
627
|
+
allow(DefMastership::Definition).to(receive(:new).twice.and_return(defs.first, defs[1]))
|
628
|
+
allow(defs.first).to(receive(:labels)).and_return([])
|
629
|
+
allow(defs[1]).to(receive(:labels)).and_return([])
|
630
|
+
allow(defs.first).to(receive(:<<).and_return(defs.first))
|
631
|
+
allow(defs[1]).to(receive(:<<).and_return(defs[1]))
|
589
632
|
end
|
590
633
|
|
591
634
|
context 'when no explicit version' do
|
592
635
|
before do
|
593
|
-
allow(
|
594
|
-
allow(
|
636
|
+
allow(defs.first).to(receive(:explicit_version)).and_return(nil)
|
637
|
+
allow(defs[1]).to(receive(:explicit_version)).and_return(nil)
|
595
638
|
document.parse(input_lines)
|
596
639
|
document.explicit_version?
|
597
640
|
end
|
598
641
|
|
599
|
-
it { expect(
|
600
|
-
it { expect(
|
601
|
-
it { expect(document.explicit_version?).to(
|
642
|
+
it { expect(defs.first).to(have_received(:explicit_version)) }
|
643
|
+
it { expect(defs[1]).to(have_received(:explicit_version)) }
|
644
|
+
it { expect(document.explicit_version?).to(be(false)) }
|
602
645
|
end
|
603
646
|
|
604
647
|
context 'when one req has explicit version' do
|
605
648
|
before do
|
606
|
-
allow(
|
607
|
-
allow(
|
649
|
+
allow(defs.first).to(receive(:explicit_version)).and_return('toto')
|
650
|
+
allow(defs[1]).to(receive(:explicit_version)).and_return(nil)
|
608
651
|
document.parse(input_lines)
|
609
652
|
document.explicit_version?
|
610
653
|
end
|
611
654
|
|
612
|
-
it { expect(document.explicit_version?).to(
|
655
|
+
it { expect(document.explicit_version?).to(be(true)) }
|
613
656
|
end
|
614
657
|
end
|
615
658
|
|
616
659
|
describe '#ref_to_def?' do
|
617
|
-
let(:
|
618
|
-
|
660
|
+
let(:definitions) do
|
661
|
+
[
|
662
|
+
instance_double(DefMastership::Definition, 'def1'),
|
663
|
+
instance_double(DefMastership::Definition, 'def2')
|
664
|
+
]
|
665
|
+
end
|
619
666
|
let(:input_lines) do
|
620
667
|
[
|
621
668
|
'[define, requirement, TOTO-0001]',
|
@@ -627,17 +674,25 @@ RSpec.describe(DefMastership::Document) do
|
|
627
674
|
end
|
628
675
|
|
629
676
|
before do
|
630
|
-
allow(DefMastership::Definition).to(receive(:new).twice.and_return(
|
631
|
-
allow(
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
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
|
+
)
|
637
692
|
document.parse(input_lines)
|
638
693
|
end
|
639
694
|
|
640
|
-
it { expect(document.ref_to_def('TOTO-0001')).to(eq(
|
641
|
-
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])) }
|
642
697
|
end
|
643
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,37 @@
|
|
1
|
+
# Copyright (c) 2023 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/modifier_factory')
|
5
|
+
|
6
|
+
module DefMastership
|
7
|
+
class TotoModifier
|
8
|
+
include Modifier
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.describe(DefMastership::ModifierFactory) do
|
13
|
+
describe('.from_config') do
|
14
|
+
let(:toto) { instance_double(DefMastership::TotoModifier, 'toto') }
|
15
|
+
let(:toto_config) { { type: 'toto', config: { p: 'whatever' } } }
|
16
|
+
let(:tutu) { instance_double(DefMastership::TotoModifier, 'tutu') }
|
17
|
+
let(:tutu_config) { { type: 'tu_tu', config: { p: 'whatever' } } }
|
18
|
+
|
19
|
+
before do
|
20
|
+
allow(DefMastership::TotoModifier).to(receive(:new).with(toto_config[:config]).and_return(toto))
|
21
|
+
allow(DefMastership::TuTuModifier).to(receive(:new).with(tutu_config[:config]).and_return(tutu))
|
22
|
+
end
|
23
|
+
|
24
|
+
it { expect(described_class.from_config(toto_config)).to(be(toto)) }
|
25
|
+
it { expect(described_class.from_config(tutu_config)).to(be(tutu)) }
|
26
|
+
|
27
|
+
it do
|
28
|
+
described_class.from_config(toto_config)
|
29
|
+
expect(DefMastership::TotoModifier).to(have_received(:new).with(toto_config[:config]))
|
30
|
+
end
|
31
|
+
|
32
|
+
it do
|
33
|
+
described_class.from_config(tutu_config)
|
34
|
+
expect(DefMastership::TuTuModifier).to(have_received(:new).with(tutu_config[:config]))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Copyright (c) 2023 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/modifier')
|
5
|
+
|
6
|
+
class DummyclassParrent
|
7
|
+
def respond_to_missing?(method_name, *_)
|
8
|
+
return true if method_name == :ploup
|
9
|
+
|
10
|
+
false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class DummyClass < DummyclassParrent
|
15
|
+
include DefMastership::Modifier
|
16
|
+
|
17
|
+
def self.replacement_methods
|
18
|
+
%i[replace_pouet_by_foo replace_foo_by_zoo]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.default_config
|
22
|
+
{ something: :default }
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(config)
|
26
|
+
setup_modifier_module(config)
|
27
|
+
super()
|
28
|
+
end
|
29
|
+
|
30
|
+
def replace_pouet_by_foo(line)
|
31
|
+
line.gsub('pouet', 'foo')
|
32
|
+
end
|
33
|
+
|
34
|
+
def replace_foo_by_zoo(line)
|
35
|
+
line.gsub('foo', 'zoo')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class BadDummyClass < DummyclassParrent
|
40
|
+
include DefMastership::Modifier
|
41
|
+
end
|
42
|
+
|
43
|
+
RSpec.describe(DefMastership::Modifier) do
|
44
|
+
subject(:modifier) { DummyClass.new({}) }
|
45
|
+
|
46
|
+
describe '.new' do
|
47
|
+
it { is_expected.not_to(be_nil) }
|
48
|
+
it { is_expected.to(have_attributes(config: { something: :default })) }
|
49
|
+
it { is_expected.to(have_attributes(changes: [])) }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when want to use config smoothly' do
|
53
|
+
subject(:modifier) { DummyClass.new(plop: 'Whatever', something: :not_default) }
|
54
|
+
|
55
|
+
it { is_expected.to(have_attributes(config: { plop: 'Whatever', something: :not_default })) }
|
56
|
+
it { is_expected.to(have_attributes(plop: 'Whatever')) }
|
57
|
+
it { is_expected.not_to(respond_to(:pleeep)) }
|
58
|
+
it { is_expected.to(respond_to(:ploup)) }
|
59
|
+
|
60
|
+
it do
|
61
|
+
expect { modifier.plooooop }
|
62
|
+
.to(raise_error(NoMethodError))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#apply_to_all' do
|
67
|
+
it do
|
68
|
+
texts = { first: "pouet\ntoto\npouet", second: "toto\npouet\ntoto" }
|
69
|
+
|
70
|
+
expect(modifier.apply_to_all(texts, :replace_pouet_by_foo))
|
71
|
+
.to(eq({ first: "foo\ntoto\nfoo", second: "toto\nfoo\ntoto" }))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#do_modifications' do
|
76
|
+
it do
|
77
|
+
adoc_sources = { first: "pouet\ntoto\npouet", second: "toto\npouet\ntoto" }
|
78
|
+
|
79
|
+
expect(modifier.do_modifications(adoc_sources))
|
80
|
+
.to(eq({ first: "zoo\ntoto\nzoo", second: "toto\nzoo\ntoto" }))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -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/parsing_state')
|
5
5
|
|
6
6
|
RSpec.describe(DefMastership::ParsingState) do
|
7
7
|
subject(:parsing_state) do
|
@@ -9,29 +9,29 @@ RSpec.describe(DefMastership::ParsingState) do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe '.new' do
|
12
|
-
it { is_expected.not_to(
|
12
|
+
it { is_expected.not_to(be_nil) }
|
13
13
|
end
|
14
14
|
|
15
15
|
describe '#enabled_with?' do
|
16
16
|
context 'when single line commment' do
|
17
|
-
it { expect(parsing_state.enabled?("//whatever\n")).to(
|
17
|
+
it { expect(parsing_state.enabled?("//whatever\n")).to(be(false)) }
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'when starting' do
|
21
|
-
it { expect(parsing_state.enabled?("whatever\n")).to(
|
22
|
-
it { expect(parsing_state.enabled?("----\n")).to(
|
23
|
-
it { expect(parsing_state.enabled?("....\n")).to(
|
24
|
-
it { expect(parsing_state.enabled?("////\n")).to(
|
25
|
-
it { expect(parsing_state.enabled?('....')).to(
|
21
|
+
it { expect(parsing_state.enabled?("whatever\n")).to(be(true)) }
|
22
|
+
it { expect(parsing_state.enabled?("----\n")).to(be(false)) }
|
23
|
+
it { expect(parsing_state.enabled?("....\n")).to(be(false)) }
|
24
|
+
it { expect(parsing_state.enabled?("////\n")).to(be(false)) }
|
25
|
+
it { expect(parsing_state.enabled?('....')).to(be(false)) }
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'when disabled' do
|
29
29
|
before { parsing_state.enabled?("----\n") }
|
30
30
|
|
31
|
-
it { expect(parsing_state.enabled?("whatever\n")).to(
|
32
|
-
it { expect(parsing_state.enabled?("----\n")).to(
|
33
|
-
it { expect(parsing_state.enabled?("....\n")).to(
|
34
|
-
it { expect(parsing_state.enabled?("////\n")).to(
|
31
|
+
it { expect(parsing_state.enabled?("whatever\n")).to(be(false)) }
|
32
|
+
it { expect(parsing_state.enabled?("----\n")).to(be(true)) }
|
33
|
+
it { expect(parsing_state.enabled?("....\n")).to(be(false)) }
|
34
|
+
it { expect(parsing_state.enabled?("////\n")).to(be(false)) }
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'with intricated disables starting with "...."' do
|
@@ -39,8 +39,8 @@ RSpec.describe(DefMastership::ParsingState) do
|
|
39
39
|
["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
|
40
40
|
end
|
41
41
|
|
42
|
-
it { expect(parsing_state.enabled?("----\n")).to(
|
43
|
-
it { expect(parsing_state.enabled?("....\n")).to(
|
42
|
+
it { expect(parsing_state.enabled?("----\n")).to(be(false)) }
|
43
|
+
it { expect(parsing_state.enabled?("....\n")).to(be(true)) }
|
44
44
|
end
|
45
45
|
|
46
46
|
context 'with intricated disables starting with "----"' do
|
@@ -48,7 +48,7 @@ RSpec.describe(DefMastership::ParsingState) do
|
|
48
48
|
["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
|
49
49
|
end
|
50
50
|
|
51
|
-
it { expect(parsing_state.enabled?("....\n")).to(
|
51
|
+
it { expect(parsing_state.enabled?("....\n")).to(be(true)) }
|
52
52
|
end
|
53
53
|
|
54
54
|
context 'with intricated disables starting with "////"' do
|
@@ -56,7 +56,7 @@ RSpec.describe(DefMastership::ParsingState) do
|
|
56
56
|
["////\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) }
|
57
57
|
end
|
58
58
|
|
59
|
-
it { expect(parsing_state.enabled?("////\n")).to(
|
59
|
+
it { expect(parsing_state.enabled?("////\n")).to(be(true)) }
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|