Skip to content

Commit 5396f5d

Browse files
committed
Unify coverage fixtures into spec/support/coverage_fixtures.rb
1 parent 8043e7d commit 5396f5d

3 files changed

Lines changed: 20 additions & 162 deletions

File tree

spec/formatter/html_formatter_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require "helper"
44
require "fileutils"
55
require "json"
6-
require "support/html_formatter_coverage_fixtures"
6+
require "support/coverage_fixtures"
77

88
describe SimpleCov::Formatter::HTMLFormatter do
99
subject(:formatter) { described_class.new(silent: true) }
@@ -21,7 +21,7 @@ def fixture_path(name)
2121
File.join(fixtures_path, name)
2222
end
2323

24-
def make_result(coverage = {"sample.rb" => HTMLFormatterCoverageFixtures::SAMPLE_RB})
24+
def make_result(coverage = {"sample.rb" => CoverageFixtures::SAMPLE_RB})
2525
SimpleCov::Result.new(coverage.transform_keys { |name| fixture_path(name) })
2626
end
2727

@@ -146,7 +146,7 @@ def coverage_data(dir = coverage_dir)
146146
let!(:original_criteria) { SimpleCov.coverage_criteria.dup }
147147
let!(:original_filters) { SimpleCov.filters.dup }
148148

149-
let(:full_coverage) { HTMLFormatterCoverageFixtures::ALL_FIXTURES }
149+
let(:full_coverage) { CoverageFixtures::ALL_FIXTURES }
150150

151151
before do
152152
SimpleCov.enable_coverage(:branch)

spec/source_file_spec.rb

Lines changed: 14 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "helper"
4+
require "support/coverage_fixtures"
45

56
COVERAGE_FOR_SAMPLE_RB = {
67
"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, 1, 0, nil, nil, nil],
@@ -16,30 +17,6 @@
1617
"branches" => nil
1718
}.freeze
1819

19-
COVERAGE_FOR_BRANCHES_RB = {
20-
"lines" => [1, 1, 1, nil, 1, nil, 1, 0, nil, 1, nil, nil, nil],
21-
"branches" => {
22-
[:if, 0, 3, 4, 3, 21] =>
23-
{[:then, 1, 3, 4, 3, 10] => 0, [:else, 2, 3, 4, 3, 21] => 1},
24-
[:if, 3, 5, 4, 5, 26] =>
25-
{[:then, 4, 5, 16, 5, 20] => 1, [:else, 5, 5, 23, 5, 26] => 0},
26-
[:if, 6, 7, 4, 11, 7] =>
27-
{[:then, 7, 8, 6, 8, 10] => 0, [:else, 8, 10, 6, 10, 9] => 1}
28-
}
29-
}.freeze
30-
31-
COVERAGE_FOR_INLINE = {
32-
"lines" => [1, 1, 1, nil, 1, 1, 0, nil, 1, nil, nil, nil, nil],
33-
"branches" => {
34-
[:if, 0, 3, 11, 3, 33] =>
35-
{[:then, 1, 3, 23, 3, 27] => 1, [:else, 2, 3, 30, 3, 33] => 0},
36-
[:if, 3, 6, 6, 10, 9] =>
37-
{[:then, 4, 7, 8, 7, 12] => 0, [:else, 5, 9, 8, 9, 11] => 1}
38-
}
39-
}.freeze
40-
41-
COVERAGE_FOR_NEVER_RB = {"lines" => [nil, nil], "branches" => {}}.freeze
42-
4320
COVERAGE_FOR_SKIPPED_RB = {"lines" => [nil, nil, nil, nil]}.freeze
4421

4522
COVERAGE_FOR_SKIPPED_RB_2 = {"lines" => [nil, nil, 0, nil]}.freeze
@@ -52,125 +29,6 @@
5229
}
5330
}.freeze
5431

55-
COVERAGE_FOR_NOCOV_COMPLEX_RB = {
56-
"lines" => [nil, nil, 1, 1, nil, 1, nil, nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, 1, nil, 0, nil, nil, 1, nil, nil, nil, nil],
57-
"branches" => {
58-
[:if, 0, 6, 4, 11, 7] =>
59-
{[:then, 1, 7, 6, 7, 7] => 0, [:else, 2, 10, 6, 10, 7] => 1},
60-
[:if, 3, 13, 4, 13, 24] =>
61-
{[:then, 4, 13, 4, 13, 12] => 1, [:else, 5, 13, 4, 13, 24] => 0},
62-
[:while, 6, 16, 4, 16, 27] =>
63-
{[:body, 7, 16, 4, 16, 12] => 2},
64-
[:case, 8, 18, 4, 24, 7] => {
65-
[:when, 9, 20, 6, 20, 11] => 0,
66-
[:when, 10, 23, 6, 23, 10] => 1,
67-
[:else, 11, 18, 4, 24, 7] => 0
68-
}
69-
}
70-
}.freeze
71-
72-
COVERAGE_FOR_NESTED_BRANCHES_RB = {
73-
"lines" => [nil, nil, 1, 1, 1, 1, 1, 1, nil, nil, 0, nil, nil, nil, nil],
74-
"branches" => {
75-
[:while, 0, 7, 8, 7, 31] =>
76-
{[:body, 1, 7, 8, 7, 16] => 2},
77-
[:if, 2, 6, 6, 9, 9] =>
78-
{[:then, 3, 7, 8, 8, 11] => 1, [:else, 4, 6, 6, 9, 9] => 0},
79-
[:if, 5, 5, 4, 12, 7] =>
80-
{[:then, 6, 6, 6, 9, 9] => 1, [:else, 7, 11, 6, 11, 11] => 0}
81-
}
82-
}.freeze
83-
84-
COVERAGE_FOR_CASE_STATEMENT_RB = {
85-
"lines" => [1, 1, 1, nil, 0, nil, 1, nil, 0, nil, 0, nil, nil, nil],
86-
"branches" => {
87-
[:case, 0, 3, 4, 12, 7] => {
88-
[:when, 1, 5, 6, 5, 10] => 0,
89-
[:when, 2, 7, 6, 7, 10] => 1,
90-
[:when, 3, 9, 6, 9, 10] => 0,
91-
[:else, 4, 11, 6, 11, 11] => 0
92-
}
93-
}
94-
}.freeze
95-
96-
COVERAGE_FOR_CASE_WITHOUT_ELSE_STATEMENT_RB = {
97-
"lines" => [1, 1, 1, nil, 0, nil, 1, nil, 0, nil, nil, nil],
98-
"branches" => {
99-
[:case, 0, 3, 4, 10, 7] => {
100-
[:when, 1, 5, 6, 5, 10] => 0,
101-
[:when, 2, 7, 6, 7, 10] => 1,
102-
[:when, 3, 9, 6, 9, 10] => 0,
103-
[:else, 4, 3, 4, 10, 7] => 0
104-
}
105-
}
106-
}.freeze
107-
108-
COVERAGE_FOR_ELSIF_RB = {
109-
"lines" => [1, 1, 1, 0, 1, 0, 1, 1, nil, 0, nil, nil, nil],
110-
"branches" => {
111-
[:if, 0, 7, 4, 10, 10] =>
112-
{[:then, 1, 8, 6, 8, 10] => 1, [:else, 2, 10, 6, 10, 10] => 0},
113-
[:if, 3, 5, 4, 10, 10] =>
114-
{[:then, 4, 6, 6, 6, 10] => 0, [:else, 5, 7, 4, 10, 10] => 1},
115-
[:if, 6, 3, 4, 11, 7] =>
116-
{[:then, 7, 4, 6, 4, 10] => 0, [:else, 8, 5, 4, 10, 10] => 1}
117-
}
118-
}.freeze
119-
120-
COVERAGE_FOR_BRANCH_TESTER_RB = {
121-
"lines" => [nil, nil, 1, 1, nil, 1, nil, 1, 1, nil, nil, 1, 0, nil, nil, 1, 0, nil, 1, nil, nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, 1, 1, nil, 0, nil, 1, 1, 0, 0, 1, 5, 0, 0, nil, 0, nil, 0, nil, nil, nil],
122-
"branches" => {
123-
[:if, 0, 4, 0, 4, 19] =>
124-
{[:then, 1, 4, 12, 4, 15] => 0, [:else, 2, 4, 18, 4, 19] => 1},
125-
[:unless, 3, 6, 0, 6, 23] =>
126-
{[:else, 4, 6, 0, 6, 23] => 0, [:then, 5, 6, 0, 6, 6] => 1},
127-
[:unless, 6, 8, 0, 10, 3] =>
128-
{[:else, 7, 8, 0, 10, 3] => 0, [:then, 8, 9, 2, 9, 14] => 1},
129-
[:unless, 9, 12, 0, 14, 3] =>
130-
{[:else, 10, 12, 0, 14, 3] => 1, [:then, 11, 13, 2, 13, 14] => 0},
131-
[:unless, 12, 16, 0, 20, 3] =>
132-
{[:else, 13, 19, 2, 19, 13] => 1, [:then, 14, 17, 2, 17, 14] => 0},
133-
[:if, 15, 22, 0, 22, 19] =>
134-
{[:then, 16, 22, 0, 22, 6] => 0, [:else, 17, 22, 0, 22, 19] => 1},
135-
[:if, 18, 23, 0, 25, 3] =>
136-
{[:then, 19, 24, 2, 24, 14] => 1, [:else, 20, 23, 0, 25, 3] => 0},
137-
[:if, 21, 27, 0, 29, 3] =>
138-
{[:then, 22, 28, 2, 28, 14] => 0, [:else, 23, 27, 0, 29, 3] => 1},
139-
[:if, 24, 31, 0, 35, 3] =>
140-
{[:then, 25, 32, 2, 32, 14] => 1, [:else, 26, 34, 2, 34, 13] => 0},
141-
[:if, 27, 42, 0, 47, 8] =>
142-
{[:then, 28, 43, 2, 45, 13] => 0, [:else, 29, 47, 2, 47, 8] => 0},
143-
[:if, 30, 40, 0, 47, 8] =>
144-
{[:then, 31, 41, 2, 41, 25] => 1, [:else, 32, 42, 0, 47, 8] => 0},
145-
[:if, 33, 37, 0, 48, 3] =>
146-
{[:then, 34, 38, 2, 39, 21] => 0, [:else, 35, 40, 0, 47, 8] => 1}
147-
}
148-
}.freeze
149-
150-
COVERAGE_FOR_SINGLE_NOCOV_RB = {
151-
"lines" => [nil, 1, 1, 1, 0, 1, 0, 1, 1, nil, 0, nil, nil, nil],
152-
"branches" => {
153-
[:if, 0, 8, 4, 11, 10] =>
154-
{[:then, 1, 9, 6, 9, 10] => 1, [:else, 2, 11, 6, 11, 10] => 0},
155-
[:if, 3, 6, 4, 11, 10] =>
156-
{[:then, 4, 7, 6, 7, 10] => 0, [:else, 5, 8, 4, 11, 10] => 1},
157-
[:if, 6, 4, 4, 12, 7] =>
158-
{[:then, 7, 5, 6, 5, 10] => 0, [:else, 8, 6, 4, 11, 10] => 1}
159-
}
160-
}.freeze
161-
162-
COVERAGE_FOR_UNEVEN_NOCOV_RB = {
163-
"lines" => [1, 1, nil, 1, 0, 1, 0, nil, 1, 1, nil, nil, 0, nil, nil, nil],
164-
"branches" => {
165-
[:if, 0, 9, 4, 13, 10] =>
166-
{[:then, 1, 10, 6, 10, 10] => 1, [:else, 2, 13, 6, 13, 10] => 0},
167-
[:if, 3, 6, 4, 13, 10] =>
168-
{[:then, 4, 7, 6, 7, 10] => 0, [:else, 5, 9, 4, 13, 10] => 1},
169-
[:if, 6, 4, 4, 14, 7] =>
170-
{[:then, 7, 5, 6, 5, 10] => 0, [:else, 8, 6, 4, 13, 10] => 1}
171-
}
172-
}.freeze
173-
17432
COVERAGE_FOR_SINGLE_LINE = {"lines" => [nil]}.freeze
17533

