From ba25c41082fd58febccaa6a17ebcfee2f6ebb3c7 Mon Sep 17 00:00:00 2001 From: Anton Chuchkalov Date: Mon, 14 Dec 2015 17:27:07 +0400 Subject: [PATCH] add coverage tool --- devops-service/Gemfile | 1 + devops-service/Gemfile.lock | 10 +++++ devops-service/spec/spec_helper.rb | 61 +++++++++++++++++++----------- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/devops-service/Gemfile b/devops-service/Gemfile index 13b88c3..d6628eb 100644 --- a/devops-service/Gemfile +++ b/devops-service/Gemfile @@ -36,4 +36,5 @@ end group :devepoment do gem 'byebug' gem 'guard-rspec', require: false + gem 'simplecov', require: false end diff --git a/devops-service/Gemfile.lock b/devops-service/Gemfile.lock index 31da4a0..d9ca5a3 100644 --- a/devops-service/Gemfile.lock +++ b/devops-service/Gemfile.lock @@ -60,6 +60,7 @@ GEM gherkin (~> 2.12.0) daemons (1.2.3) diff-lcs (1.2.5) + docile (1.1.5) em-websocket (0.3.8) addressable (>= 2.1.1) eventmachine (>= 0.12.9) @@ -291,6 +292,11 @@ GEM json redis (>= 3.0.6) redis-namespace (>= 1.3.1) + simplecov (0.11.1) + docile (~> 1.1.0) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) sinatra (1.4.5) rack (~> 1.4) rack-protection (~> 1.4) @@ -352,9 +358,13 @@ DEPENDENCIES rspec (~> 3.3) rspec_junit_formatter sidekiq (= 3.2.6) + simplecov sinatra (= 1.4.5) sinatra-contrib sinatra-websocket test-unit thin (~> 1.5.1) wisper + +BUNDLED WITH + 1.10.6 diff --git a/devops-service/spec/spec_helper.rb b/devops-service/spec/spec_helper.rb index 9f2500f..5dd1d0a 100644 --- a/devops-service/spec/spec_helper.rb +++ b/devops-service/spec/spec_helper.rb @@ -4,32 +4,49 @@ require 'factory_girl' require 'active_support/core_ext/hash/indifferent_access' require 'active_support/inflector' -# setup load_path and require support files -root = File.join(File.dirname(__FILE__), "..") -$LOAD_PATH.push root unless $LOAD_PATH.include? root - -# suppress output -original_stdout = $stdout -$stdout = File.open(File::NULL, "w") - -Dir[("./spec/support/**/*.rb")].each { |f| require f } -Dir[("./spec/shared_contexts/**/*.rb")].each { |f| require f } - -# Factory girl configuration -FactoryGirl.define do - # do not try to persist, but raise validation errors - to_create { |model| model.validate! } +def suppress_output! + original_stdout = $stdout + $stdout = File.open(File::NULL, "w") + RSpec.configure do |config| + config.after(:all) do + $stdout = original_stdout + end + end end -FactoryGirl.find_definitions + +def check_coverage + require 'simplecov' + SimpleCov.start do + add_filter { |src| src.filename =~ /spec\// } + end +end + +def require_support_files + root = File.join(File.dirname(__FILE__), "..") + $LOAD_PATH.push root unless $LOAD_PATH.include?(root) + Dir[("#{root}/spec/support/**/*.rb")].each { |f| require f } + Dir[("#{root}/spec/shared_contexts/**/*.rb")].each { |f| require f } +end + +def setup_factory_girl + FactoryGirl.define do + # do not persist, but raise validation errors + to_create { |model| model.validate! } + end + FactoryGirl.find_definitions + RSpec.configure { |config| config.include FactoryGirl::Syntax::Methods } +end + + +# extra configuration +suppress_output! +check_coverage if ENV['COVERAGE'] +require_support_files +setup_factory_girl + # RSpec configuration RSpec.configure do |config| - config.include FactoryGirl::Syntax::Methods - - config.after(:all) do - $stdout = original_stdout - end - # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer.