simplecov 0.7.1 → 0.8.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.travis.yml +9 -2
  2. data/CHANGELOG.md +17 -2
  3. data/Gemfile +13 -2
  4. data/{LICENSE → MIT-LICENSE} +0 -0
  5. data/README.md +174 -117
  6. data/Rakefile +8 -3
  7. data/features/config_command_name.feature +12 -0
  8. data/features/config_merge_timeout.feature +3 -3
  9. data/features/config_profiles.feature +44 -0
  10. data/features/config_project_name.feature +2 -2
  11. data/features/cucumber_basic.feature +1 -1
  12. data/features/step_definitions/html_steps.rb +1 -1
  13. data/features/support/env.rb +23 -5
  14. data/gemfiles/multi_json_legacy.gemfile +12 -0
  15. data/gemfiles/multi_json_new.gemfile +12 -0
  16. data/lib/simplecov.rb +33 -25
  17. data/lib/simplecov/command_guesser.rb +6 -6
  18. data/lib/simplecov/configuration.rb +7 -2
  19. data/lib/simplecov/defaults.rb +9 -5
  20. data/lib/simplecov/file_list.rb +1 -1
  21. data/lib/simplecov/jruby16_fix.rb +43 -0
  22. data/lib/simplecov/no_defaults.rb +2 -0
  23. data/lib/simplecov/{adapters.rb → profiles.rb} +8 -8
  24. data/lib/simplecov/result.rb +10 -2
  25. data/lib/simplecov/source_file.rb +2 -3
  26. data/lib/simplecov/version.rb +1 -1
  27. data/simplecov.gemspec +8 -9
  28. data/test/faked_project/Gemfile +1 -1
  29. data/test/helper.rb +0 -1
  30. data/test/shoulda_macros.rb +0 -10
  31. data/test/test_1_8_fallbacks.rb +16 -18
  32. data/test/test_command_guesser.rb +13 -15
  33. data/test/test_deleted_source.rb +5 -7
  34. data/test/test_file_list.rb +15 -17
  35. data/test/test_filters.rb +56 -58
  36. data/test/test_merge_helpers.rb +73 -75
  37. data/test/test_result.rb +114 -116
  38. data/test/test_return_codes.rb +24 -26
  39. data/test/test_source_file.rb +75 -64
  40. data/test/test_source_file_line.rb +78 -82
  41. metadata +38 -86
  42. data/features/config_adapters.feature +0 -44
  43. data/gemfiles/multi_json-legacy.gemfile +0 -7
  44. data/gemfiles/multi_json-new.gemfile +0 -7
@@ -0,0 +1,2 @@
1
+ ENV['SIMPLECOV_NO_DEFAULTS'] = 'yes, no defaults'
2
+ require 'simplecov'
@@ -1,29 +1,29 @@
1
1
  #
2
- # Adapters are glorified SimpleCov configuration procs that can be easily
2
+ # Profiles are SimpleCov configuration procs that can be easily
3
3
  # loaded using SimpleCov.start :rails and defined using
4
- # SimpleCov.adapters.define :foo do
4
+ # SimpleCov.profiles.define :foo do
5
5
  # # SimpleCov configuration here, same as in SimpleCov.configure
6
6
  # end
7
7
  #
8
- class SimpleCov::Adapters < Hash
8
+ class SimpleCov::Profiles < Hash
9
9
  #
10
- # Define a SimpleCov adapter:
11
- # SimpleCov.adapters.define 'rails' do
10
+ # Define a SimpleCov profile:
11
+ # SimpleCov.profiles.define 'rails' do
12
12
  # # Same as SimpleCov.configure do .. here
13
13
  # end
14
14
  #
15
15
  def define(name, &blk)
16
16
  name = name.to_sym
17
- raise "SimpleCov Adapter '#{name}' is already defined" unless self[name].nil?
17
+ raise "SimpleCov Profile '#{name}' is already defined" unless self[name].nil?
18
18
  self[name] = blk
