simplecov 0.7.1 → 0.8.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +9 -2
- data/CHANGELOG.md +17 -2
- data/Gemfile +13 -2
- data/{LICENSE → MIT-LICENSE} +0 -0
- data/README.md +174 -117
- data/Rakefile +8 -3
- data/features/config_command_name.feature +12 -0
- data/features/config_merge_timeout.feature +3 -3
- data/features/config_profiles.feature +44 -0
- data/features/config_project_name.feature +2 -2
- data/features/cucumber_basic.feature +1 -1
- data/features/step_definitions/html_steps.rb +1 -1
- data/features/support/env.rb +23 -5
- data/gemfiles/multi_json_legacy.gemfile +12 -0
- data/gemfiles/multi_json_new.gemfile +12 -0
- data/lib/simplecov.rb +33 -25
- data/lib/simplecov/command_guesser.rb +6 -6
- data/lib/simplecov/configuration.rb +7 -2
- data/lib/simplecov/defaults.rb +9 -5
- data/lib/simplecov/file_list.rb +1 -1
- data/lib/simplecov/jruby16_fix.rb +43 -0
- data/lib/simplecov/no_defaults.rb +2 -0
- data/lib/simplecov/{adapters.rb → profiles.rb} +8 -8
- data/lib/simplecov/result.rb +10 -2
- data/lib/simplecov/source_file.rb +2 -3
- data/lib/simplecov/version.rb +1 -1
- data/simplecov.gemspec +8 -9
- data/test/faked_project/Gemfile +1 -1
- data/test/helper.rb +0 -1
- data/test/shoulda_macros.rb +0 -10
- data/test/test_1_8_fallbacks.rb +16 -18
- data/test/test_command_guesser.rb +13 -15
- data/test/test_deleted_source.rb +5 -7
- data/test/test_file_list.rb +15 -17
- data/test/test_filters.rb +56 -58
- data/test/test_merge_helpers.rb +73 -75
- data/test/test_result.rb +114 -116
- data/test/test_return_codes.rb +24 -26
- data/test/test_source_file.rb +75 -64
- data/test/test_source_file_line.rb +78 -82
- metadata +38 -86
- data/features/config_adapters.feature +0 -44
- data/gemfiles/multi_json-legacy.gemfile +0 -7
- data/gemfiles/multi_json-new.gemfile +0 -7
@@ -1,29 +1,29 @@
|
|
1
1
|
#
|
2
|
-
#
|
2
|
+
# Profiles are SimpleCov configuration procs that can be easily
|
3
3
|
# loaded using SimpleCov.start :rails and defined using
|
4
|
-
# SimpleCov.
|
4
|
+
# SimpleCov.profiles.define :foo do
|
5
5
|
# # SimpleCov configuration here, same as in SimpleCov.configure
|
6
6
|
# end
|
7
7
|
#
|
8
|
-
class SimpleCov::
|
8
|
+
class SimpleCov::Profiles < Hash
|
9
9
|
#
|
10
|
-
# Define a SimpleCov
|
11
|
-
# SimpleCov.
|
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
|
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
|
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
|
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
|
data/lib/simplecov/result.rb
CHANGED
@@ -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.
|
23
|
-
|
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, "
|
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
|
|
data/lib/simplecov/version.rb
CHANGED
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'
|
16
|
+
gem.add_dependency 'multi_json'
|
16
17
|
gem.add_dependency 'simplecov-html', '~> 0.7.1'
|
17
|
-
|
18
|
-
gem.add_development_dependency '
|
19
|
-
gem.add_development_dependency '
|
20
|
-
gem.add_development_dependency '
|
21
|
-
gem.add_development_dependency '
|
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")
|
data/test/faked_project/Gemfile
CHANGED
data/test/helper.rb
CHANGED
data/test/shoulda_macros.rb
CHANGED
@@ -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)
|
data/test/test_1_8_fallbacks.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
10
|
+
should "return false when calling SimpleCov.start" do
|
11
|
+
assert_equal false, SimpleCov.start
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
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?
|
data/test/test_deleted_source.rb
CHANGED
@@ -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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
data/test/test_file_list.rb
CHANGED
@@ -1,24 +1,22 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestFileList < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
9
|
+
should "not match a new SimpleCov::StringFilter 'foobar'" do
|
10
|
+
assert !SimpleCov::StringFilter.new('foobar').matches?(@source_file)
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
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?
|
data/test/test_merge_helpers.rb
CHANGED
@@ -1,107 +1,105 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestMergeHelpers < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
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
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
41
|
-
|
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
|
-
|
46
|
-
|
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
|
-
|
52
|
-
|
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
|
-
|
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 "
|
65
|
+
context "with stored results" do
|
58
66
|
setup do
|
59
|
-
|
60
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
81
|
-
|
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
|
-
|
85
|
-
|
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
|
-
|
96
|
-
|
94
|
+
context "with merging disabled" do
|
95
|
+
setup { SimpleCov.use_merging false }
|
97
96
|
|
98
|
-
|
99
|
-
|
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?
|