-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathsimplecov_helper.rb
67 lines (59 loc) · 2 KB
/
simplecov_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'simplecov/no_defaults'
require 'simplecov-html'
require 'simplecov_json_formatter'
require 'simplecov-cobertura'
class SimplecovHelper
def self.start
configure
SimpleCov.start
at_exit do
SimpleCov.run_exit_tasks!
end
end
def self.configure
SimpleCov.configure do
if ENV['CI_JOB_NAME']
# this puts results in different sub-folders of coverage/ for each parallel test worker
# by using the job name. Folders end up being coverage/specs-1-5, coverage/specs-2-5, etc.
# This is not necessarily folder name friendly, so non-alphabetic/numeric characters are
# removed.
job_name = ENV['CI_JOB_NAME'].downcase
.gsub(/[^a-z0-9]/, '-')[0..62]
.gsub(/(\A-+|-+\z)/, '')
command_name job_name
coverage_dir "coverage/#{job_name}"
end
enable_coverage :branch
formatter SimpleCov::Formatter::MultiFormatter.new(configured_formatters)
track_files '{app,lib}/**/*.rb'
add_group 'Controllers', 'app/controllers'
add_group 'Forms', 'app/forms'
add_group 'Models', 'app/models'
add_group 'Mailers', 'app/mailers'
add_group 'Helpers', 'app/helpers'
add_group 'Jobs', %w[app/jobs app/workers]
add_group 'Libraries', 'lib/'
add_group 'Presenters', 'app/presenters'
add_group 'Services', 'app/services'
add_filter %r{^/spec/}
add_filter '/vendor/bundle/'
add_filter '/config/'
add_filter '/lib/deploy/migration_statement_timeout.rb'
add_filter '/lib/tasks/create_test_accounts.rb'
add_filter %r{^/db/}
add_filter %r{^/\.gem/}
add_filter %r{/vendor/ruby/}
end
end
def self.configured_formatters
formatters = [
SimpleCov::Formatter::SimpleFormatter,
SimpleCov::Formatter::HTMLFormatter,
]
if ENV['GITLAB_CI']
# GitLab CI uses Cobertura formatter to display diffs in pull requests
formatters << SimpleCov::Formatter::CoberturaFormatter
end
formatters
end
end