simplecov 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/.rspec +3 -1
- data/.rubocop.yml +6 -5
- data/CHANGELOG.md +16 -2
- data/Gemfile +14 -14
- data/README.md +28 -12
- data/Rakefile +5 -8
- data/features/config_formatters.feature +1 -1
- data/features/config_tracked_files.feature +29 -0
- data/features/step_definitions/transformers.rb +1 -1
- data/features/support/env.rb +6 -3
- data/lib/simplecov.rb +19 -2
- data/lib/simplecov/configuration.rb +24 -4
- data/lib/simplecov/defaults.rb +28 -5
- data/lib/simplecov/file_list.rb +11 -0
- data/lib/simplecov/filter.rb +1 -1
- data/lib/simplecov/formatter/multi_formatter.rb +17 -13
- data/lib/simplecov/result.rb +1 -1
- data/lib/simplecov/source_file.rb +6 -3
- data/lib/simplecov/version.rb +1 -1
- data/spec/1_8_fallbacks_spec.rb +29 -0
- data/spec/command_guesser_spec.rb +46 -0
- data/spec/deleted_source_spec.rb +12 -0
- data/{test → spec}/faked_project/Gemfile +0 -0
- data/{test → spec}/faked_project/Rakefile +0 -0
- data/{test → spec}/faked_project/cucumber.yml +0 -0
- data/{test → spec}/faked_project/features/step_definitions/my_steps.rb +0 -0
- data/{test → spec}/faked_project/features/support/env.rb +0 -0
- data/{test → spec}/faked_project/features/test_stuff.feature +0 -0
- data/{test → spec}/faked_project/lib/faked_project.rb +1 -1
- data/{test → spec}/faked_project/lib/faked_project/framework_specific.rb +0 -0
- data/{test → spec}/faked_project/lib/faked_project/meta_magic.rb +0 -0
- data/{test → spec}/faked_project/lib/faked_project/some_class.rb +0 -0
- data/spec/faked_project/lib/faked_project/untested_class.rb +11 -0
- data/{test → spec}/faked_project/spec/faked_spec.rb +0 -0
- data/{test → spec}/faked_project/spec/forking_spec.rb +0 -0
- data/{test → spec}/faked_project/spec/meta_magic_spec.rb +0 -0
- data/{test → spec}/faked_project/spec/some_class_spec.rb +0 -0
- data/{test → spec}/faked_project/spec/spec_helper.rb +0 -0
- data/{test → spec}/faked_project/test/faked_test.rb +0 -0
- data/{test → spec}/faked_project/test/meta_magic_test.rb +0 -0
- data/{test → spec}/faked_project/test/some_class_test.rb +0 -0
- data/{test → spec}/faked_project/test/test_helper.rb +0 -0
- data/spec/file_list_spec.rb +48 -0
- data/spec/filters_spec.rb +96 -0
- data/{test → spec}/fixtures/app/controllers/sample_controller.rb +0 -0
- data/{test → spec}/fixtures/app/models/user.rb +0 -0
- data/{test → spec}/fixtures/deleted_source_sample.rb +0 -0
- data/{test → spec}/fixtures/frameworks/rspec_bad.rb +0 -0
- data/{test → spec}/fixtures/frameworks/rspec_good.rb +0 -0
- data/{test → spec}/fixtures/frameworks/testunit_bad.rb +0 -0
- data/{test → spec}/fixtures/frameworks/testunit_good.rb +0 -0
- data/{test → spec}/fixtures/iso-8859.rb +0 -0
- data/{test → spec}/fixtures/resultset1.rb +0 -0
- data/{test → spec}/fixtures/resultset2.rb +0 -0
- data/{test → spec}/fixtures/sample.rb +0 -0
- data/{test → spec}/fixtures/utf-8.rb +0 -0
- data/{test → spec}/helper.rb +3 -7
- data/spec/merge_helpers_spec.rb +108 -0
- data/spec/result_spec.rb +207 -0
- data/spec/return_codes_spec.rb +37 -0
- data/spec/source_file_line_spec.rb +153 -0
- data/spec/source_file_spec.rb +75 -0
- metadata +163 -149
- data/test/shoulda_macros.rb +0 -19
- data/test/test_1_8_fallbacks.rb +0 -31
- data/test/test_command_guesser.rb +0 -19
- data/test/test_deleted_source.rb +0 -14
- data/test/test_file_list.rb +0 -23
- data/test/test_filters.rb +0 -94
- data/test/test_merge_helpers.rb +0 -112
- data/test/test_result.rb +0 -175
- data/test/test_return_codes.rb +0 -41
- data/test/test_source_file.rb +0 -73
- data/test/test_source_file_line.rb +0 -106
data/test/test_1_8_fallbacks.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
# Tests that verify that on 1.8 versions of ruby, simplecov simply
|
4
|
-
# does not launch and does not cause errors on the way
|
5
|
-
#
|
6
|
-
# TODO: This should be expanded upon all methods that could potentially
|
7
|
-
# be called in a test/spec-helper simplecov config block
|
8
|
-
#
|
9
|
-
class Test18FallBacks < Minitest::Test
|
10
|
-
should "return false when calling SimpleCov.start" do
|
11
|
-
assert_equal false, SimpleCov.start
|
12
|
-
end
|
13
|
-
|
14
|
-
should "return false when calling SimpleCov.start with a block" do
|
15
|
-
assert_equal false, SimpleCov.start { fail "Shouldn't reach this!?" }
|
16
|
-
end
|
17
|
-
|
18
|
-
should "return false when calling SimpleCov.configure with a block" do
|
19
|
-
assert_equal false, SimpleCov.configure { fail "Shouldn't reach this!?" }
|
20
|
-
end
|
21
|
-
|
22
|
-
should "allow to define a profile" do
|
23
|
-
begin
|
24
|
-
SimpleCov.profiles.define "testprofile" do
|
25
|
-
add_filter "/config/"
|
26
|
-
end
|
27
|
-
rescue => err
|
28
|
-
assert false, "Profile definition should have been fine, but raised #{err}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end if RUBY_VERSION.start_with? "1.8"
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestCommandGuesser < Minitest::Test
|
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
|
9
|
-
end
|
10
|
-
end
|
11
|
-
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?
|
data/test/test_deleted_source.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
# Test to verify correct handling of deleted files,
|
4
|
-
# see issue #9 on github
|
5
|
-
class TestDeletedSource < Minitest::Test
|
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
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/test/test_file_list.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestFileList < Minitest::Test
|
4
|
-
context "With a file list from a result" do
|
5
|
-
setup do
|
6
|
-
original_result = {
|
7
|
-
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, 2, 2, 0, nil, nil, 0, nil, nil, nil],
|
10
|
-
}
|
11
|
-
@file_list = SimpleCov::Result.new(original_result).files
|
12
|
-
end
|
13
|
-
|
14
|
-
should("have 11 covered_lines") { assert_equal 11, @file_list.covered_lines }
|
15
|
-
should("have 3 missed_lines") { assert_equal 3, @file_list.missed_lines }
|
16
|
-
should("have 19 never_lines") { assert_equal 19, @file_list.never_lines }
|
17
|
-
should("have 14 lines_of_code") { assert_equal 14, @file_list.lines_of_code }
|
18
|
-
should("have 3 skipped_lines") { assert_equal 3, @file_list.skipped_lines }
|
19
|
-
|
20
|
-
should("have correct covered_percent") { assert_equal 100.0 * 11 / 14, @file_list.covered_percent }
|
21
|
-
should("have correct covered_strength") { assert_equal 13.to_f / 14, @file_list.covered_strength }
|
22
|
-
end
|
23
|
-
end if SimpleCov.usable?
|
data/test/test_filters.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestFilters < Minitest::Test
|
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
|
8
|
-
|
9
|
-
should "not match a new SimpleCov::StringFilter 'foobar'" do
|
10
|
-
assert !SimpleCov::StringFilter.new("foobar").matches?(@source_file)
|
11
|
-
end
|
12
|
-
|
13
|
-
should "not match a new SimpleCov::StringFilter 'some/path'" do
|
14
|
-
assert !SimpleCov::StringFilter.new("some/path").matches?(@source_file)
|
15
|
-
end
|
16
|
-
|
17
|
-
should "match a new SimpleCov::StringFilter 'test/fixtures'" do
|
18
|
-
assert SimpleCov::StringFilter.new("test/fixtures").matches?(@source_file)
|
19
|
-
end
|
20
|
-
|
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
|
24
|
-
|
25
|
-
should "match a new SimpleCov::StringFilter 'sample.rb'" do
|
26
|
-
assert SimpleCov::StringFilter.new("sample.rb").matches?(@source_file)
|
27
|
-
end
|
28
|
-
|
29
|
-
should "not match a new SimpleCov::BlockFilter that is not applicable" do
|
30
|
-
assert !SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "foo.rb" }).matches?(@source_file)
|
31
|
-
end
|
32
|
-
|
33
|
-
should "match a new SimpleCov::BlockFilter that is applicable" do
|
34
|
-
assert SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "sample.rb" }).matches?(@source_file)
|
35
|
-
end
|
36
|
-
|
37
|
-
should "match a new SimpleCov::ArrayFilter when 'sample.rb' is passed as array" do
|
38
|
-
assert SimpleCov::ArrayFilter.new(["sample.rb"]).matches?(@source_file)
|
39
|
-
end
|
40
|
-
|
41
|
-
should "not match a new SimpleCov::ArrayFilter when a file path different than 'sample.rb' is passed as array" do
|
42
|
-
assert !SimpleCov::ArrayFilter.new(["other_file.rb"]).matches?(@source_file)
|
43
|
-
end
|
44
|
-
|
45
|
-
should "match a new SimpleCov::ArrayFilter when two file paths including 'sample.rb' are passed as array" do
|
46
|
-
assert SimpleCov::ArrayFilter.new(["sample.rb", "other_file.rb"]).matches?(@source_file)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "with no filters set up and a basic source file in an array" do
|
51
|
-
setup do
|
52
|
-
@prev_filters, SimpleCov.filters = SimpleCov.filters, []
|
53
|
-
@files = [SimpleCov::SourceFile.new(source_fixture("sample.rb"), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])]
|
54
|
-
end
|
55
|
-
|
56
|
-
teardown do
|
57
|
-
SimpleCov.filters = @prev_filters
|
58
|
-
end
|
59
|
-
|
60
|
-
should "return 0 items after executing SimpleCov.filtered on files when using a 'sample' string filter" do
|
61
|
-
SimpleCov.add_filter "sample"
|
62
|
-
assert_equal 0, SimpleCov.filtered(@files).count
|
63
|
-
end
|
64
|
-
|
65
|
-
should "return 0 items after executing SimpleCov.filtered on files when using a 'test/fixtures/' string filter" do
|
66
|
-
SimpleCov.add_filter "test/fixtures"
|
67
|
-
assert_equal 0, SimpleCov.filtered(@files).count
|
68
|
-
end
|
69
|
-
|
70
|
-
should "return 1 item after executing SimpleCov.filtered on files when using a 'fooo' string filter" do
|
71
|
-
SimpleCov.add_filter "fooo"
|
72
|
-
assert_equal 1, SimpleCov.filtered(@files).count
|
73
|
-
end
|
74
|
-
|
75
|
-
should "return 0 items after executing SimpleCov.filtered on files when using a block filter that returns true" do
|
76
|
-
SimpleCov.add_filter do
|
77
|
-
true
|
78
|
-
end
|
79
|
-
assert_equal 0, SimpleCov.filtered(@files).count
|
80
|
-
end
|
81
|
-
|
82
|
-
should "return 1 item after executing SimpleCov.filtered on files when using an always-false block filter" do
|
83
|
-
SimpleCov.add_filter do
|
84
|
-
false
|
85
|
-
end
|
86
|
-
assert_equal 1, SimpleCov.filtered(@files).count
|
87
|
-
end
|
88
|
-
|
89
|
-
should "return a FileList after filtering" do
|
90
|
-
SimpleCov.add_filter "fooo"
|
91
|
-
assert_equal SimpleCov::FileList, SimpleCov.filtered(@files).class
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end if SimpleCov.usable?
|
data/test/test_merge_helpers.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestMergeHelpers < Minitest::Test
|
4
|
-
def self.test_order
|
5
|
-
:alpha
|
6
|
-
end
|
7
|
-
|
8
|
-
context "With two faked coverage resultsets" do
|
9
|
-
setup do
|
10
|
-
SimpleCov.use_merging true
|
11
|
-
@resultset1 = {
|
12
|
-
source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
13
|
-
source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
14
|
-
source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
15
|
-
source_fixture("resultset1.rb") => [1, 1, 1, 1],
|
16
|
-
}
|
17
|
-
|
18
|
-
@resultset2 = {
|
19
|
-
source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
|
20
|
-
source_fixture("app/models/user.rb") => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
|
21
|
-
source_fixture("app/controllers/sample_controller.rb") => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
|
22
|
-
source_fixture("resultset2.rb") => [nil, 1, 1, nil],
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
context "a merge" do
|
27
|
-
setup do
|
28
|
-
assert @merged = @resultset1.merge_resultset(@resultset2)
|
29
|
-
end
|
30
|
-
|
31
|
-
should "have proper results for sample.rb" do
|
32
|
-
assert_equal [1, 1, 2, 2, nil, nil, 2, 2, nil, nil], @merged[source_fixture("sample.rb")]
|
33
|
-
end
|
34
|
-
|
35
|
-
should "have proper results for user.rb" do
|
36
|
-
assert_equal [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil], @merged[source_fixture("app/models/user.rb")]
|
37
|
-
end
|
38
|
-
|
39
|
-
should "have proper results for sample_controller.rb" do
|
40
|
-
assert_equal [nil, 4, 2, 1, nil, nil, 2, 0, nil, nil], @merged[source_fixture("app/controllers/sample_controller.rb")]
|
41
|
-
end
|
42
|
-
|
43
|
-
should "have proper results for resultset1.rb" do
|
44
|
-
assert_equal [1, 1, 1, 1], @merged[source_fixture("resultset1.rb")]
|
45
|
-
end
|
46
|
-
|
47
|
-
should "have proper results for resultset2.rb" do
|
48
|
-
assert_equal [nil, 1, 1, nil], @merged[source_fixture("resultset2.rb")]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# See Github issue #6
|
53
|
-
should "return an empty hash when the resultset cache file is empty" do
|
54
|
-
File.open(SimpleCov::ResultMerger.resultset_path, "w+") { |f| f.puts "" }
|
55
|
-
assert_empty SimpleCov::ResultMerger.resultset
|
56
|
-
end
|
57
|
-
|
58
|
-
# See Github issue #6
|
59
|
-
should "return an empty hash when the resultset cache file is not present" do
|
60
|
-
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
|
61
|
-
assert_empty SimpleCov::ResultMerger.resultset
|
62
|
-
end
|
63
|
-
|
64
|
-
context "and results generated from those" do
|
65
|
-
setup do
|
66
|
-
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
|
67
|
-
@result1 = SimpleCov::Result.new(@resultset1)
|
68
|
-
@result1.command_name = "result1"
|
69
|
-
@result2 = SimpleCov::Result.new(@resultset2)
|
70
|
-
@result2.command_name = "result2"
|
71
|
-
end
|
72
|
-
|
73
|
-
context "with stored results" do
|
74
|
-
setup do
|
75
|
-
assert SimpleCov::ResultMerger.store_result(@result1)
|
76
|
-
assert SimpleCov::ResultMerger.store_result(@result2)
|
77
|
-
end
|
78
|
-
|
79
|
-
should "have stored data in resultset_path JSON file" do
|
80
|
-
assert File.readlines(SimpleCov::ResultMerger.resultset_path).length > 50
|
81
|
-
end
|
82
|
-
|
83
|
-
should "return a hash containing keys ['result1' and 'result2'] for resultset" do
|
84
|
-
assert_equal %w(result1 result2), SimpleCov::ResultMerger.resultset.keys.sort
|
85
|
-
end
|
86
|
-
|
87
|
-
should "return proper values for merged_result" do
|
88
|
-
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)
|
89
|
-
end
|
90
|
-
|
91
|
-
context "with second result way above the merge_timeout" do
|
92
|
-
setup do
|
93
|
-
@result2.created_at = Time.now - 172_800 # two days ago
|
94
|
-
assert SimpleCov::ResultMerger.store_result(@result2)
|
95
|
-
end
|
96
|
-
|
97
|
-
should "have only one result in SimpleCov::ResultMerger.results" do
|
98
|
-
assert_equal 1, SimpleCov::ResultMerger.results.length
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context "with merging disabled" do
|
103
|
-
setup { SimpleCov.use_merging false }
|
104
|
-
|
105
|
-
should "return nil for SimpleCov.result" do
|
106
|
-
assert_nil SimpleCov.result
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end if SimpleCov.usable?
|
data/test/test_result.rb
DELETED
@@ -1,175 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestResult < Minitest::Test # rubocop:disable Metrics/ClassLength
|
4
|
-
context "With a (mocked) Coverage.result" do
|
5
|
-
setup do
|
6
|
-
@prev_filters, SimpleCov.filters = SimpleCov.filters, []
|
7
|
-
@prev_groups, SimpleCov.groups = SimpleCov.groups, {}
|
8
|
-
@prev_formatter, SimpleCov.formatter = SimpleCov.formatter, nil
|
9
|
-
|
10
|
-
@original_result = {
|
11
|
-
source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
12
|
-
source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
13
|
-
source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
teardown do
|
18
|
-
SimpleCov.filters = @prev_filters
|
19
|
-
SimpleCov.groups = @prev_groups
|
20
|
-
SimpleCov.formatter = @prev_formatter
|
21
|
-
end
|
22
|
-
|
23
|
-
context "a simple cov result initialized from that" do
|
24
|
-
setup { @result = SimpleCov::Result.new(@original_result) }
|
25
|
-
|
26
|
-
should "have 3 filenames" do
|
27
|
-
assert_equal 3, @result.filenames.count
|
28
|
-
end
|
29
|
-
|
30
|
-
should "have 3 source files" do
|
31
|
-
assert_equal 3, @result.source_files.count
|
32
|
-
assert @result.source_files.all? { |s| s.instance_of?(SimpleCov::SourceFile) }, "Not all instances are of SimpleCov::SourceFile type"
|
33
|
-
end
|
34
|
-
|
35
|
-
should "return an instance of SimpleCov::FileList for source_files and files" do
|
36
|
-
assert_equal SimpleCov::FileList, @result.source_files.class
|
37
|
-
assert_equal SimpleCov::FileList, @result.files.class
|
38
|
-
end
|
39
|
-
|
40
|
-
should "have files equal to source_files" do
|
41
|
-
assert_equal @result.files, @result.source_files
|
42
|
-
end
|
43
|
-
|
44
|
-
should "have accurate covered percent" do
|
45
|
-
# in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil)
|
46
|
-
assert_equal 100.0 * 13 / 15, @result.covered_percent
|
47
|
-
end
|
48
|
-
|
49
|
-
[:covered_percent, :covered_strength, :covered_lines, :missed_lines, :total_lines].each do |msg|
|
50
|
-
should "respond to #{msg}" do
|
51
|
-
assert @result.respond_to? msg
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "dumped with to_hash" do
|
56
|
-
setup { @hash = @result.to_hash }
|
57
|
-
should("be a hash") { assert_equal Hash, @hash.class }
|
58
|
-
|
59
|
-
context "loaded back with from_hash" do
|
60
|
-
setup { @dumped_result = SimpleCov::Result.from_hash(@hash) }
|
61
|
-
|
62
|
-
should "have 3 source files" do
|
63
|
-
assert_equal @result.source_files.count, @dumped_result.source_files.count
|
64
|
-
end
|
65
|
-
|
66
|
-
should "have the same covered_percent" do
|
67
|
-
assert_equal @result.covered_percent, @dumped_result.covered_percent
|
68
|
-
end
|
69
|
-
|
70
|
-
should "have the same timestamp" do
|
71
|
-
assert_equal @result.created_at.to_i, @dumped_result.created_at.to_i
|
72
|
-
end
|
73
|
-
|
74
|
-
should "have the same command_name" do
|
75
|
-
assert_equal @result.command_name, @dumped_result.command_name
|
76
|
-
end
|
77
|
-
|
78
|
-
should "have the same original_result" do
|
79
|
-
assert_equal @result.original_result, @dumped_result.original_result
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "with some filters set up" do
|
86
|
-
setup do
|
87
|
-
SimpleCov.add_filter "sample.rb"
|
88
|
-
end
|
89
|
-
|
90
|
-
should "have 2 files in a new simple cov result" do
|
91
|
-
assert_equal 2, SimpleCov::Result.new(@original_result).source_files.length
|
92
|
-
end
|
93
|
-
|
94
|
-
should "have 80 covered percent" do
|
95
|
-
assert_equal 80, SimpleCov::Result.new(@original_result).covered_percent
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "with groups set up for all files" do
|
100
|
-
setup do
|
101
|
-
SimpleCov.add_group "Models", "app/models"
|
102
|
-
SimpleCov.add_group "Controllers", ["app/controllers"]
|
103
|
-
SimpleCov.add_group "Other" do |src_file|
|
104
|
-
File.basename(src_file.filename) == "sample.rb"
|
105
|
-
end
|
106
|
-
@result = SimpleCov::Result.new(@original_result)
|
107
|
-
end
|
108
|
-
|
109
|
-
should "have 3 groups" do
|
110
|
-
assert_equal 3, @result.groups.length
|
111
|
-
end
|
112
|
-
|
113
|
-
should "have user.rb in 'Models' group" do
|
114
|
-
assert_equal "user.rb", File.basename(@result.groups["Models"].first.filename)
|
115
|
-
end
|
116
|
-
|
117
|
-
should "have sample_controller.rb in 'Controllers' group" do
|
118
|
-
assert_equal "sample_controller.rb", File.basename(@result.groups["Controllers"].first.filename)
|
119
|
-
end
|
120
|
-
|
121
|
-
context "and simple formatter being used" do
|
122
|
-
setup { SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter }
|
123
|
-
|
124
|
-
should "return a formatted string with result.format!" do
|
125
|
-
assert_equal String, @result.format!.class
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context "and multi formatter being used" do
|
130
|
-
setup do
|
131
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
132
|
-
SimpleCov::Formatter::SimpleFormatter,
|
133
|
-
SimpleCov::Formatter::SimpleFormatter,
|
134
|
-
]
|
135
|
-
end
|
136
|
-
|
137
|
-
should "return an array containing formatted string with result.format!" do
|
138
|
-
formated = @result.format!
|
139
|
-
assert_equal 2, formated.count
|
140
|
-
assert_equal String, formated.first.class
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context "with groups set up that do not match all files" do
|
146
|
-
setup do
|
147
|
-
SimpleCov.configure do
|
148
|
-
add_group "Models", "app/models"
|
149
|
-
add_group "Controllers", "app/controllers"
|
150
|
-
end
|
151
|
-
@result = SimpleCov::Result.new(@original_result)
|
152
|
-
end
|
153
|
-
|
154
|
-
should "have 3 groups" do
|
155
|
-
assert_equal 3, @result.groups.length
|
156
|
-
end
|
157
|
-
|
158
|
-
should "have 1 item per group" do
|
159
|
-
@result.groups.each do |name, files|
|
160
|
-
assert_equal 1, files.length, "Group #{name} should have 1 file"
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
should "have sample.rb in 'Ungrouped' group" do
|
165
|
-
assert_equal "sample.rb", File.basename(@result.groups["Ungrouped"].first.filename)
|
166
|
-
end
|
167
|
-
|
168
|
-
should "return all groups as instances of SimpleCov::FileList" do
|
169
|
-
@result.groups.each_value do |files|
|
170
|
-
assert_equal SimpleCov::FileList, files.class
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end if SimpleCov.usable?
|