19
19
  end
20
20
 
21
21
  #
22
- # Applies the adapter of given name on SimpleCov.configure
22
+ # Applies the profile of given name on SimpleCov.configure
23
23
  #
24
24
  def load(name)
25
25
  name = name.to_sym
26
- raise "Could not find SimpleCov Adapter called '#{name}'" unless has_key?(name)
26
+ raise "Could not find SimpleCov Profile called '#{name}'" unless has_key?(name)
27
27
  SimpleCov.configure(&self[name])
28
28
  end
29
29
  end
@@ -19,10 +19,18 @@ module SimpleCov
19
19
  # Initialize a new SimpleCov::Result from given Coverage.result (a Hash of filenames each containing an array of
20
20
  # coverage data)
21
21
  def initialize(original_result)
22
- @original_result = original_result.freeze
23
- @files = SimpleCov::FileList.new(original_result.map do |filename, coverage|
22
+ @original_result = original_result.dup
23
+
24
+ # Squeeze filepaths (i.e. "/a/b/../c" becomes "/a/c")
25
+ @original_result.keys.each do |filename|
26
+ expanded_filename = File.expand_path filename
27
+ @original_result[expanded_filename] = @original_result.delete filename
28
+ end
29
+
30
+ @files = SimpleCov::FileList.new(@original_result.map do |filename, coverage|
24
31
  SimpleCov::SourceFile.new(filename, coverage) if File.file?(filename)
25
32
  end.compact.sort_by(&:filename))
33
+
26
34
  filter!
27
35
  end
28
36
 
@@ -30,7 +30,6 @@ module SimpleCov
30
30
  raise ArgumentError, "Only Fixnum and nil accepted for coverage" unless coverage.kind_of?(Fixnum) or coverage.nil?
31
31
  @src, @line_number, @coverage = src, line_number, coverage
32
32
  @skipped = false
33
- @src.encode!('UTF-8', 'UTF-8', :invalid => :replace) if @src.respond_to?(:encode!)
34
33
  end
35
34
 
36
35
  # Returns true if this is a line that should have been covered, but was not
@@ -79,7 +78,7 @@ module SimpleCov
79
78
 
80
79
  def initialize(filename, coverage)
81
80
  @filename, @coverage = filename, coverage
82
- File.open(filename, "r:UTF-8") {|f| @src = f.readlines }
81
+ File.open(filename, "rb") {|f| @src = f.readlines }
83
82
  end
84
83
 
85
84
  # Returns all source lines for this file as instances of SimpleCov::SourceFile::Line,
@@ -114,7 +113,7 @@ module SimpleCov
114
113
  if relevant_lines == 0
115
114
  0
116
115
  else
117
- (covered_lines.count) * 100 / relevant_lines.to_f
116
+ (covered_lines.count) * 100.0 / relevant_lines.to_f
118
117
  end
119
118
  end
120
119
 
@@ -1,3 +1,3 @@
1
1
  module SimpleCov
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0.pre"
3
3
  end
data/simplecov.gemspec CHANGED
@@ -9,18 +9,17 @@ Gem::Specification.new do |gem|
9
9
  gem.authors = ["Christoph Olszowka"]
10
10
  gem.email = ['christoph at olszowka de']
11
11
  gem.homepage = 'http://github.com/colszowka/simplecov'
12
- gem.description = %Q{Code coverage for Ruby 1.9 with a powerful configuration library and automatic merging of coverage across test suites}
12
+ gem.description = %Q{Code coverage for Ruby 1.9+ with a powerful configuration library and automatic merging of coverage across test suites}
13
13
  gem.summary = gem.description
14
+ gem.license = "MIT"
14
15
 
15
- gem.add_dependency 'multi_json', '~> 1.0'
16
+ gem.add_dependency 'multi_json'
16
17
  gem.add_dependency 'simplecov-html', '~> 0.7.1'
17
- gem.add_development_dependency 'aruba'
18
- gem.add_development_dependency 'capybara'
19
- gem.add_development_dependency 'appraisal'
20
- gem.add_development_dependency 'cucumber', '>= 1.1.4'
21
- gem.add_development_dependency 'rake'
22
- gem.add_development_dependency 'rspec'
23
- gem.add_development_dependency 'shoulda'
18
+
19
+ gem.add_development_dependency 'appraisal', '~> 0.5.1'
20
+ gem.add_development_dependency 'rake', '~> 10.0.3'
21
+ gem.add_development_dependency 'rspec', '~> 2.13.0'
22
+ gem.add_development_dependency 'shoulda', '~> 3.4.0'
24
23
 
25
24
  gem.files = `git ls-files`.split("\n")
26
25
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'simplecov', :path => '../../../'
4
4
  gem 'rake'
data/test/helper.rb CHANGED
@@ -13,7 +13,6 @@ class Test::Unit::TestCase
13
13
  # Keep 1.8-rubies from complaining about missing tests in each file that covers only 1.9 functionality
14
14
  def default_test
15
15
  end
16
-
17
16
  end
18
17
 
19
18
  require 'shoulda_macros'
@@ -1,14 +1,4 @@
1
1
  module ShouldaMacros
2
- #
3
- # Simple block helper for running certain tests only on specific ruby versions.
4
- # The given strings will be regexp-matched against RUBY_VERSION
5
- #
6
- def on_ruby(*ruby_versions)
7
- context "On Ruby #{RUBY_VERSION}" do
8
- yield
9
- end if ruby_versions.any? {|v| RUBY_VERSION =~ /#{v}/ }
10
- end
11
-
12
2
  def should_be(boolean_flag)
13
3
  should "be #{boolean_flag}" do
14
4
  assert_equal true, subject.send(boolean_flag)
@@ -7,27 +7,25 @@ require 'helper'
7
7
  # be called in a test/spec-helper simplecov config block
8
8
  #
9
9
  class Test18FallBacks < Test::Unit::TestCase
10
- on_ruby '1.8' do
11
- should "return false when calling SimpleCov.start" do
12
- assert_equal false, SimpleCov.start
13
- end
10
+ should "return false when calling SimpleCov.start" do
11
+ assert_equal false, SimpleCov.start
12
+ end
14
13
 
15
- should "return false when calling SimpleCov.start with a block" do
16
- assert_equal false, SimpleCov.start { raise "Shouldn't reach this!?" }
17
- end
14
+ should "return false when calling SimpleCov.start with a block" do
15
+ assert_equal false, SimpleCov.start { raise "Shouldn't reach this!?" }
16
+ end
18
17
 
19
- should "return false when calling SimpleCov.configure with a block" do
20
- assert_equal false, SimpleCov.configure { raise "Shouldn't reach this!?" }
21
- end
18
+ should "return false when calling SimpleCov.configure with a block" do
19
+ assert_equal false, SimpleCov.configure { raise "Shouldn't reach this!?" }
20
+ end
22
21
 
23
- should "allow to define an adapter" do
24
- begin
25
- SimpleCov.adapters.define 'testadapter' do
26
- add_filter '/config/'
27
- end
28
- rescue => err
29
- assert false, "Adapter definition should have been fine, but raised #{err}"
22
+ should "allow to define a profile" do
23
+ begin
24
+ SimpleCov.profiles.define 'testprofile' do
25
+ add_filter '/config/'
30
26
  end
27
+ rescue => err
28
+ assert false, "Profile definition should have been fine, but raised #{err}"
31
29
  end
32
30
  end
33
- end
31
+ end if RUBY_VERSION.start_with? '1.8'
@@ -1,21 +1,19 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestCommandGuesser < Test::Unit::TestCase
4
- on_ruby '1.9' do
5
- def self.should_guess_command_name(expectation, *argv)
6
- argv.each do |args|
7
- should "return '#{expectation}' for '#{args}'" do
8
- SimpleCov::CommandGuesser.original_run_command = args
9
- assert_equal expectation, SimpleCov::CommandGuesser.guess
10
- end
4
+ def self.should_guess_command_name(expectation, *argv)
5
+ argv.each do |args|
6
+ should "return '#{expectation}' for '#{args}'" do
7
+ SimpleCov::CommandGuesser.original_run_command = args
8
+ assert_equal expectation, SimpleCov::CommandGuesser.guess
11
9
  end
12
10
  end
13
-
14
- should_guess_command_name "Unit Tests", '/some/path/test/units/foo_bar_test.rb', 'test/units/foo.rb', 'test/foo.rb'
15
- should_guess_command_name "Functional Tests", '/some/path/test/functional/foo_bar_controller_test.rb'
16
- should_guess_command_name "Integration Tests", '/some/path/test/integration/foo_bar_controller_test.rb'
17
- should_guess_command_name "Cucumber Features", 'features', 'cucumber', 'cucumber features'
18
- should_guess_command_name "RSpec", '/some/path/spec/foo.rb'
19
- should_guess_command_name "Unit Tests", 'some_arbitrary_command with arguments' # Because Test::Unit const is defined!
20
11
  end
21
- end
12
+
13
+ should_guess_command_name "Unit Tests", '/some/path/test/units/foo_bar_test.rb', 'test/units/foo.rb', 'test/foo.rb', 'test/{models,helpers,unit}/**/*_test.rb'
14
+ should_guess_command_name "Functional Tests", '/some/path/test/functional/foo_bar_controller_test.rb', 'test/{controllers,mailers,functional}/**/*_test.rb'
15
+ should_guess_command_name "Integration Tests", '/some/path/test/integration/foo_bar_controller_test.rb', 'test/integration/**/*_test.rb'
16
+ should_guess_command_name "Cucumber Features", 'features', 'cucumber', 'cucumber features'
17
+ should_guess_command_name "RSpec", '/some/path/spec/foo.rb'
18
+ should_guess_command_name "Unit Tests", 'some_arbitrary_command with arguments' # Because Test::Unit const is defined!
19
+ end if SimpleCov.usable?
@@ -3,13 +3,11 @@ require 'helper'
3
3
  # Test to verify correct handling of deleted files,
4
4
  # see issue #9 on github
5
5
  class TestDeletedSource < Test::Unit::TestCase
6
- on_ruby '1.8', '1.9' do
7
- context "A source file which is subsequently deleted" do
8
- should "not cause an error" do
9
- Dir.chdir(File.join(File.dirname(__FILE__), 'fixtures')) do
10
- `ruby deleted_source_sample.rb`
11
- assert_equal 0, $?.exitstatus
12
- end
6
+ context "A source file which is subsequently deleted" do
7
+ should "not cause an error" do
8
+ Dir.chdir(File.join(File.dirname(__FILE__), 'fixtures')) do
9
+ `ruby deleted_source_sample.rb`
10
+ assert_equal 0, $?.exitstatus
13
11
  end
14
12
  end
15
13
  end
@@ -1,24 +1,22 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestFileList < Test::Unit::TestCase
4
- on_ruby "1.9" do
5
- context "With a file list from a result" do
6
- setup do
7
- original_result = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
8
- source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
9
- source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]}
10
- @file_list = SimpleCov::Result.new(original_result).files
11
- end
4
+ context "With a file list from a result" do
5
+ setup do
6
+ original_result = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
7
+ source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
8
+ source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]}
9
+ @file_list = SimpleCov::Result.new(original_result).files
10
+ end
12
11
 
