diff options
-rw-r--r-- | features/support/env.rb | 4 | ||||
-rwxr-xr-x | scripts/merge-simplecov | 9 | ||||
-rw-r--r-- | spec/simplecov_env.rb | 71 | ||||
-rw-r--r-- | spec/spec_helper.rb | 4 |
4 files changed, 51 insertions, 37 deletions
diff --git a/features/support/env.rb b/features/support/env.rb index 2a3e21d28bc..569fd444e86 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,5 +1,5 @@ -require_relative '../../spec/simplecov_env' -SimpleCov.start if ENV['SIMPLECOV'] +require './spec/simplecov_env' +SimpleCovEnv.start! ENV['RAILS_ENV'] = 'test' require './config/environment' diff --git a/scripts/merge-simplecov b/scripts/merge-simplecov index ab15b43bd0f..65f93f8830b 100755 --- a/scripts/merge-simplecov +++ b/scripts/merge-simplecov @@ -1,6 +1,7 @@ #!/usr/bin/env ruby -require 'simplecov' +require_relative '../spec/simplecov_env' +SimpleCovEnv.configure_profile module SimpleCov module ResultMerger @@ -26,10 +27,4 @@ module SimpleCov end end -# Ignore CI environment -ENV['CI'] = nil -ENV['CI_BUILD_NAME'] = nil - -require_relative '../spec/simplecov_env' - SimpleCov::ResultMerger.merged_result.format! diff --git a/spec/simplecov_env.rb b/spec/simplecov_env.rb index 112ca1b176a..6f8f7109e14 100644 --- a/spec/simplecov_env.rb +++ b/spec/simplecov_env.rb @@ -1,35 +1,54 @@ require 'simplecov' -SimpleCov.configure do - load_profile 'test_frameworks' - track_files '{app,lib}/**/*.rb' +module SimpleCovEnv + extend self - if ENV['CI_BUILD_NAME'] - coverage_dir "coverage/#{ENV['CI_BUILD_NAME']}" - command_name ENV['CI_BUILD_NAME'] + def start! + return unless ENV['SIMPLECOV'] + + configure_profile + configure_job + + SimpleCov.start end - if ENV['CI'] - SimpleCov.at_exit do - # In CI environment don't generate formatted reports - # Only generate .resultset.json - SimpleCov.result + def configure_job + SimpleCov.configure do + if ENV['CI_BUILD_NAME'] + coverage_dir "coverage/#{ENV['CI_BUILD_NAME']}" + command_name ENV['CI_BUILD_NAME'] + end + + if ENV['CI'] + SimpleCov.at_exit do + # In CI environment don't generate formatted reports + # Only generate .resultset.json + SimpleCov.result + end + end end end - add_filter '/vendor/ruby/' - add_filter 'config/initializers/' - - add_group 'Controllers', 'app/controllers' - add_group 'Models', 'app/models' - add_group 'Mailers', 'app/mailers' - add_group 'Helpers', 'app/helpers' - add_group 'Workers', %w(app/jobs app/workers) - add_group 'Libraries', 'lib' - add_group 'Services', 'app/services' - add_group 'Finders', 'app/finders' - add_group 'Uploaders', 'app/uploaders' - add_group 'Validators', 'app/validators' - - merge_timeout 7200 + def configure_profile + SimpleCov.configure do + load_profile 'test_frameworks' + track_files '{app,lib}/**/*.rb' + + add_filter '/vendor/ruby/' + add_filter 'config/initializers/' + + add_group 'Controllers', 'app/controllers' + add_group 'Models', 'app/models' + add_group 'Mailers', 'app/mailers' + add_group 'Helpers', 'app/helpers' + add_group 'Workers', %w(app/jobs app/workers) + add_group 'Libraries', 'lib' + add_group 'Services', 'app/services' + add_group 'Finders', 'app/finders' + add_group 'Uploaders', 'app/uploaders' + add_group 'Validators', 'app/validators' + + merge_timeout 7200 + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d2760d0ef28..4f3aacf55be 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ -require_relative 'simplecov_env' -SimpleCov.start if ENV['SIMPLECOV'] +require './spec/simplecov_env' +SimpleCovEnv.start! ENV["RAILS_ENV"] ||= 'test' |