From a3312c44dd6ed3cad71cbcdf19683e197b823f11 Mon Sep 17 00:00:00 2001 From: Tony Spataro Date: Tue, 30 Sep 2014 15:32:13 -0700 Subject: [PATCH] Fix Coveralls merged result reporting. --- .simplecov | 9 --------- .travis.yml | 2 +- Rakefile | 5 +++++ features/step_definitions/ruby_steps.rb | 23 +++++++++++++++++------ features/support/env.rb | 6 ++++++ spec/spec_helper.rb | 7 ++++++- 6 files changed, 35 insertions(+), 17 deletions(-) delete mode 100644 .simplecov diff --git a/.simplecov b/.simplecov deleted file mode 100644 index 67a9d5f..0000000 --- a/.simplecov +++ /dev/null @@ -1,9 +0,0 @@ -require 'simplecov' -require 'coveralls' - -SimpleCov.formatter = Coveralls::SimpleCov::Formatter -SimpleCov.start do - add_filter '/features/' - add_filter '/spec/' - add_filter '/vendor/' -end diff --git a/.travis.yml b/.travis.yml index ddbff7c..8ae7d3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,5 @@ rvm: - 2.0.0 - 2.1.0 script: - - bundle exec rake ci:spec && bundle exec rake ci:cucumber + - bundle exec rake ci:spec && bundle exec rake ci:cucumber && bundle exec rake coveralls:push bundler_args: --without debugger development diff --git a/Rakefile b/Rakefile index 985fc4c..b3b7f9c 100644 --- a/Rakefile +++ b/Rakefile @@ -7,6 +7,7 @@ require 'rake' begin require 'rdoc/task' require 'jeweler' + require 'coveralls/rake/task' rescue LoadError # ignore; these gems can be excluded from the bundle using --without end @@ -78,6 +79,10 @@ if defined?(Jeweler) CLEAN.include('pkg') end +if defined?(Coveralls) + Coveralls::RakeTask.new +end + RightDevelop::CI::RakeTask.new RightDevelop::Git::RakeTask.new RightDevelop::S3::RakeTask.new diff --git a/features/step_definitions/ruby_steps.rb b/features/step_definitions/ruby_steps.rb index 5cfc74e..83321c6 100644 --- a/features/step_definitions/ruby_steps.rb +++ b/features/step_definitions/ruby_steps.rb @@ -12,17 +12,24 @@ basedir = File.expand_path('../../..', __FILE__) File.open(gemfile, 'w') do |file| file.puts "source 'https://rubygems.org'" - file.puts "gem 'right_develop', :path=>'#{basedir}'" - file.puts "gem 'coveralls'" unless RUBY_VERSION =~ /^1\.8/ + file.puts "gem 'right_develop', :path=>'#{basedir}', :require=>false" + file.puts "gem 'coveralls', :require=>false" unless RUBY_VERSION =~ /^1\.8/ end end unless File.exist?(simplecov) File.open(simplecov, 'w') do |file| - dir = File.expand_path('../../../coverage', __FILE__) + root_dir = File.expand_path('../../..', __FILE__) + coverage_dir = File.join(root_dir, 'coverage') + # IMPORTANT: each scenario we invoke must use a distinct command_name, else coverage results + # will overwrite one another! + suite = "cucumber[#{scenario_location}]" + file.puts "require 'coveralls'" - file.puts "Coveralls.wear! do" - file.puts " coverage_dir '#{dir}'" + file.puts "Coveralls.wear_merged! do" + file.puts " command_name '#{suite}'" + file.puts " root '#{root_dir}'" + file.puts " coverage_dir '#{coverage_dir}'" file.puts "end" end end @@ -50,6 +57,7 @@ step 'a Rakefile' rakefile = ruby_app_path('Rakefile') File.open(rakefile, 'w') do |file| + file.puts "require 'simplecov'" unless RUBY_VERSION =~ /^1\.8/ file.puts "require 'right_develop'" file.puts "#{mod}::RakeTask.new" end @@ -69,6 +77,7 @@ step 'a Rakefile' rakefile = ruby_app_path('Rakefile') File.open(rakefile, 'w') do |file| + file.puts "require 'simplecov'" unless RUBY_VERSION =~ /^1\.8/ file.puts "require 'right_develop'" content.split("\n").each do |line| file.puts line @@ -83,7 +92,7 @@ File.open(spec, 'w') do |file| # ensure that our formatter's coverage gets handled file.puts "require 'simplecov'" unless RUBY_VERSION =~ /^1\.8/ - + file.puts "require 'right_develop'" # always include one passing test case as a baseline file.puts "describe String do" file.puts " it 'has a size' do" @@ -121,6 +130,7 @@ File.open(spec, 'w') do |file| # ensure that our formatter's coverage gets handled file.puts "require 'simplecov'" unless RUBY_VERSION =~ /^1\.8/ + file.puts "require 'right_develop'" content.split("\n").each do |line| file.puts line @@ -143,6 +153,7 @@ File.open(env, 'w') do |file| # ensure that our formatter's coverage gets handled file.puts "require 'simplecov'" unless RUBY_VERSION =~ /^1\.8/ + file.puts "require 'right_develop'" end end diff --git a/features/support/env.rb b/features/support/env.rb index 4a30c17..2bda624 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -77,8 +77,14 @@ def ruby_app_shell(cmd, options={}) module RightDevelopWorld include RubyAppHelper + + # @return [String] the filename and line of the current scenario + attr_reader :scenario_location end +Before do |scenario| + @scenario_location = scenario.location +end # The Cucumber world World(RightDevelopWorld) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ff19622..ff78aac 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,6 +26,11 @@ $: << lib_dir unless $:.include?(lib_dir) require 'coveralls' -Coveralls.wear! +Coveralls.wear_merged! do + command_name 'spec' + add_filter '/features/' + add_filter '/spec/' + add_filter '/vendor/' +end require 'right_develop'