13
- should("have 13 covered_lines") { assert_equal 13, @file_list.covered_lines }
14
- should("have 2 missed_lines") { assert_equal 2, @file_list.missed_lines }
15
- should("have 18 never_lines") { assert_equal 18, @file_list.never_lines }
16
- should("have 15 lines_of_code") { assert_equal 15, @file_list.lines_of_code }
17
- should("have 3 skipped_lines") { assert_equal 3, @file_list.skipped_lines }
12
+ should("have 13 covered_lines") { assert_equal 13, @file_list.covered_lines }
13
+ should("have 2 missed_lines") { assert_equal 2, @file_list.missed_lines }
14
+ should("have 18 never_lines") { assert_equal 18, @file_list.never_lines }
15
+ should("have 15 lines_of_code") { assert_equal 15, @file_list.lines_of_code }
16
+ should("have 3 skipped_lines") { assert_equal 3, @file_list.skipped_lines }
18
17
 
19
- should "have correct covered_percent" do
20
- assert_equal 100.0*13/15, @file_list.covered_percent
21
- end
18
+ should "have correct covered_percent" do
19
+ assert_equal 100.0*13/15, @file_list.covered_percent
22
20
  end
23
21
  end
24
- end
22
+ end if SimpleCov.usable?
data/test/test_filters.rb CHANGED
@@ -1,80 +1,78 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestFilters < Test::Unit::TestCase
4
- on_ruby '1.9' do
5
- context "A source file initialized with some coverage data" do
6
- setup do
7
- @source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
8
- end
4
+ context "A source file initialized with some coverage data" do
5
+ setup do
6
+ @source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
7
+ end
9
8
 