17634
COVERAGE_FOR_DOUBLE_LINES = {"lines" => [nil, 1]}.freeze
@@ -448,7 +306,7 @@
448306

449307
context "when file with branches" do
450308
subject(:source_file) do
451-
described_class.new(source_fixture("branches.rb"), COVERAGE_FOR_BRANCHES_RB)
309+
described_class.new(source_fixture("branches.rb"), CoverageFixtures::BRANCHES_RB)
452310
end
453311

454312
describe "branch coverage" do
@@ -525,7 +383,7 @@
525383

526384
context "when A file that has inline branches" do
527385
subject(:source_file) do
528-
described_class.new(source_fixture("inline.rb"), COVERAGE_FOR_INLINE)
386+
described_class.new(source_fixture("inline.rb"), CoverageFixtures::INLINE_RB)
529387
end
530388

531389
it "has branches report on 3 lines" do
@@ -548,7 +406,7 @@
548406

549407
context "when a file that is never relevant" do
550408
subject(:source_file) do
551-
described_class.new(source_fixture("never.rb"), COVERAGE_FOR_NEVER_RB)
409+
described_class.new(source_fixture("never.rb"), CoverageFixtures::NEVER_RB)
552410
end
553411

554412
it "has 0.0 covered_strength" do
@@ -647,7 +505,7 @@
647505

648506
context "when a file with more complex skipping" do
649507
subject(:source_file) do
650-
described_class.new(source_fixture("nocov_complex.rb"), COVERAGE_FOR_NOCOV_COMPLEX_RB)
508+
described_class.new(source_fixture("nocov_complex.rb"), CoverageFixtures::NOCOV_COMPLEX_RB)
651509
end
652510

653511
describe "line coverage" do
@@ -691,7 +549,7 @@
691549

