From 77ebd7089796b3dda61d01899e7e9f4a9e81ff4b Mon Sep 17 00:00:00 2001 From: Simone Carletti Date: Wed, 9 Oct 2013 15:58:45 +0200 Subject: [PATCH 1/3] Allow a custom SimpleCov adapter (aka profile) This will fix the issue where code coverage is not fully reported for a Rails project or any other Ruby project containing files outside /lib. --- lib/code_climate/test_reporter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/code_climate/test_reporter.rb b/lib/code_climate/test_reporter.rb index e7a6ca0..2de2dcb 100644 --- a/lib/code_climate/test_reporter.rb +++ b/lib/code_climate/test_reporter.rb @@ -6,7 +6,7 @@ def self.start require "simplecov" ::SimpleCov.add_filter 'vendor' ::SimpleCov.formatter = Formatter - ::SimpleCov.start("test_frameworks") + ::SimpleCov.start(ENV["CODECLIMATE_SIMPLECOV_PROFILE"] || "test_frameworks") else puts("Not reporting to Code Climate because ENV['CODECLIMATE_REPO_TOKEN'] is not set.") end From 9e0bb2e20ecb3d1a8164e0c8e0f49a6d1c0a2d67 Mon Sep 17 00:00:00 2001 From: Simone Carletti Date: Tue, 15 Oct 2013 17:26:53 +0200 Subject: [PATCH 2/3] Use the configuration to store the SimpleCov profile --- lib/code_climate/test_reporter.rb | 2 +- .../test_reporter/configuration.rb | 6 +++- spec/lib/configuration_spec.rb | 30 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/code_climate/test_reporter.rb b/lib/code_climate/test_reporter.rb index e1ee56f..17ed2da 100644 --- a/lib/code_climate/test_reporter.rb +++ b/lib/code_climate/test_reporter.rb @@ -6,7 +6,7 @@ def self.start require "simplecov" ::SimpleCov.add_filter 'vendor' ::SimpleCov.formatter = Formatter - ::SimpleCov.start(ENV["CODECLIMATE_SIMPLECOV_PROFILE"] || "test_frameworks") + ::SimpleCov.start(configuration.profile) end end diff --git a/lib/code_climate/test_reporter/configuration.rb b/lib/code_climate/test_reporter/configuration.rb index bda363a..79307f6 100644 --- a/lib/code_climate/test_reporter/configuration.rb +++ b/lib/code_climate/test_reporter/configuration.rb @@ -17,12 +17,16 @@ def self.configuration end class Configuration - attr_accessor :branch, :logger + attr_accessor :branch, :logger, :profile def logger @logger ||= default_logger end + def profile + @profile ||= (ENV["CODECLIMATE_SIMPLECOV_PROFILE"] || "test_frameworks") + end + private def default_logger diff --git a/spec/lib/configuration_spec.rb b/spec/lib/configuration_spec.rb index 6708198..689c1f9 100644 --- a/spec/lib/configuration_spec.rb +++ b/spec/lib/configuration_spec.rb @@ -12,6 +12,7 @@ module CodeClimate::TestReporter expect(CodeClimate::TestReporter.configuration.branch).to be_nil expect(CodeClimate::TestReporter.configuration.logger).to be_instance_of Logger expect(CodeClimate::TestReporter.configuration.logger.level).to eq Logger::INFO + expect(CodeClimate::TestReporter.configuration.profile).to eq('test_frameworks') end end @@ -38,6 +39,35 @@ module CodeClimate::TestReporter expect(CodeClimate::TestReporter.configuration.branch).to eq :master end + + it 'stores profile' do + CodeClimate::TestReporter.configure do |config| + config.profile = 'custom' + end + + expect(CodeClimate::TestReporter.configuration.profile).to eq('custom') + end + end + + describe 'profile' do + context 'when the CODECLIMATE_SIMPLECOV_PROFILE environment variable is set' do + before do + ENV['CODECLIMATE_SIMPLECOV_PROFILE'] = 'custom' + CodeClimate::TestReporter.configure + end + + it 'uses the variable over the default' do + expect(CodeClimate::TestReporter.configuration.profile).to eq('custom') + end + + it 'uses the custom value over the variable' do + CodeClimate::TestReporter.configure do |config| + config.profile = 'provided' + end + + expect(CodeClimate::TestReporter.configuration.profile).to eq('provided') + end + end end end end From 7a99a9622939cb5af52d78fe1d3d0c29eb8d0cc2 Mon Sep 17 00:00:00 2001 From: Simone Carletti Date: Tue, 29 Oct 2013 15:43:13 +0100 Subject: [PATCH 3/3] Remove the ENV variable as requested --- .../test_reporter/configuration.rb | 2 +- spec/lib/configuration_spec.rb | 21 ------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/lib/code_climate/test_reporter/configuration.rb b/lib/code_climate/test_reporter/configuration.rb index 79307f6..3e5fddc 100644 --- a/lib/code_climate/test_reporter/configuration.rb +++ b/lib/code_climate/test_reporter/configuration.rb @@ -24,7 +24,7 @@ def logger end def profile - @profile ||= (ENV["CODECLIMATE_SIMPLECOV_PROFILE"] || "test_frameworks") + @profile ||= "test_frameworks" end private diff --git a/spec/lib/configuration_spec.rb b/spec/lib/configuration_spec.rb index 689c1f9..5f4a379 100644 --- a/spec/lib/configuration_spec.rb +++ b/spec/lib/configuration_spec.rb @@ -48,26 +48,5 @@ module CodeClimate::TestReporter expect(CodeClimate::TestReporter.configuration.profile).to eq('custom') end end - - describe 'profile' do - context 'when the CODECLIMATE_SIMPLECOV_PROFILE environment variable is set' do - before do - ENV['CODECLIMATE_SIMPLECOV_PROFILE'] = 'custom' - CodeClimate::TestReporter.configure - end - - it 'uses the variable over the default' do - expect(CodeClimate::TestReporter.configuration.profile).to eq('custom') - end - - it 'uses the custom value over the variable' do - CodeClimate::TestReporter.configure do |config| - config.profile = 'provided' - end - - expect(CodeClimate::TestReporter.configuration.profile).to eq('provided') - end - end - end end end