10
- should "not match a new SimpleCov::StringFilter 'foobar'" do
11
- assert !SimpleCov::StringFilter.new('foobar').matches?(@source_file)
12
- end
9
+ should "not match a new SimpleCov::StringFilter 'foobar'" do
10
+ assert !SimpleCov::StringFilter.new('foobar').matches?(@source_file)
11
+ end
13
12
 
14
- should "not match a new SimpleCov::StringFilter 'some/path'" do
15
- assert !SimpleCov::StringFilter.new('some/path').matches?(@source_file)
16
- end
13
+ should "not match a new SimpleCov::StringFilter 'some/path'" do
14
+ assert !SimpleCov::StringFilter.new('some/path').matches?(@source_file)
15
+ end
17
16
 
18
- should "match a new SimpleCov::StringFilter 'test/fixtures'" do
19
- assert SimpleCov::StringFilter.new('test/fixtures').matches?(@source_file)
20
- end
17
+ should "match a new SimpleCov::StringFilter 'test/fixtures'" do
18
+ assert SimpleCov::StringFilter.new('test/fixtures').matches?(@source_file)
19
+ end
21
20
 
22
- should "match a new SimpleCov::StringFilter 'test/fixtures/sample.rb'" do
23
- assert SimpleCov::StringFilter.new('test/fixtures/sample.rb').matches?(@source_file)
24
- end
21
+ should "match a new SimpleCov::StringFilter 'test/fixtures/sample.rb'" do
22
+ assert SimpleCov::StringFilter.new('test/fixtures/sample.rb').matches?(@source_file)
23
+ end
25
24
 
