diff --git a/CHANGELOG.md b/CHANGELOG.md index 3500017f..ac2ed6ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ Unreleased ([changes](https://github.com/colszowka/simplecov/compare/v0.7.0...master)) ------------------- + * [FEATURE] Automatically detect the usage of parallel_tests. + See https://github.com/colszowka/simplecov/issues/64 * [FEATURE] Adds support for Rails 4 command guessing. v0.7.1, 2012-10-12 ([changes](https://github.com/colszowka/simplecov/compare/v0.7.0...v0.7.1)) diff --git a/lib/simplecov.rb b/lib/simplecov.rb index 0db017fe..50739b2d 100644 --- a/lib/simplecov.rb +++ b/lib/simplecov.rb @@ -1,6 +1,8 @@ # # Code coverage for ruby 1.9. Please check out README for a full introduction. # +require 'lockfile' + module SimpleCov # Indicates invalid coverage data class CoverageDataError < StandardError; end; @@ -52,8 +54,12 @@ def result # If we're using merging of results, store the current result # first, then merge the results and return those if use_merging - SimpleCov::ResultMerger.store_result(@result) if @result - return SimpleCov::ResultMerger.merged_result + lockfile = ::Lockfile.new ResultMerger.resultset_path + '.lockfile' + + lockfile.lock do + SimpleCov::ResultMerger.store_result(@result) if @result + return SimpleCov::ResultMerger.merged_result + end else return @result if defined? @result end diff --git a/lib/simplecov/command_guesser.rb b/lib/simplecov/command_guesser.rb index 4fb8b1fb..c27984a0 100644 --- a/lib/simplecov/command_guesser.rb +++ b/lib/simplecov/command_guesser.rb @@ -11,10 +11,19 @@ class << self attr_accessor :original_run_command def guess - from_command_line_options || from_defined_constants + from_env || from_command_line_options || from_defined_constants end private + + def from_env + # If being run from inside parallel_tests set the command name according to the process number + if ENV['PARALLEL_TEST_GROUPS'] && ENV['TEST_ENV_NUMBER'] + number = ENV['TEST_ENV_NUMBER'] + number = '1' if number == '' + "(#{number}/#{ENV['PARALLEL_TEST_GROUPS']})" + end + end def from_command_line_options case original_run_command diff --git a/simplecov.gemspec b/simplecov.gemspec index 65eae894..fa1fb229 100644 --- a/simplecov.gemspec +++ b/simplecov.gemspec @@ -13,6 +13,7 @@ Gem::Specification.new do |gem| gem.summary = gem.description gem.add_dependency 'multi_json', '~> 1.0' + gem.add_dependency 'lockfile' gem.add_dependency 'simplecov-html', '~> 0.7.1' gem.add_development_dependency 'aruba'