692550
context "when a file with nested branches" do
693551
subject(:source_file) do
694-
described_class.new(source_fixture("nested_branches.rb"), COVERAGE_FOR_NESTED_BRANCHES_RB)
552+
described_class.new(source_fixture("nested_branches.rb"), CoverageFixtures::NESTED_BRANCHES_RB)
695553
end
696554

697555
describe "line coverage" do
@@ -715,7 +573,7 @@
715573

716574
context "when a file with case" do
717575
subject(:source_file) do
718-
described_class.new(source_fixture("case.rb"), COVERAGE_FOR_CASE_STATEMENT_RB)
576+
described_class.new(source_fixture("case.rb"), CoverageFixtures::CASE_RB)
719577
end
720578

721579
describe "line coverage" do
@@ -746,7 +604,7 @@
746604

747605
context "when a file with case without else" do
748606
subject(:source_file) do
749-
described_class.new(source_fixture("case_without_else.rb"), COVERAGE_FOR_CASE_WITHOUT_ELSE_STATEMENT_RB)
607+
described_class.new(source_fixture("case_without_else.rb"), CoverageFixtures::CASE_WITHOUT_ELSE_RB)
750608
end
751609

752610
describe "line coverage" do
@@ -781,7 +639,7 @@
781639

782640
context "when a file with if/elsif" do
783641
subject(:source_file) do
784-
described_class.new(source_fixture("elsif.rb"), COVERAGE_FOR_ELSIF_RB)
642+
described_class.new(source_fixture("elsif.rb"), CoverageFixtures::ELSIF_RB)
785643
end
786644

787645
describe "line coverage" do
@@ -807,7 +665,7 @@
807665

808666
context "when the branch tester script" do
809667
subject(:source_file) do
810-
described_class.new(source_fixture("branch_tester_script.rb"), COVERAGE_FOR_BRANCH_TESTER_RB)
668+
described_class.new(source_fixture("branch_tester_script.rb"), CoverageFixtures::BRANCH_TESTER_RB)
811669
end
812670

813671
describe "line coverage" do
@@ -831,7 +689,7 @@
831689

832690
context "when a file using the deprecated # :nocov: directive" do
833691
subject(:source_file) do
834-
described_class.new(source_fixture("single_nocov.rb"), COVERAGE_FOR_SINGLE_NOCOV_RB)
692+
described_class.new(source_fixture("single_nocov.rb"), CoverageFixtures::SINGLE_NOCOV_RB)
835693
end
836694

837695
before { described_class.nocov_warned.clear }
@@ -848,7 +706,7 @@
848706

849707
it "deduplicates the warning for the same file across SourceFile instances" do
850708
capture_stderr { source_file.lines }
851-
another = described_class.new(source_fixture("single_nocov.rb"), COVERAGE_FOR_SINGLE_NOCOV_RB)
709+
another = described_class.new(source_fixture("single_nocov.rb"), CoverageFixtures::SINGLE_NOCOV_RB)
852710
stderr = capture_stderr { another.lines }
853711

854712
expect(stderr).to be_empty
@@ -857,7 +715,7 @@
857715

858716
context "when a file entirely ignored with a single # :nocov:" do
859717
subject(:source_file) do
860-
described_class.new(source_fixture("single_nocov.rb"), COVERAGE_FOR_SINGLE_NOCOV_RB)
718+
described_class.new(source_fixture("single_nocov.rb"), CoverageFixtures::SINGLE_NOCOV_RB)
861719
end
862720

863721
describe "line coverage" do
@@ -890,7 +748,7 @@
890748

891749
context "when a file with an uneven usage of # :nocov:s" do
892750
subject(:source_file) do
893-
described_class.new(source_fixture("uneven_nocovs.rb"), COVERAGE_FOR_UNEVEN_NOCOV_RB)
751+
described_class.new(source_fixture("uneven_nocovs.rb"), CoverageFixtures::UNEVEN_NOCOVS_RB)
894752
end
895753

896754
describe "line coverage" do

spec/support/html_formatter_coverage_fixtures.rb renamed to spec/support/coverage_fixtures.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
# Coverage data hashes that pair with the Ruby fixture files in
4-
# spec/fixtures/html_formatter/. Each constant maps the fixture's filename
5-
# to a coverage hash in the shape `Coverage.result` returns.
6-
module HTMLFormatterCoverageFixtures
4+
# spec/fixtures/. Each constant matches a fixture file and provides a
5+
# coverage hash in the shape `Coverage.result` returns.
6+
module CoverageFixtures
77
BRANCHES_RB = {
88
"lines" => [1, 1, 1, nil, 1, nil, 1, 0, nil, 1, nil, nil, nil],
99
"branches" => {

0 commit comments

Comments
 (0)