26
- should "match a new SimpleCov::StringFilter 'sample.rb'" do
27
- assert SimpleCov::StringFilter.new('sample.rb').matches?(@source_file)
28
- end
25
+ should "match a new SimpleCov::StringFilter 'sample.rb'" do
26
+ assert SimpleCov::StringFilter.new('sample.rb').matches?(@source_file)
27
+ end
29
28
 
30
- should "not match a new SimpleCov::BlockFilter that is not applicable" do
31
- assert !SimpleCov::BlockFilter.new(Proc.new {|s| File.basename(s.filename) == 'foo.rb'}).matches?(@source_file)
32
- end
29
+ should "not match a new SimpleCov::BlockFilter that is not applicable" do
30
+ assert !SimpleCov::BlockFilter.new(Proc.new {|s| File.basename(s.filename) == 'foo.rb'}).matches?(@source_file)
31
+ end
33
32
 
34
- should "match a new SimpleCov::BlockFilter that is applicable" do
35
- assert SimpleCov::BlockFilter.new(Proc.new {|s| File.basename(s.filename) == 'sample.rb'}).matches?(@source_file)
36
- end
33
+ should "match a new SimpleCov::BlockFilter that is applicable" do
34
+ assert SimpleCov::BlockFilter.new(Proc.new {|s| File.basename(s.filename) == 'sample.rb'}).matches?(@source_file)
37
35
  end
