simplecov 0.15.1 → 0.18.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +74 -1
- data/CODE_OF_CONDUCT.md +76 -0
- data/CONTRIBUTING.md +12 -9
- data/ISSUE_TEMPLATE.md +23 -0
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/README.md +205 -104
- data/doc/alternate-formatters.md +20 -0
- data/lib/simplecov.rb +246 -52
- data/lib/simplecov/combine.rb +30 -0
- data/lib/simplecov/combine/branches_combiner.rb +32 -0
- data/lib/simplecov/combine/files_combiner.rb +25 -0
- data/lib/simplecov/combine/lines_combiner.rb +43 -0
- data/lib/simplecov/combine/results_combiner.rb +60 -0
- data/lib/simplecov/command_guesser.rb +8 -3
- data/lib/simplecov/configuration.rb +79 -8
- data/lib/simplecov/defaults.rb +12 -81
- data/lib/simplecov/exit_codes.rb +2 -0
- data/lib/simplecov/file_list.rb +32 -3
- data/lib/simplecov/filter.rb +5 -2
- data/lib/simplecov/formatter.rb +2 -0
- data/lib/simplecov/formatter/multi_formatter.rb +4 -2
- data/lib/simplecov/formatter/simple_formatter.rb +6 -4
- data/lib/simplecov/last_run.rb +4 -0
- data/lib/simplecov/lines_classifier.rb +21 -5
- data/lib/simplecov/load_global_config.rb +2 -0
- data/lib/simplecov/no_defaults.rb +2 -0
- data/lib/simplecov/profiles.rb +11 -7
- data/lib/simplecov/profiles/bundler_filter.rb +5 -0
- data/lib/simplecov/profiles/hidden_filter.rb +5 -0
- data/lib/simplecov/profiles/rails.rb +18 -0
- data/lib/simplecov/profiles/root_filter.rb +10 -0
- data/lib/simplecov/profiles/test_frameworks.rb +8 -0
- data/lib/simplecov/result.rb +23 -4
- data/lib/simplecov/result_adapter.rb +30 -0
- data/lib/simplecov/result_merger.rb +14 -11
- data/lib/simplecov/simulate_coverage.rb +29 -0
- data/lib/simplecov/source_file.rb +222 -110
- data/lib/simplecov/source_file/branch.rb +106 -0
- data/lib/simplecov/source_file/line.rb +72 -0
- data/lib/simplecov/useless_results_remover.rb +16 -0
- data/lib/simplecov/version.rb +3 -1
- metadata +44 -162
- data/.gitignore +0 -31
- data/.rspec +0 -3
- data/.rubocop.yml +0 -88
- data/.travis.yml +0 -29
- data/.yardopts +0 -1
- data/Gemfile +0 -38
- data/Rakefile +0 -39
- data/cucumber.yml +0 -13
- data/features/config_autoload.feature +0 -46
- data/features/config_command_name.feature +0 -45
- data/features/config_coverage_dir.feature +0 -33
- data/features/config_deactivate_merging.feature +0 -42
- data/features/config_formatters.feature +0 -77
- data/features/config_merge_timeout.feature +0 -39
- data/features/config_nocov_token.feature +0 -79
- data/features/config_profiles.feature +0 -44
- data/features/config_project_name.feature +0 -27
- data/features/config_styles.feature +0 -121
- data/features/config_tracked_files.feature +0 -29
- data/features/config_tracked_files_relevant_lines.feature +0 -31
- data/features/cucumber_basic.feature +0 -29
- data/features/maximum_coverage_drop.feature +0 -89
- data/features/merging_test_unit_and_rspec.feature +0 -44
- data/features/minimum_coverage.feature +0 -59
- data/features/refuse_coverage_drop.feature +0 -95
- data/features/rspec_basic.feature +0 -32
- data/features/rspec_fails_on_initialization.feature +0 -14
- data/features/rspec_groups_and_filters_basic.feature +0 -29
- data/features/rspec_groups_and_filters_complex.feature +0 -37
- data/features/rspec_groups_using_filter_class.feature +0 -41
- data/features/rspec_without_simplecov.feature +0 -20
- data/features/skipping_code_blocks_manually.feature +0 -70
- data/features/step_definitions/html_steps.rb +0 -44
- data/features/step_definitions/simplecov_steps.rb +0 -68
- data/features/step_definitions/transformers.rb +0 -13
- data/features/step_definitions/web_steps.rb +0 -64
- data/features/support/aruba_freedom_patch.rb +0 -53
- data/features/support/env.rb +0 -50
- data/features/test_unit_basic.feature +0 -34
- data/features/test_unit_groups_and_filters_basic.feature +0 -29
- data/features/test_unit_groups_and_filters_complex.feature +0 -35
- data/features/test_unit_groups_using_filter_class.feature +0 -40
- data/features/test_unit_without_simplecov.feature +0 -20
- data/features/unicode_compatiblity.feature +0 -67
- data/lib/simplecov/jruby_fix.rb +0 -42
- data/lib/simplecov/railtie.rb +0 -7
- data/lib/simplecov/railties/tasks.rake +0 -11
- data/lib/simplecov/raw_coverage.rb +0 -39
- data/simplecov.gemspec +0 -27
- data/spec/1_8_fallbacks_spec.rb +0 -31
- data/spec/command_guesser_spec.rb +0 -48
- data/spec/config_loader_spec.rb +0 -14
- data/spec/configuration_spec.rb +0 -35
- data/spec/defaults_spec.rb +0 -41
- data/spec/deleted_source_spec.rb +0 -12
- data/spec/faked_project/Gemfile +0 -6
- data/spec/faked_project/Rakefile +0 -8
- data/spec/faked_project/cucumber.yml +0 -13
- data/spec/faked_project/features/step_definitions/my_steps.rb +0 -22
- data/spec/faked_project/features/support/env.rb +0 -12
- data/spec/faked_project/features/test_stuff.feature +0 -6
- data/spec/faked_project/lib/faked_project.rb +0 -11
- data/spec/faked_project/lib/faked_project/framework_specific.rb +0 -18
- data/spec/faked_project/lib/faked_project/meta_magic.rb +0 -24
- data/spec/faked_project/lib/faked_project/some_class.rb +0 -28
- data/spec/faked_project/lib/faked_project/untested_class.rb +0 -11
- data/spec/faked_project/spec/faked_spec.rb +0 -11
- data/spec/faked_project/spec/forking_spec.rb +0 -8
- data/spec/faked_project/spec/meta_magic_spec.rb +0 -15
- data/spec/faked_project/spec/some_class_spec.rb +0 -13
- data/spec/faked_project/spec/spec_helper.rb +0 -11
- data/spec/faked_project/test/faked_test.rb +0 -11
- data/spec/faked_project/test/meta_magic_test.rb +0 -13
- data/spec/faked_project/test/some_class_test.rb +0 -15
- data/spec/faked_project/test/test_helper.rb +0 -12
- data/spec/file_list_spec.rb +0 -50
- data/spec/filters_spec.rb +0 -202
- data/spec/fixtures/app/controllers/sample_controller.rb +0 -10
- data/spec/fixtures/app/models/user.rb +0 -10
- data/spec/fixtures/deleted_source_sample.rb +0 -15
- data/spec/fixtures/frameworks/rspec_bad.rb +0 -9
- data/spec/fixtures/frameworks/rspec_good.rb +0 -9
- data/spec/fixtures/frameworks/testunit_bad.rb +0 -9
- data/spec/fixtures/frameworks/testunit_good.rb +0 -9
- data/spec/fixtures/iso-8859.rb +0 -3
- data/spec/fixtures/never.rb +0 -2
- data/spec/fixtures/resultset1.rb +0 -4
- data/spec/fixtures/resultset2.rb +0 -4
- data/spec/fixtures/sample.rb +0 -16
- data/spec/fixtures/skipped.rb +0 -4
- data/spec/fixtures/skipped_and_executed.rb +0 -8
- data/spec/fixtures/utf-8.rb +0 -3
- data/spec/helper.rb +0 -26
- data/spec/last_run_spec.rb +0 -48
- data/spec/lines_classifier_spec.rb +0 -103
- data/spec/multi_formatter_spec.rb +0 -20
- data/spec/raw_coverage_spec.rb +0 -92
- data/spec/result_merger_spec.rb +0 -171
- data/spec/result_spec.rb +0 -209
- data/spec/return_codes_spec.rb +0 -34
- data/spec/simplecov_spec.rb +0 -109
- data/spec/source_file_line_spec.rb +0 -155
- data/spec/source_file_spec.rb +0 -145
- data/spec/support/fail_rspec_on_ruby_warning.rb +0 -75
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
module Combine
|
5
|
+
#
|
6
|
+
# Handle combining two coverage results for same file
|
7
|
+
#
|
8
|
+
# Should be called through `SimpleCov.combine`.
|
9
|
+
module FilesCombiner
|
10
|
+
module_function
|
11
|
+
|
12
|
+
#
|
13
|
+
# Combines the results for 2 coverages of a file.
|
14
|
+
#
|
15
|
+
# @return [Hash]
|
16
|
+
#
|
17
|
+
def combine(coverage_a, coverage_b)
|
18
|
+
{
|
19
|
+
:lines => Combine.combine(LinesCombiner, coverage_a[:lines], coverage_b[:lines]),
|
20
|
+
:branches => Combine.combine(BranchesCombiner, coverage_a[:branches], coverage_b[:branches])
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
module Combine
|
5
|
+
#
|
6
|
+
# Combine two different lines coverage results on same file
|
7
|
+
#
|
8
|
+
# Should be called through `SimpleCov.combine`.
|
9
|
+
module LinesCombiner
|
10
|
+
module_function
|
11
|
+
|
12
|
+
def combine(coverage_a, coverage_b)
|
13
|
+
coverage_a
|
14
|
+
.zip(coverage_b)
|
15
|
+
.map do |coverage_a_val, coverage_b_val|
|
16
|
+
merge_line_coverage(coverage_a_val, coverage_b_val)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return depends on coverage in a specific line
|
21
|
+
#
|
22
|
+
# @param [Integer || nil] first_val
|
23
|
+
# @param [Integer || nil] second_val
|
24
|
+
#
|
25
|
+
# Logic:
|
26
|
+
#
|
27
|
+
# => nil + 0 = nil
|
28
|
+
# => nil + nil = nil
|
29
|
+
# => int + int = int
|
30
|
+
#
|
31
|
+
# @return [Integer || nil]
|
32
|
+
def merge_line_coverage(first_val, second_val)
|
33
|
+
sum = first_val.to_i + second_val.to_i
|
34
|
+
|
35
|
+
if sum.zero? && (first_val.nil? || second_val.nil?)
|
36
|
+
nil
|
37
|
+
else
|
38
|
+
sum
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
module Combine
|
5
|
+
# There might be reports from different kinds of tests,
|
6
|
+
# e.g. RSpec and Cucumber. We need to combine their results
|
7
|
+
# into unified one. This class does that.
|
8
|
+
# To unite the results on file basis, it leverages
|
9
|
+
# the combine of lines and branches inside each file within given results.
|
10
|
+
module ResultsCombiner
|
11
|
+
module_function
|
12
|
+
|
13
|
+
#
|
14
|
+
# Combine process explanation
|
15
|
+
# => ResultCombiner: define all present files between results and start combine on file level.
|
16
|
+
# ==> FileCombiner: collect result of next combine levels lines and branches.
|
17
|
+
# ===> LinesCombiner: combine lines results.
|
18
|
+
# ===> BranchesCombiner: combine branches results.
|
19
|
+
#
|
20
|
+
# @return [Hash]
|
21
|
+
#
|
22
|
+
def combine(*results)
|
23
|
+
results.reduce({}) do |result, next_result|
|
24
|
+
combine_result_sets(result, next_result)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Manage combining results on files level
|
30
|
+
#
|
31
|
+
# @param [Hash] result_a
|
32
|
+
# @param [Hash] result_b
|
33
|
+
#
|
34
|
+
# @return [Hash]
|
35
|
+
#
|
36
|
+
def combine_result_sets(result_a, result_b)
|
37
|
+
results_files = result_a.keys | result_b.keys
|
38
|
+
|
39
|
+
results_files.each_with_object({}) do |file_name, combined_results|
|
40
|
+
combined_results[file_name] = combine_file_coverage(
|
41
|
+
result_a[file_name],
|
42
|
+
result_b[file_name]
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Combine two files coverage results
|
49
|
+
#
|
50
|
+
# @param [Hash] coverage_a
|
51
|
+
# @param [Hash] coverage_b
|
52
|
+
#
|
53
|
+
# @return [Hash]
|
54
|
+
#
|
55
|
+
def combine_file_coverage(coverage_a, coverage_b)
|
56
|
+
Combine.combine(Combine::FilesCombiner, coverage_a, coverage_b)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
4
3
|
module SimpleCov
|
4
|
+
#
|
5
|
+
# Helper that tries to find out what test suite is running (for SimpleCov.command_name)
|
6
|
+
#
|
5
7
|
module CommandGuesser
|
6
8
|
class << self
|
7
9
|
# Storage for the original command line call that invoked the test suite.
|
@@ -20,6 +22,7 @@ module SimpleCov
|
|
20
22
|
def from_env
|
21
23
|
# If being run from inside parallel_tests set the command name according to the process number
|
22
24
|
return unless ENV["PARALLEL_TEST_GROUPS"] && ENV["TEST_ENV_NUMBER"]
|
25
|
+
|
23
26
|
number = ENV["TEST_ENV_NUMBER"]
|
24
27
|
number = "1" if number.empty?
|
25
28
|
"(#{number}/#{ENV['PARALLEL_TEST_GROUPS']})"
|
@@ -46,6 +49,8 @@ module SimpleCov
|
|
46
49
|
"RSpec"
|
47
50
|
elsif defined?(Test::Unit)
|
48
51
|
"Unit Tests"
|
52
|
+
elsif defined?(Minitest)
|
53
|
+
"Minitest"
|
49
54
|
elsif defined?(MiniTest)
|
50
55
|
"MiniTest"
|
51
56
|
else
|
@@ -1,14 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "fileutils"
|
2
4
|
require "docile"
|
3
5
|
require "simplecov/formatter/multi_formatter"
|
4
|
-
|
5
|
-
# Bundles the configuration options used for SimpleCov. All methods
|
6
|
-
# defined here are usable from SimpleCov directly. Please check out
|
7
|
-
# SimpleCov documentation for further info.
|
8
|
-
#
|
6
|
+
|
9
7
|
module SimpleCov
|
10
|
-
|
11
|
-
|
8
|
+
#
|
9
|
+
# Bundles the configuration options used for SimpleCov. All methods
|
10
|
+
# defined here are usable from SimpleCov directly. Please check out
|
11
|
+
# SimpleCov documentation for further info.
|
12
|
+
#
|
13
|
+
module Configuration # rubocop:disable Metrics/ModuleLength
|
14
|
+
attr_writer :filters, :groups, :formatter, :print_error_status
|
12
15
|
|
13
16
|
#
|
14
17
|
# The root for the project. This defaults to the
|
@@ -18,6 +21,7 @@ module SimpleCov
|
|
18
21
|
#
|
19
22
|
def root(root = nil)
|
20
23
|
return @root if defined?(@root) && root.nil?
|
24
|
+
|
21
25
|
@root = File.expand_path(root || Dir.getwd)
|
22
26
|
end
|
23
27
|
|
@@ -28,6 +32,7 @@ module SimpleCov
|
|
28
32
|
#
|
29
33
|
def coverage_dir(dir = nil)
|
30
34
|
return @coverage_dir if defined?(@coverage_dir) && dir.nil?
|
35
|
+
|
31
36
|
@coverage_path = nil # invalidate cache
|
32
37
|
@coverage_dir = (dir || "coverage")
|
33
38
|
end
|
@@ -91,8 +96,10 @@ module SimpleCov
|
|
91
96
|
#
|
92
97
|
def formatter(formatter = nil)
|
93
98
|
return @formatter if defined?(@formatter) && formatter.nil?
|
99
|
+
|
94
100
|
@formatter = formatter
|
95
101
|
raise "No formatter configured. Please specify a formatter using SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter" unless @formatter
|
102
|
+
|
96
103
|
@formatter
|
97
104
|
end
|
98
105
|
|
@@ -114,6 +121,14 @@ module SimpleCov
|
|
114
121
|
end
|
115
122
|
end
|
116
123
|
|
124
|
+
#
|
125
|
+
# Whether we should print non-success status codes. This can be
|
126
|
+
# configured with the #print_error_status= method.
|
127
|
+
#
|
128
|
+
def print_error_status
|
129
|
+
defined?(@print_error_status) ? @print_error_status : true
|
130
|
+
end
|
131
|
+
|
117
132
|
#
|
118
133
|
# Certain code blocks (i.e. Ruby-implementation specific code) can be excluded from
|
119
134
|
# the coverage metrics by wrapping it inside # :nocov: comment blocks. The nocov token
|
@@ -123,6 +138,7 @@ module SimpleCov
|
|
123
138
|
#
|
124
139
|
def nocov_token(nocov_token = nil)
|
125
140
|
return @nocov_token if defined?(@nocov_token) && nocov_token.nil?
|
141
|
+
|
126
142
|
@nocov_token = (nocov_token || "nocov")
|
127
143
|
end
|
128
144
|
alias skip_token nocov_token
|
@@ -158,7 +174,6 @@ module SimpleCov
|
|
158
174
|
# options at once.
|
159
175
|
#
|
160
176
|
def configure(&block)
|
161
|
-
return false unless SimpleCov.usable?
|
162
177
|
Docile.dsl_eval(self, &block)
|
163
178
|
end
|
164
179
|
|
@@ -176,6 +191,7 @@ module SimpleCov
|
|
176
191
|
#
|
177
192
|
def at_exit(&block)
|
178
193
|
return proc {} unless running || block_given?
|
194
|
+
|
179
195
|
@at_exit = block if block_given?
|
180
196
|
@at_exit ||= proc { SimpleCov.result.format! }
|
181
197
|
end
|
@@ -186,6 +202,7 @@ module SimpleCov
|
|
186
202
|
#
|
187
203
|
def project_name(new_name = nil)
|
188
204
|
return @project_name if defined?(@project_name) && @project_name && new_name.nil?
|
205
|
+
|
189
206
|
@project_name = new_name if new_name.is_a?(String)
|
190
207
|
@project_name ||= File.basename(root.split("/").last).capitalize.tr("_", " ")
|
191
208
|
end
|
@@ -223,6 +240,7 @@ module SimpleCov
|
|
223
240
|
# Default is 0% (disabled)
|
224
241
|
#
|
225
242
|
def minimum_coverage(coverage = nil)
|
243
|
+
minimum_possible_coverage_exceeded("minimum_coverage") if coverage && coverage > 100
|
226
244
|
@minimum_coverage ||= (coverage || 0).to_f.round(2)
|
227
245
|
end
|
228
246
|
|
@@ -244,6 +262,7 @@ module SimpleCov
|
|
244
262
|
# Default is 0% (disabled)
|
245
263
|
#
|
246
264
|
def minimum_coverage_by_file(coverage = nil)
|
265
|
+
minimum_possible_coverage_exceeded("minimum_coverage_by_file") if coverage && coverage > 100
|
247
266
|
@minimum_coverage_by_file ||= (coverage || 0).to_f.round(2)
|
248
267
|
end
|
249
268
|
|
@@ -285,8 +304,60 @@ module SimpleCov
|
|
285
304
|
groups[group_name] = parse_filter(filter_argument, &filter_proc)
|
286
305
|
end
|
287
306
|
|
307
|
+
SUPPORTED_COVERAGE_CRITERIA = %i[line branch].freeze
|
308
|
+
DEFAULT_COVERAGE_CRITERION = :line
|
309
|
+
#
|
310
|
+
# Define which coverage criterion should be evaluated.
|
311
|
+
#
|
312
|
+
# Possible coverage criteria:
|
313
|
+
# * :line - coverage based on lines aka has this line been executed?
|
314
|
+
# * :branch - coverage based on branches aka has this branch (think conditions) been executed?
|
315
|
+
#
|
316
|
+
# If not set the default is is `:line`
|
317
|
+
#
|
318
|
+
# @param [Symbol] criterion
|
319
|
+
#
|
320
|
+
def coverage_criterion(criterion = nil)
|
321
|
+
return @coverage_criterion ||= DEFAULT_COVERAGE_CRITERION unless criterion
|
322
|
+
|
323
|
+
raise_if_criterion_unsupported(criterion)
|
324
|
+
|
325
|
+
@coverage_criterion = criterion
|
326
|
+
end
|
327
|
+
|
328
|
+
def enable_coverage(criterion)
|
329
|
+
raise_if_criterion_unsupported(criterion)
|
330
|
+
|
331
|
+
coverage_criteria << criterion
|
332
|
+
end
|
333
|
+
|
334
|
+
def coverage_criteria
|
335
|
+
@coverage_criteria ||= Set[DEFAULT_COVERAGE_CRITERION]
|
336
|
+
end
|
337
|
+
|
338
|
+
def branch_coverage?
|
339
|
+
branch_coverage_supported? && coverage_criteria.member?(:branch)
|
340
|
+
end
|
341
|
+
|
342
|
+
def branch_coverage_supported?
|
343
|
+
require "coverage"
|
344
|
+
!Coverage.method(:start).arity.zero?
|
345
|
+
end
|
346
|
+
|
288
347
|
private
|
289
348
|
|
349
|
+
def raise_if_criterion_unsupported(criterion)
|
350
|
+
raise_criterion_unsupported(criterion) unless SUPPORTED_COVERAGE_CRITERIA.member?(criterion)
|
351
|
+
end
|
352
|
+
|
353
|
+
def raise_criterion_unsupported(criterion)
|
354
|
+
raise "Unsupported coverage criterion #{criterion}, supported values are #{SUPPORTED_COVERAGE_CRITERIA}"
|
355
|
+
end
|
356
|
+
|
357
|
+
def minimum_possible_coverage_exceeded(coverage_option)
|
358
|
+
warn "The coverage you set for #{coverage_option} is greater than 100%"
|
359
|
+
end
|
360
|
+
|
290
361
|
#
|
291
362
|
# The actual filter processor. Not meant for direct use
|
292
363
|
#
|
data/lib/simplecov/defaults.rb
CHANGED
@@ -1,48 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Load default formatter gem
|
2
4
|
require "simplecov-html"
|
3
5
|
require "pathname"
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
root_filter ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/io
|
10
|
-
src.filename !~ root_filter
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
SimpleCov.profiles.define "test_frameworks" do
|
15
|
-
add_filter "/test/"
|
16
|
-
add_filter "/features/"
|
17
|
-
add_filter "/spec/"
|
18
|
-
add_filter "/autotest/"
|
19
|
-
end
|
20
|
-
|
21
|
-
SimpleCov.profiles.define "bundler_filter" do
|
22
|
-
add_filter "/vendor/bundle/"
|
23
|
-
end
|
24
|
-
|
25
|
-
SimpleCov.profiles.define "rails" do
|
26
|
-
load_profile "test_frameworks"
|
27
|
-
|
28
|
-
add_filter %r{^/config/}
|
29
|
-
add_filter %r{^/db/}
|
30
|
-
|
31
|
-
add_group "Controllers", "app/controllers"
|
32
|
-
add_group "Channels", "app/channels" if defined?(ActionCable)
|
33
|
-
add_group "Models", "app/models"
|
34
|
-
add_group "Mailers", "app/mailers"
|
35
|
-
add_group "Helpers", "app/helpers"
|
36
|
-
add_group "Jobs", %w[app/jobs app/workers]
|
37
|
-
add_group "Libraries", "lib"
|
38
|
-
|
39
|
-
track_files "{app,lib}/**/*.rb"
|
40
|
-
end
|
6
|
+
require "simplecov/profiles/root_filter"
|
7
|
+
require "simplecov/profiles/test_frameworks"
|
8
|
+
require "simplecov/profiles/bundler_filter"
|
9
|
+
require "simplecov/profiles/hidden_filter"
|
10
|
+
require "simplecov/profiles/rails"
|
41
11
|
|
42
12
|
# Default configuration
|
43
13
|
SimpleCov.configure do
|
44
14
|
formatter SimpleCov::Formatter::HTMLFormatter
|
45
15
|
load_profile "bundler_filter"
|
16
|
+
load_profile "hidden_filter"
|
46
17
|
# Exclude files outside of SimpleCov.root
|
47
18
|
load_profile "root_filter"
|
48
19
|
end
|
@@ -50,52 +21,12 @@ end
|
|
50
21
|
# Gotta stash this a-s-a-p, see the CommandGuesser class and i.e. #110 for further info
|
51
22
|
SimpleCov::CommandGuesser.original_run_command = "#{$PROGRAM_NAME} #{ARGV.join(' ')}"
|
52
23
|
|
53
|
-
at_exit do
|
24
|
+
at_exit do
|
54
25
|
# If we are in a different process than called start, don't interfere.
|
55
26
|
next if SimpleCov.pid != Process.pid
|
56
27
|
|
57
|
-
|
58
|
-
|
59
|
-
# otherwise set a non-zero status representing termination by
|
60
|
-
# some other exception (see github issue 41)
|
61
|
-
$!.is_a?(SystemExit) ? $!.status : SimpleCov::ExitCodes::EXCEPTION
|
62
|
-
else
|
63
|
-
# Store the exit status of the test run since it goes away
|
64
|
-
# after calling the at_exit proc...
|
65
|
-
SimpleCov::ExitCodes::SUCCESS
|
66
|
-
end
|
67
|
-
|
68
|
-
SimpleCov.at_exit.call
|
69
|
-
|
70
|
-
if SimpleCov.result? # Result has been computed
|
71
|
-
covered_percent = SimpleCov.result.covered_percent.round(2)
|
72
|
-
covered_percentages = SimpleCov.result.covered_percentages.map { |p| p.round(2) }
|
73
|
-
|
74
|
-
if @exit_status == SimpleCov::ExitCodes::SUCCESS # No other errors
|
75
|
-
if covered_percent < SimpleCov.minimum_coverage # rubocop:disable Metrics/BlockNesting
|
76
|
-
$stderr.printf("Coverage (%.2f%%) is below the expected minimum coverage (%.2f%%).\n", covered_percent, SimpleCov.minimum_coverage)
|
77
|
-
@exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
78
|
-
elsif covered_percentages.any? { |p| p < SimpleCov.minimum_coverage_by_file } # rubocop:disable Metrics/BlockNesting
|
79
|
-
$stderr.printf("File (%s) is only (%.2f%%) covered. This is below the expected minimum coverage per file of (%.2f%%).\n", SimpleCov.result.least_covered_file, covered_percentages.min, SimpleCov.minimum_coverage_by_file)
|
80
|
-
@exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE
|
81
|
-
elsif (last_run = SimpleCov::LastRun.read) # rubocop:disable Metrics/BlockNesting
|
82
|
-
coverage_diff = last_run["result"]["covered_percent"] - covered_percent
|
83
|
-
if coverage_diff > SimpleCov.maximum_coverage_drop # rubocop:disable Metrics/BlockNesting
|
84
|
-
$stderr.printf("Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%).\n", coverage_diff, SimpleCov.maximum_coverage_drop)
|
85
|
-
@exit_status = SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Don't overwrite last_run file if refuse_coverage_drop option is enabled and the coverage has dropped
|
91
|
-
unless @exit_status == SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
|
92
|
-
SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent})
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Force exit with stored status (see github issue #5)
|
97
|
-
# unless it's nil or 0 (see github issue #281)
|
98
|
-
Kernel.exit @exit_status if @exit_status && @exit_status > 0
|
28
|
+
SimpleCov.set_exit_exception
|
29
|
+
SimpleCov.run_exit_tasks!
|
99
30
|
end
|
100
31
|
|
101
32
|
# Autoload config from ~/.simplecov if present
|
@@ -111,7 +42,7 @@ loop do
|
|
111
42
|
begin
|
112
43
|
load filename
|
113
44
|
rescue LoadError, StandardError
|
114
|
-
|
45
|
+
warn "Warning: Error occurred while trying to load #{filename}. " \
|
115
46
|
"Error message: #{$!.message}"
|
116
47
|
end
|
117
48
|
break
|