simplecov-patched 0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +31 -0
- data/.rspec +3 -0
- data/.rubocop.yml +88 -0
- data/.travis.yml +29 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +435 -0
- data/CONTRIBUTING.md +48 -0
- data/Gemfile +38 -0
- data/MIT-LICENSE +20 -0
- data/README.md +646 -0
- data/Rakefile +41 -0
- data/cucumber.yml +13 -0
- data/doc/alternate-formatters.md +36 -0
- data/doc/commercial-services.md +20 -0
- data/doc/editor-integration.md +13 -0
- data/features/config_autoload.feature +46 -0
- data/features/config_command_name.feature +45 -0
- data/features/config_coverage_dir.feature +33 -0
- data/features/config_deactivate_merging.feature +42 -0
- data/features/config_formatters.feature +77 -0
- data/features/config_merge_timeout.feature +39 -0
- data/features/config_nocov_token.feature +79 -0
- data/features/config_profiles.feature +44 -0
- data/features/config_project_name.feature +27 -0
- data/features/config_styles.feature +121 -0
- data/features/config_tracked_files.feature +29 -0
- data/features/cucumber_basic.feature +29 -0
- data/features/maximum_coverage_drop.feature +89 -0
- data/features/merging_test_unit_and_rspec.feature +44 -0
- data/features/minimum_coverage.feature +59 -0
- data/features/refuse_coverage_drop.feature +95 -0
- data/features/rspec_basic.feature +32 -0
- data/features/rspec_fails_on_initialization.feature +14 -0
- data/features/rspec_groups_and_filters_basic.feature +29 -0
- data/features/rspec_groups_and_filters_complex.feature +37 -0
- data/features/rspec_groups_using_filter_class.feature +41 -0
- data/features/rspec_without_simplecov.feature +20 -0
- data/features/skipping_code_blocks_manually.feature +70 -0
- data/features/step_definitions/html_steps.rb +44 -0
- data/features/step_definitions/simplecov_steps.rb +68 -0
- data/features/step_definitions/transformers.rb +13 -0
- data/features/step_definitions/web_steps.rb +64 -0
- data/features/support/env.rb +50 -0
- data/features/test_unit_basic.feature +34 -0
- data/features/test_unit_groups_and_filters_basic.feature +29 -0
- data/features/test_unit_groups_and_filters_complex.feature +35 -0
- data/features/test_unit_groups_using_filter_class.feature +40 -0
- data/features/test_unit_without_simplecov.feature +20 -0
- data/features/unicode_compatiblity.feature +67 -0
- data/lib/simplecov.rb +189 -0
- data/lib/simplecov/command_guesser.rb +59 -0
- data/lib/simplecov/configuration.rb +307 -0
- data/lib/simplecov/defaults.rb +121 -0
- data/lib/simplecov/exit_codes.rb +8 -0
- data/lib/simplecov/file_list.rb +59 -0
- data/lib/simplecov/filter.rb +54 -0
- data/lib/simplecov/formatter.rb +8 -0
- data/lib/simplecov/formatter/multi_formatter.rb +32 -0
- data/lib/simplecov/formatter/simple_formatter.rb +23 -0
- data/lib/simplecov/jruby_fix.rb +42 -0
- data/lib/simplecov/last_run.rb +24 -0
- data/lib/simplecov/load_global_config.rb +6 -0
- data/lib/simplecov/no_defaults.rb +2 -0
- data/lib/simplecov/profiles.rb +31 -0
- data/lib/simplecov/railtie.rb +7 -0
- data/lib/simplecov/railties/tasks.rake +11 -0
- data/lib/simplecov/raw_coverage.rb +39 -0
- data/lib/simplecov/result.rb +86 -0
- data/lib/simplecov/result_merger.rb +95 -0
- data/lib/simplecov/source_file.rb +196 -0
- data/lib/simplecov/version.rb +25 -0
- data/spec/1_8_fallbacks_spec.rb +31 -0
- data/spec/command_guesser_spec.rb +48 -0
- data/spec/config_loader_spec.rb +14 -0
- data/spec/configuration_spec.rb +35 -0
- data/spec/deleted_source_spec.rb +12 -0
- data/spec/faked_project/Gemfile +6 -0
- data/spec/faked_project/Rakefile +8 -0
- data/spec/faked_project/cucumber.yml +13 -0
- data/spec/faked_project/features/step_definitions/my_steps.rb +22 -0
- data/spec/faked_project/features/support/env.rb +12 -0
- data/spec/faked_project/features/test_stuff.feature +6 -0
- data/spec/faked_project/lib/faked_project.rb +11 -0
- data/spec/faked_project/lib/faked_project/framework_specific.rb +18 -0
- data/spec/faked_project/lib/faked_project/meta_magic.rb +24 -0
- data/spec/faked_project/lib/faked_project/some_class.rb +28 -0
- data/spec/faked_project/lib/faked_project/untested_class.rb +11 -0
- data/spec/faked_project/spec/faked_spec.rb +11 -0
- data/spec/faked_project/spec/forking_spec.rb +8 -0
- data/spec/faked_project/spec/meta_magic_spec.rb +15 -0
- data/spec/faked_project/spec/some_class_spec.rb +13 -0
- data/spec/faked_project/spec/spec_helper.rb +11 -0
- data/spec/faked_project/test/faked_test.rb +11 -0
- data/spec/faked_project/test/meta_magic_test.rb +13 -0
- data/spec/faked_project/test/some_class_test.rb +15 -0
- data/spec/faked_project/test/test_helper.rb +12 -0
- data/spec/file_list_spec.rb +50 -0
- data/spec/filters_spec.rb +98 -0
- data/spec/fixtures/app/controllers/sample_controller.rb +10 -0
- data/spec/fixtures/app/models/user.rb +10 -0
- data/spec/fixtures/deleted_source_sample.rb +15 -0
- data/spec/fixtures/frameworks/rspec_bad.rb +9 -0
- data/spec/fixtures/frameworks/rspec_good.rb +9 -0
- data/spec/fixtures/frameworks/testunit_bad.rb +9 -0
- data/spec/fixtures/frameworks/testunit_good.rb +9 -0
- data/spec/fixtures/iso-8859.rb +3 -0
- data/spec/fixtures/never.rb +2 -0
- data/spec/fixtures/resultset1.rb +4 -0
- data/spec/fixtures/resultset2.rb +4 -0
- data/spec/fixtures/sample.rb +16 -0
- data/spec/fixtures/skipped.rb +4 -0
- data/spec/fixtures/skipped_and_executed.rb +8 -0
- data/spec/fixtures/utf-8.rb +3 -0
- data/spec/helper.rb +26 -0
- data/spec/last_run_spec.rb +48 -0
- data/spec/multi_formatter_spec.rb +20 -0
- data/spec/raw_coverage_spec.rb +92 -0
- data/spec/result_merger_spec.rb +96 -0
- data/spec/result_spec.rb +209 -0
- data/spec/return_codes_spec.rb +34 -0
- data/spec/simplecov_spec.rb +110 -0
- data/spec/source_file_line_spec.rb +155 -0
- data/spec/source_file_spec.rb +141 -0
- data/spec/support/fail_rspec_on_ruby_warning.rb +75 -0
- metadata +320 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
# Make sure that exit codes of tests are propagated properly
|
4
|
+
# See https://github.com/colszowka/simplecov/issues/5
|
5
|
+
describe "return codes" do
|
6
|
+
context "inside fixtures/frameworks" do
|
7
|
+
around do |test|
|
8
|
+
Dir.chdir(File.join(File.dirname(__FILE__), "fixtures", "frameworks")) do
|
9
|
+
FileUtils.rm_rf("./coverage")
|
10
|
+
test.call
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has return code 0 when running testunit_good.rb" do
|
15
|
+
`ruby testunit_good.rb`
|
16
|
+
expect($?.exitstatus).to be_zero
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has return code 0 when running rspec_good.rb" do
|
20
|
+
`rspec rspec_good.rb`
|
21
|
+
expect($?.exitstatus).to be_zero
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has non-0 return code when running testunit_bad.rb" do
|
25
|
+
`ruby testunit_bad.rb`
|
26
|
+
expect($?.exitstatus).not_to be_zero
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has return code 1 when running rspec_bad.rb" do
|
30
|
+
`rspec rspec_bad.rb`
|
31
|
+
expect($?.exitstatus).not_to be_zero
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
if SimpleCov.usable?
|
4
|
+
describe SimpleCov do
|
5
|
+
describe ".result" do
|
6
|
+
before do
|
7
|
+
SimpleCov.clear_result!
|
8
|
+
allow(Coverage).to receive(:result).once.and_return({})
|
9
|
+
allow(SimpleCov).to receive(:add_not_loaded_files).once.and_return({})
|
10
|
+
end
|
11
|
+
|
12
|
+
context "with merging disabled" do
|
13
|
+
before do
|
14
|
+
allow(SimpleCov).to receive(:use_merging).once.and_return(false)
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when not running" do
|
18
|
+
before do
|
19
|
+
allow(SimpleCov).to receive(:running).and_return(false)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns nil" do
|
23
|
+
expect(SimpleCov.result).to be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when running" do
|
28
|
+
before do
|
29
|
+
allow(SimpleCov).to receive(:running).and_return(true, false)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "uses the result from Coverage" do
|
33
|
+
expect(Coverage).to receive(:result).once.and_return({})
|
34
|
+
SimpleCov.result
|
35
|
+
end
|
36
|
+
|
37
|
+
it "adds not-loaded-files" do
|
38
|
+
expect(SimpleCov).to receive(:add_not_loaded_files).once.and_return({})
|
39
|
+
SimpleCov.result
|
40
|
+
end
|
41
|
+
|
42
|
+
it "doesn't store the current coverage" do
|
43
|
+
expect(SimpleCov::ResultMerger).to receive(:store_result).never
|
44
|
+
SimpleCov.result
|
45
|
+
end
|
46
|
+
|
47
|
+
it "doesn't merge the result" do
|
48
|
+
expect(SimpleCov::ResultMerger).to receive(:merged_result).never
|
49
|
+
SimpleCov.result
|
50
|
+
end
|
51
|
+
|
52
|
+
it "caches its result" do
|
53
|
+
result = SimpleCov.result
|
54
|
+
expect(SimpleCov.result).to equal(result)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with merging enabled" do
|
60
|
+
let(:the_merged_result) { double }
|
61
|
+
|
62
|
+
before do
|
63
|
+
allow(SimpleCov).to receive(:use_merging).once.and_return(true)
|
64
|
+
allow(SimpleCov::ResultMerger).to receive(:store_result).once
|
65
|
+
allow(SimpleCov::ResultMerger).to receive(:merged_result).once.and_return(the_merged_result)
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when not running" do
|
69
|
+
before do
|
70
|
+
allow(SimpleCov).to receive(:running).and_return(false)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "merges the result" do
|
74
|
+
expect(SimpleCov.result).to equal(the_merged_result)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when running" do
|
79
|
+
before do
|
80
|
+
allow(SimpleCov).to receive(:running).and_return(true, false)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "uses the result from Coverage" do
|
84
|
+
expect(Coverage).to receive(:result).once.and_return({})
|
85
|
+
SimpleCov.result
|
86
|
+
end
|
87
|
+
|
88
|
+
it "adds not-loaded-files" do
|
89
|
+
expect(SimpleCov).to receive(:add_not_loaded_files).once.and_return({})
|
90
|
+
SimpleCov.result
|
91
|
+
end
|
92
|
+
|
93
|
+
it "stores the current coverage" do
|
94
|
+
expect(SimpleCov::ResultMerger).to receive(:store_result).once
|
95
|
+
SimpleCov.result
|
96
|
+
end
|
97
|
+
|
98
|
+
it "merges the result" do
|
99
|
+
expect(SimpleCov.result).to equal(the_merged_result)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "caches its result" do
|
103
|
+
result = SimpleCov.result
|
104
|
+
expect(SimpleCov.result).to equal(result)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
if SimpleCov.usable?
|
4
|
+
describe SimpleCov::SourceFile::Line do
|
5
|
+
context "a source line" do
|
6
|
+
subject do
|
7
|
+
SimpleCov::SourceFile::Line.new("# the ruby source", 5, 3)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns "# the ruby source" as src' do
|
11
|
+
expect(subject.src).to eq("# the ruby source")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns the same for source as for src" do
|
15
|
+
expect(subject.src).to eq(subject.source)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has line number 5" do
|
19
|
+
expect(subject.line_number).to eq(5)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "has equal line_number, line and number" do
|
23
|
+
expect(subject.line).to eq(subject.line_number)
|
24
|
+
expect(subject.number).to eq(subject.line_number)
|
25
|
+
end
|
26
|
+
|
27
|
+
context "flagged as skipped!" do
|
28
|
+
before do
|
29
|
+
subject.skipped!
|
30
|
+
end
|
31
|
+
it "is not covered" do
|
32
|
+
expect(subject).not_to be_covered
|
33
|
+
end
|
34
|
+
|
35
|
+
it "is skipped" do
|
36
|
+
expect(subject).to be_skipped
|
37
|
+
end
|
38
|
+
|
39
|
+
it "is not missed" do
|
40
|
+
expect(subject).not_to be_missed
|
41
|
+
end
|
42
|
+
|
43
|
+
it "is not never" do
|
44
|
+
expect(subject).not_to be_never
|
45
|
+
end
|
46
|
+
|
47
|
+
it "status is skipped" do
|
48
|
+
expect(subject.status).to eq("skipped")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "A source line with coverage" do
|
54
|
+
subject do
|
55
|
+
SimpleCov::SourceFile::Line.new("# the ruby source", 5, 3)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "has coverage of 3" do
|
59
|
+
expect(subject.coverage).to eq(3)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "is covered" do
|
63
|
+
expect(subject).to be_covered
|
64
|
+
end
|
65
|
+
|
66
|
+
it "is not skipped" do
|
67
|
+
expect(subject).not_to be_skipped
|
68
|
+
end
|
69
|
+
|
70
|
+
it "is not missed" do
|
71
|
+
expect(subject).not_to be_missed
|
72
|
+
end
|
73
|
+
|
74
|
+
it "is not never" do
|
75
|
+
expect(subject).not_to be_never
|
76
|
+
end
|
77
|
+
|
78
|
+
it "status is covered" do
|
79
|
+
expect(subject.status).to eq("covered")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "A source line without coverage" do
|
84
|
+
subject do
|
85
|
+
SimpleCov::SourceFile::Line.new("# the ruby source", 5, 0)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "has coverage of 0" do
|
89
|
+
expect(subject.coverage).to be_zero
|
90
|
+
end
|
91
|
+
|
92
|
+
it "is not covered" do
|
93
|
+
expect(subject).not_to be_covered
|
94
|
+
end
|
95
|
+
|
96
|
+
it "is not skipped" do
|
97
|
+
expect(subject).not_to be_skipped
|
98
|
+
end
|
99
|
+
|
100
|
+
it "is missed" do
|
101
|
+
expect(subject).to be_missed
|
102
|
+
end
|
103
|
+
|
104
|
+
it "is not never" do
|
105
|
+
expect(subject).not_to be_never
|
106
|
+
end
|
107
|
+
|
108
|
+
it "status is missed" do
|
109
|
+
expect(subject.status).to eq("missed")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "A source line with no code" do
|
114
|
+
subject do
|
115
|
+
SimpleCov::SourceFile::Line.new("# the ruby source", 5, nil)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "has nil coverage" do
|
119
|
+
expect(subject.coverage).to be_nil
|
120
|
+
end
|
121
|
+
|
122
|
+
it "is not covered" do
|
123
|
+
expect(subject).not_to be_covered
|
124
|
+
end
|
125
|
+
|
126
|
+
it "is not skipped" do
|
127
|
+
expect(subject).not_to be_skipped
|
128
|
+
end
|
129
|
+
|
130
|
+
it "is not missed" do
|
131
|
+
expect(subject).not_to be_missed
|
132
|
+
end
|
133
|
+
|
134
|
+
it "is never" do
|
135
|
+
expect(subject).to be_never
|
136
|
+
end
|
137
|
+
|
138
|
+
it "status is never" do
|
139
|
+
expect(subject.status).to eq("never")
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it "raises ArgumentError when initialized with invalid src" do
|
144
|
+
expect { SimpleCov::SourceFile::Line.new(:symbol, 5, 3) }.to raise_error(ArgumentError)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "raises ArgumentError when initialized with invalid line_number" do
|
148
|
+
expect { SimpleCov::SourceFile::Line.new("some source", "five", 3) }.to raise_error(ArgumentError)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "raises ArgumentError when initialized with invalid coverage" do
|
152
|
+
expect { SimpleCov::SourceFile::Line.new("some source", 5, "three") }.to raise_error(ArgumentError)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
if SimpleCov.usable?
|
4
|
+
describe SimpleCov::SourceFile do
|
5
|
+
COVERAGE_FOR_SAMPLE_RB = [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, nil, nil, nil, nil, nil].freeze
|
6
|
+
context "a source file initialized with some coverage data" do
|
7
|
+
subject do
|
8
|
+
SimpleCov::SourceFile.new(source_fixture("sample.rb"), COVERAGE_FOR_SAMPLE_RB)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a filename" do
|
12
|
+
expect(subject.filename).not_to be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has source equal to src" do
|
16
|
+
expect(subject.src).to eq(subject.source)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has source_lines equal to lines" do
|
20
|
+
expect(subject.lines).to eq(subject.source_lines)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has 16 source lines" do
|
24
|
+
expect(subject.lines.count).to eq(16)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has all source lines of type SimpleCov::SourceFile::Line" do
|
28
|
+
subject.lines.each do |line|
|
29
|
+
expect(line).to be_a SimpleCov::SourceFile::Line
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "has 'class Foo' as line(2).source" do
|
34
|
+
expect(subject.line(2).source).to eq("class Foo\n")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns lines number 2, 3, 4, 7 for covered_lines" do
|
38
|
+
expect(subject.covered_lines.map(&:line)).to eq([2, 3, 4, 7])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns lines number 8 for missed_lines" do
|
42
|
+
expect(subject.missed_lines.map(&:line)).to eq([8])
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns lines number 1, 5, 6, 9, 10, 16 for never_lines" do
|
46
|
+
expect(subject.never_lines.map(&:line)).to eq([1, 5, 6, 9, 10, 16])
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns line numbers 11, 12, 13, 14, 15 for skipped_lines" do
|
50
|
+
expect(subject.skipped_lines.map(&:line)).to eq([11, 12, 13, 14, 15])
|
51
|
+
end
|
52
|
+
|
53
|
+
it "has 80% covered_percent" do
|
54
|
+
expect(subject.covered_percent).to eq(80.0)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "simulating potential Ruby 1.9 defect -- see Issue #56" do
|
59
|
+
subject do
|
60
|
+
SimpleCov::SourceFile.new(source_fixture("sample.rb"), COVERAGE_FOR_SAMPLE_RB + [nil])
|
61
|
+
end
|
62
|
+
|
63
|
+
it "has 16 source lines regardless of extra data in coverage array" do
|
64
|
+
# Do not litter test output with known warning
|
65
|
+
capture_stderr { expect(subject.lines.count).to eq(16) }
|
66
|
+
end
|
67
|
+
|
68
|
+
it "prints a warning to stderr if coverage array contains more data than lines in the file" do
|
69
|
+
captured_output = capture_stderr do
|
70
|
+
subject.lines
|
71
|
+
end
|
72
|
+
|
73
|
+
expect(captured_output).to match(/^Warning: coverage data provided/)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "a file that is never relevant" do
|
78
|
+
COVERAGE_FOR_NEVER_RB = [nil, nil].freeze
|
79
|
+
|
80
|
+
subject do
|
81
|
+
SimpleCov::SourceFile.new(source_fixture("never.rb"), COVERAGE_FOR_NEVER_RB)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "has 0.0 covered_strength" do
|
85
|
+
expect(subject.covered_strength).to eq 0.0
|
86
|
+
end
|
87
|
+
|
88
|
+
it "has 0.0 covered_percent" do
|
89
|
+
expect(subject.covered_percent).to eq 100.0
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "a file where nothing is ever executed mixed with skipping #563" do
|
94
|
+
COVERAGE_FOR_SKIPPED_RB = [nil, nil, nil, nil].freeze
|
95
|
+
|
96
|
+
subject do
|
97
|
+
SimpleCov::SourceFile.new(source_fixture("skipped.rb"), COVERAGE_FOR_SKIPPED_RB)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "has 0.0 covered_strength" do
|
101
|
+
expect(subject.covered_strength).to eq 0.0
|
102
|
+
end
|
103
|
+
|
104
|
+
it "has 0.0 covered_percent" do
|
105
|
+
expect(subject.covered_percent).to eq 0.0
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "a file where everything is skipped and missed #563" do
|
110
|
+
COVERAGE_FOR_SKIPPED_RB_2 = [nil, nil, 0, nil].freeze
|
111
|
+
|
112
|
+
subject do
|
113
|
+
SimpleCov::SourceFile.new(source_fixture("skipped.rb"), COVERAGE_FOR_SKIPPED_RB_2)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "has 0.0 covered_strength" do
|
117
|
+
expect(subject.covered_strength).to eq 0.0
|
118
|
+
end
|
119
|
+
|
120
|
+
it "has 0.0 covered_percent" do
|
121
|
+
expect(subject.covered_percent).to eq 0.0
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "a file where everything is skipped/irrelevamt but executed #563" do
|
126
|
+
COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB = [nil, nil, 1, 1, 0, nil, nil, nil].freeze
|
127
|
+
|
128
|
+
subject do
|
129
|
+
SimpleCov::SourceFile.new(source_fixture("skipped_and_executed.rb"), COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "has 0.0 covered_strength" do
|
133
|
+
expect(subject.covered_strength).to eq 0.0
|
134
|
+
end
|
135
|
+
|
136
|
+
it "has 0.0 covered_percent" do
|
137
|
+
expect(subject.covered_percent).to eq 0.0
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Borrowed and heavily adjusted from:
|
2
|
+
# https://github.com/metricfu/metric_fu/blob/master/spec/capture_warnings.rb
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
class FailOnWarnings
|
6
|
+
def initialize
|
7
|
+
@stderr_stream = StringIO.new
|
8
|
+
@app_root = Dir.pwd
|
9
|
+
end
|
10
|
+
|
11
|
+
def collect_warnings
|
12
|
+
$stderr = @stderr_stream
|
13
|
+
$VERBOSE = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def process_warnings
|
17
|
+
lines = close_stream
|
18
|
+
app_warnings, other_warnings = split_lines(lines)
|
19
|
+
|
20
|
+
print_own_warnings(app_warnings) if app_warnings.any?
|
21
|
+
write_other_warnings_to_tmp(other_warnings) if other_warnings.any?
|
22
|
+
fail_script(app_warnings) if app_warnings.any?
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def close_stream
|
28
|
+
$stderr = STDERR
|
29
|
+
|
30
|
+
@stderr_stream.rewind
|
31
|
+
lines = @stderr_stream.read.split("\n")
|
32
|
+
lines.uniq!
|
33
|
+
@stderr_stream.close
|
34
|
+
lines
|
35
|
+
end
|
36
|
+
|
37
|
+
def split_lines(lines)
|
38
|
+
lines.partition { |line| line.include?(@app_root) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def print_own_warnings(app_warnings)
|
42
|
+
puts ""
|
43
|
+
puts ""
|
44
|
+
puts <<-WARNINGS
|
45
|
+
#{'-' * 30} app warnings: #{'-' * 30}
|
46
|
+
#{app_warnings.join("\n")}
|
47
|
+
#{'-' * 75}
|
48
|
+
WARNINGS
|
49
|
+
end
|
50
|
+
|
51
|
+
def write_other_warnings_to_tmp(other_warnings)
|
52
|
+
output_dir = File.join(@app_root, "tmp")
|
53
|
+
FileUtils.mkdir_p(output_dir)
|
54
|
+
output_file = File.join(output_dir, "warnings.txt")
|
55
|
+
File.open(output_file, "w") do |file|
|
56
|
+
file.write(other_warnings.join("\n") << "\n")
|
57
|
+
end
|
58
|
+
puts
|
59
|
+
puts "Non-app warnings written to tmp/warnings.txt"
|
60
|
+
puts
|
61
|
+
end
|
62
|
+
|
63
|
+
def fail_script(app_warnings)
|
64
|
+
abort "Failing build due to app warnings: #{app_warnings.inspect}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
warning_collector = FailOnWarnings.new
|
69
|
+
warning_collector.collect_warnings
|
70
|
+
|
71
|
+
RSpec.configure do |config|
|
72
|
+
config.after(:suite) do
|
73
|
+
warning_collector.process_warnings
|
74
|
+
end
|
75
|
+
end
|