36
+ end
38
37
 
39
- context "with no filters set up and a basic source file in an array" do
40
- setup do
41
- SimpleCov.filters = []
42
- @files = [SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])]
43
- end
38
+ context "with no filters set up and a basic source file in an array" do
39
+ setup do
40
+ SimpleCov.filters = []
41
+ @files = [SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])]
42
+ end
44
43
 
45
- should "return 0 items after executing SimpleCov.filtered on files when using a 'sample' string filter" do
46
- SimpleCov.add_filter "sample"
47
- assert_equal 0, SimpleCov.filtered(@files).count
48
- end
44
+ should "return 0 items after executing SimpleCov.filtered on files when using a 'sample' string filter" do
45
+ SimpleCov.add_filter "sample"
46
+ assert_equal 0, SimpleCov.filtered(@files).count
47
+ end
49
48
 
50
- should "return 0 items after executing SimpleCov.filtered on files when using a 'test/fixtures/' string filter" do
51
- SimpleCov.add_filter "test/fixtures"
52
- assert_equal 0, SimpleCov.filtered(@files).count
53
- end
49
+ should "return 0 items after executing SimpleCov.filtered on files when using a 'test/fixtures/' string filter" do
50
+ SimpleCov.add_filter "test/fixtures"
51
+ assert_equal 0, SimpleCov.filtered(@files).count
52
+ end
54
53
 
55
- should "return 1 item after executing SimpleCov.filtered on files when using a 'fooo' string filter" do
56
- SimpleCov.add_filter "fooo"
57
- assert_equal 1, SimpleCov.filtered(@files).count
58
- end
54
+ should "return 1 item after executing SimpleCov.filtered on files when using a 'fooo' string filter" do
55
+ SimpleCov.add_filter "fooo"
56
+ assert_equal 1, SimpleCov.filtered(@files).count
57
+ end
59
58
 
60
- should "return 0 items after executing SimpleCov.filtered on files when using a block filter that returns true" do
61
- SimpleCov.add_filter do |src_file|
62
- true
63
- end
64
- assert_equal 0, SimpleCov.filtered(@files).count
59
+ should "return 0 items after executing SimpleCov.filtered on files when using a block filter that returns true" do
60
+ SimpleCov.add_filter do |src_file|
61
+ true
65
62
  end
63
+ assert_equal 0, SimpleCov.filtered(@files).count
64
+ end
66
65
 
67
- should "return 1 item after executing SimpleCov.filtered on files when using an always-false block filter" do
68
- SimpleCov.add_filter do |src_file|
69
- false
70
- end
71
- assert_equal 1, SimpleCov.filtered(@files).count
66
+ should "return 1 item after executing SimpleCov.filtered on files when using an always-false block filter" do
67
+ SimpleCov.add_filter do |src_file|
68
+ false
72
69
  end
70
+ assert_equal 1, SimpleCov.filtered(@files).count
71
+ end
73
72
 
74
- should "return a FileList after filtering" do
75
- SimpleCov.add_filter "fooo"
76
- assert_equal SimpleCov::FileList, SimpleCov.filtered(@files).class
77
- end
73
+ should "return a FileList after filtering" do
74
+ SimpleCov.add_filter "fooo"
75
+ assert_equal SimpleCov::FileList, SimpleCov.filtered(@files).class
78
76
  end
79
77
  end
80
- end
78
+ end if SimpleCov.usable?
@@ -1,107 +1,105 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestMergeHelpers < Test::Unit::TestCase
4
- on_ruby '1.9' do
5
- context "With two faked coverage resultsets" do
4
+ context "With two faked coverage resultsets" do
5
+ setup do
6
+ SimpleCov.use_merging true
7
+ @resultset1 = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
8
+ source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
9
+ source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
10
+ source_fixture('resultset1.rb') => [1, 1, 1, 1]}
11
+
12
+ @resultset2 = {source_fixture('sample.rb') => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
13
+ source_fixture('app/models/user.rb') => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
14
+ source_fixture('app/controllers/sample_controller.rb') => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
15
+ source_fixture('resultset2.rb') => [nil, 1, 1, nil]}
16
+ end
17
+
18
+ context "a merge" do
6
19
  setup do
7
- SimpleCov.use_merging true
8
- @resultset1 = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
9
- source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
10
- source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
11
- source_fixture('resultset1.rb') => [1, 1, 1, 1]}
12
-
13
- @resultset2 = {source_fixture('sample.rb') => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
14
- source_fixture('app/models/user.rb') => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
15
- source_fixture('app/controllers/sample_controller.rb') => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
16
- source_fixture('resultset2.rb') => [nil, 1, 1, nil]}
20
+ assert @merged = @resultset1.merge_resultset(@resultset2)
17
21
  end
18
22
 
19
- context "a merge" do
20
- setup do
21
- assert @merged = @resultset1.merge_resultset(@resultset2)
22
- end
23
-
24
- should "have proper results for sample.rb" do
25
- assert_equal [1, 1, 2, 2, nil, nil, 2, 2, nil, nil], @merged[source_fixture('sample.rb')]
26
- end
27
-
28
- should "have proper results for user.rb" do
29
- assert_equal [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil], @merged[source_fixture('app/models/user.rb')]
30
- end
23
+ should "have proper results for sample.rb" do
24
+ assert_equal [1, 1, 2, 2, nil, nil, 2, 2, nil, nil], @merged[source_fixture('sample.rb')]
25
+ end
31
26
 
32
- should "have proper results for sample_controller.rb" do
33
- assert_equal [nil, 4, 2, 1, nil, nil, 2, 0, nil, nil], @merged[source_fixture('app/controllers/sample_controller.rb')]
34
- end
27
+ should "have proper results for user.rb" do
28
+ assert_equal [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil], @merged[source_fixture('app/models/user.rb')]
29
+ end
35
30
 
36
- should "have proper results for resultset1.rb" do
37
- assert_equal [1, 1, 1, 1], @merged[source_fixture('resultset1.rb')]
38
- end
31
+ should "have proper results for sample_controller.rb" do
32
+ assert_equal [nil, 4, 2, 1, nil, nil, 2, 0, nil, nil], @merged[source_fixture('app/controllers/sample_controller.rb')]
33
+ end
39
34
 
40
- should "have proper results for resultset2.rb" do
41
- assert_equal [nil, 1, 1, nil], @merged[source_fixture('resultset2.rb')]
42
- end
35
+ should "have proper results for resultset1.rb" do
36
+ assert_equal [1, 1, 1, 1], @merged[source_fixture('resultset1.rb')]
43
37
  end
44
38
 
45
- # See Github issue #6
46
- should "return an empty hash when the resultset cache file is empty" do
47
- File.open(SimpleCov::ResultMerger.resultset_path, "w+") {|f| f.puts ""}
48
- assert_equal Hash.new, SimpleCov::ResultMerger.resultset
39
+ should "have proper results for resultset2.rb" do
40
+ assert_equal [nil, 1, 1, nil], @merged[source_fixture('resultset2.rb')]
49
41
  end
42
+ end
43
+
44
+ # See Github issue #6
45
+ should "return an empty hash when the resultset cache file is empty" do
46
+ File.open(SimpleCov::ResultMerger.resultset_path, "w+") {|f| f.puts ""}
47
+ assert_equal Hash.new, SimpleCov::ResultMerger.resultset
48
+ end
50
49
 
51
- # See Github issue #6
52
- should "return an empty hash when the resultset cache file is not present" do
50
+ # See Github issue #6
51
+ should "return an empty hash when the resultset cache file is not present" do
52
+ system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
53
+ assert_equal Hash.new, SimpleCov::ResultMerger.resultset
54
+ end
55
+
56
+ context "and results generated from those" do
57
+ setup do
53
58
  system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
54
- assert_equal Hash.new, SimpleCov::ResultMerger.resultset
59
+ @result1 = SimpleCov::Result.new(@resultset1)
60
+ @result1.command_name = "result1"
61
+ @result2 = SimpleCov::Result.new(@resultset2)
62
+ @result2.command_name = "result2"
55
63
  end
56
64
 
57
- context "and results generated from those" do
65
+ context "with stored results" do
58
66
  setup do
59
- system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
60
- @result1 = SimpleCov::Result.new(@resultset1)
61
- @result1.command_name = "result1"
62
- @result2 = SimpleCov::Result.new(@resultset2)
63
- @result2.command_name = "result2"
67
+ assert SimpleCov::ResultMerger.store_result(@result1)
68
+ assert SimpleCov::ResultMerger.store_result(@result2)
64
69
  end
65
70
 
66
- context "with stored results" do
67
- setup do
68
- assert SimpleCov::ResultMerger.store_result(@result1)
69
- assert SimpleCov::ResultMerger.store_result(@result2)
70
- end
71
+ should "have stored data in resultset_path yaml file" do
72
+ assert File.readlines(SimpleCov::ResultMerger.resultset_path).length > 50
73
+ end
71
74
 
72
- should "have stored data in resultset_path yaml file" do
73
- assert File.readlines(SimpleCov::ResultMerger.resultset_path).length > 50
74
- end
75
+ should "return a hash containing keys ['result1' and 'result2'] for resultset" do
76
+ assert_equal ['result1', 'result2'], SimpleCov::ResultMerger.resultset.keys.sort
77
+ end
75
78
 
76
- should "return a hash containing keys ['result1' and 'result2'] for resultset" do
77
- assert_equal ['result1', 'result2'], SimpleCov::ResultMerger.resultset.keys.sort
78
- end
79
+ should "return proper values for merged_result" do
80
+ assert_equal [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil], SimpleCov::ResultMerger.merged_result.source_files.find {|s| s.filename =~ /user/}.lines.map(&:coverage)
81
+ end
79
82
 
80
- should "return proper values for merged_result" do
81
- assert_equal [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil], SimpleCov::ResultMerger.merged_result.source_files.find {|s| s.filename =~ /user/}.lines.map(&:coverage)
83
+ context "with second result way above the merge_timeout" do
84
+ setup do
85
+ @result2.created_at = Time.now - 172800 # two days ago
86
+ assert SimpleCov::ResultMerger.store_result(@result2)
82
87
  end
83
88
 
84
- context "with second result way above the merge_timeout" do
85
- setup do
86
- @result2.created_at = Time.now - 172800 # two days ago
87
- assert SimpleCov::ResultMerger.store_result(@result2)
88
- end
89
-
90
- should "have only one result in SimpleCov::ResultMerger.results" do
91
- assert_equal 1, SimpleCov::ResultMerger.results.length
92
- end
89
+ should "have only one result in SimpleCov::ResultMerger.results" do
90
+ assert_equal 1, SimpleCov::ResultMerger.results.length
93
91
  end
92
+ end
94
93
 
95
- context "with merging disabled" do
96
- setup { SimpleCov.use_merging false }
94
+ context "with merging disabled" do
95
+ setup { SimpleCov.use_merging false }
97
96
 
98
- should "return nil for SimpleCov.result" do
99
- assert_nil SimpleCov.result
100
- end
97
+ should "return nil for SimpleCov.result" do
98
+ assert_nil SimpleCov.result
101
99
  end
102
100
  end
103
-
104
101
  end
102
+
105
103
  end
106
104
  end
107
- end
105
+ end if SimpleCov.usable?