simplecov 0.4.2 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/.rvmrc +1 -1
- data/.travis.yml +9 -0
- data/CHANGELOG.md +64 -0
- data/Gemfile +7 -0
- data/README.rdoc +83 -66
- data/Rakefile +3 -7
- data/cucumber.yml +13 -0
- data/features/config_adapters.feature +44 -0
- data/features/config_autoload.feature +46 -0
- data/features/config_command_name.feature +33 -0
- data/features/config_coverage_dir.feature +20 -0
- data/features/config_deactivate_merging.feature +42 -0
- data/features/config_merge_timeout.feature +38 -0
- data/features/config_project_name.feature +27 -0
- data/features/config_styles.feature +93 -0
- data/features/cucumber_basic.feature +29 -0
- data/features/merging_test_unit_and_rspec.feature +44 -0
- data/features/rspec_basic.feature +31 -0
- data/features/rspec_groups_and_filters_basic.feature +29 -0
- data/features/rspec_groups_and_filters_complex.feature +35 -0
- data/features/rspec_without_simplecov.feature +20 -0
- data/features/step_definitions/html_steps.rb +42 -0
- data/features/step_definitions/simplecov_steps.rb +61 -0
- data/features/step_definitions/transformers.rb +13 -0
- data/features/step_definitions/web_steps.rb +64 -0
- data/features/support/env.rb +26 -0
- data/features/test_unit_basic.feature +34 -0
- data/features/test_unit_groups_and_filters_basic.feature +29 -0
- data/features/test_unit_groups_and_filters_complex.feature +35 -0
- data/features/test_unit_without_simplecov.feature +20 -0
- data/lib/simplecov.rb +15 -30
- data/lib/simplecov/adapters.rb +3 -26
- data/lib/simplecov/command_guesser.rb +2 -2
- data/lib/simplecov/configuration.rb +21 -21
- data/lib/simplecov/defaults.rb +48 -0
- data/lib/simplecov/file_list.rb +44 -0
- data/lib/simplecov/filter.rb +5 -5
- data/lib/simplecov/formatter.rb +1 -1
- data/lib/simplecov/formatter/simple_formatter.rb +1 -1
- data/lib/simplecov/jruby_float_fix.rb +1 -1
- data/lib/simplecov/merge_helpers.rb +4 -4
- data/lib/simplecov/result.rb +33 -30
- data/lib/simplecov/result_merger.rb +30 -13
- data/lib/simplecov/source_file.rb +78 -21
- data/lib/simplecov/version.rb +1 -1
- data/simplecov.gemspec +25 -22
- data/test/faked_project/Gemfile +6 -0
- data/test/faked_project/Rakefile +8 -0
- data/test/faked_project/cucumber.yml +13 -0
- data/test/faked_project/features/step_definitions/my_steps.rb +23 -0
- data/test/faked_project/features/support/env.rb +12 -0
- data/test/faked_project/features/test_stuff.feature +6 -0
- data/test/faked_project/lib/faked_project.rb +11 -0
- data/test/faked_project/lib/faked_project/framework_specific.rb +18 -0
- data/test/faked_project/lib/faked_project/meta_magic.rb +24 -0
- data/test/faked_project/lib/faked_project/some_class.rb +29 -0
- data/test/faked_project/spec/faked_spec.rb +11 -0
- data/test/faked_project/spec/meta_magic_spec.rb +10 -0
- data/test/faked_project/spec/some_class_spec.rb +10 -0
- data/test/faked_project/spec/spec_helper.rb +15 -0
- data/test/faked_project/test/faked_test.rb +11 -0
- data/test/faked_project/test/meta_magic_test.rb +13 -0
- data/test/faked_project/test/some_class_test.rb +15 -0
- data/test/faked_project/test/test_helper.rb +16 -0
- data/test/fixtures/app/controllers/sample_controller.rb +2 -2
- data/test/fixtures/app/models/user.rb +2 -2
- data/test/fixtures/frameworks/rspec_bad.rb +1 -1
- data/test/fixtures/frameworks/rspec_good.rb +1 -1
- data/test/fixtures/frameworks/testunit_bad.rb +1 -1
- data/test/fixtures/frameworks/testunit_good.rb +1 -1
- data/test/fixtures/resultset1.rb +1 -1
- data/test/fixtures/resultset2.rb +1 -1
- data/test/fixtures/sample.rb +8 -2
- data/test/helper.rb +17 -4
- data/test/shoulda_macros.rb +2 -2
- data/test/test_1_8_fallbacks.rb +3 -3
- data/test/test_command_guesser.rb +3 -3
- data/test/test_file_list.rb +24 -0
- data/test/test_filters.rb +18 -13
- data/test/test_merge_helpers.rb +23 -23
- data/test/test_result.rb +40 -31
- data/test/test_return_codes.rb +5 -5
- data/test/test_source_file.rb +39 -15
- data/test/test_source_file_line.rb +22 -22
- metadata +191 -53
- data/.document +0 -5
@@ -9,12 +9,12 @@ class TestCommandGuesser < Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
should_guess_command_name "Unit Tests", '/some/path/test/units/foo_bar_test.rb', 'test/units/foo.rb', 'test/foo.rb'
|
14
14
|
should_guess_command_name "Functional Tests", '/some/path/test/functional/foo_bar_controller_test.rb'
|
15
|
-
should_guess_command_name "Integration Tests", '/some/path/test/integration/foo_bar_controller_test.rb'
|
15
|
+
should_guess_command_name "Integration Tests", '/some/path/test/integration/foo_bar_controller_test.rb'
|
16
16
|
should_guess_command_name "Cucumber Features", 'features', 'cucumber', 'cucumber features'
|
17
17
|
should_guess_command_name "RSpec", '/some/path/spec/foo.rb'
|
18
18
|
should_guess_command_name "some_arbitrary_command with arguments", 'some_arbitrary_command with arguments'
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
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
|
12
|
+
|
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 }
|
18
|
+
|
19
|
+
should "have correct covered_percent" do
|
20
|
+
assert_equal 100.0*13/15, @file_list.covered_percent
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/test/test_filters.rb
CHANGED
@@ -6,70 +6,75 @@ class TestFilters < Test::Unit::TestCase
|
|
6
6
|
setup do
|
7
7
|
@source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
should "pass a new SimpleCov::StringFilter 'foobar'" do
|
11
11
|
assert SimpleCov::StringFilter.new('foobar').passes?(@source_file)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
should "pass a new SimpleCov::StringFilter 'some/path'" do
|
15
15
|
assert SimpleCov::StringFilter.new('some/path').passes?(@source_file)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
should "not pass a new SimpleCov::StringFilter 'test/fixtures'" do
|
19
19
|
assert !SimpleCov::StringFilter.new('test/fixtures').passes?(@source_file)
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
should "not pass a new SimpleCov::StringFilter 'test/fixtures/sample.rb'" do
|
23
23
|
assert !SimpleCov::StringFilter.new('test/fixtures/sample.rb').passes?(@source_file)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
should "not pass a new SimpleCov::StringFilter 'sample.rb'" do
|
27
27
|
assert !SimpleCov::StringFilter.new('sample.rb').passes?(@source_file)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
should "pass a new SimpleCov::BlockFilter that is not applicable" do
|
31
31
|
assert SimpleCov::BlockFilter.new(Proc.new {|s| File.basename(s.filename) == 'foo.rb'}).passes?(@source_file)
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
should "not pass a new SimpleCov::BlockFilter that is applicable" do
|
35
35
|
assert !SimpleCov::BlockFilter.new(Proc.new {|s| File.basename(s.filename) == 'sample.rb'}).passes?(@source_file)
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
context "with no filters set up and a basic source file in an array" do
|
40
40
|
setup do
|
41
41
|
SimpleCov.filters = []
|
42
42
|
@files = [SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])]
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
should "return 0 items after executing SimpleCov.filtered on files when using a 'sample' string filter" do
|
46
46
|
SimpleCov.add_filter "sample"
|
47
47
|
assert_equal 0, SimpleCov.filtered(@files).count
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
should "return 0 items after executing SimpleCov.filtered on files when using a 'test/fixtures/' string filter" do
|
51
51
|
SimpleCov.add_filter "test/fixtures"
|
52
52
|
assert_equal 0, SimpleCov.filtered(@files).count
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
should "return 1 item after executing SimpleCov.filtered on files when using a 'fooo' string filter" do
|
56
56
|
SimpleCov.add_filter "fooo"
|
57
57
|
assert_equal 1, SimpleCov.filtered(@files).count
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
should "return 0 items after executing SimpleCov.filtered on files when using a block filter that returns true" do
|
61
61
|
SimpleCov.add_filter do |src_file|
|
62
62
|
true
|
63
63
|
end
|
64
64
|
assert_equal 0, SimpleCov.filtered(@files).count
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
should "return 1 item after executing SimpleCov.filtered on files when using an always-false block filter" do
|
68
68
|
SimpleCov.add_filter do |src_file|
|
69
69
|
false
|
70
70
|
end
|
71
71
|
assert_equal 1, SimpleCov.filtered(@files).count
|
72
72
|
end
|
73
|
+
|
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
78
|
end
|
74
79
|
end
|
75
80
|
end
|
data/test/test_merge_helpers.rb
CHANGED
@@ -9,51 +9,51 @@ class TestMergeHelpers < Test::Unit::TestCase
|
|
9
9
|
source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
10
10
|
source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
11
11
|
source_fixture('resultset1.rb') => [1, 1, 1, 1]}
|
12
|
-
|
12
|
+
|
13
13
|
@resultset2 = {source_fixture('sample.rb') => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
|
14
14
|
source_fixture('app/models/user.rb') => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
|
15
15
|
source_fixture('app/controllers/sample_controller.rb') => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
|
16
16
|
source_fixture('resultset2.rb') => [nil, 1, 1, nil]}
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
context "a merge" do
|
20
20
|
setup do
|
21
21
|
assert @merged = @resultset1.merge_resultset(@resultset2)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
should "have proper results for sample.rb" do
|
25
25
|
assert_equal [1, 1, 2, 2, nil, nil, 2, 2, nil, nil], @merged[source_fixture('sample.rb')]
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
should "have proper results for user.rb" do
|
29
29
|
assert_equal [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil], @merged[source_fixture('app/models/user.rb')]
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
should "have proper results for sample_controller.rb" do
|
33
33
|
assert_equal [nil, 4, 2, 1, nil, nil, 2, 0, nil, nil], @merged[source_fixture('app/controllers/sample_controller.rb')]
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
should "have proper results for resultset1.rb" do
|
37
37
|
assert_equal [1, 1, 1, 1], @merged[source_fixture('resultset1.rb')]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
should "have proper results for resultset2.rb" do
|
41
41
|
assert_equal [nil, 1, 1, nil], @merged[source_fixture('resultset2.rb')]
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# See Github issue #6
|
46
46
|
should "return an empty hash when the resultset cache file is empty" do
|
47
47
|
File.open(SimpleCov::ResultMerger.resultset_path, "w+") {|f| f.puts ""}
|
48
|
-
assert_equal Hash.new, SimpleCov::ResultMerger.resultset
|
48
|
+
assert_equal Hash.new, SimpleCov::ResultMerger.resultset
|
49
49
|
end
|
50
50
|
|
51
|
-
# See Github issue #6
|
51
|
+
# See Github issue #6
|
52
52
|
should "return an empty hash when the resultset cache file is not present" do
|
53
53
|
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
|
54
|
-
assert_equal Hash.new, SimpleCov::ResultMerger.resultset
|
54
|
+
assert_equal Hash.new, SimpleCov::ResultMerger.resultset
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
context "and results generated from those" do
|
58
58
|
setup do
|
59
59
|
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
|
@@ -62,46 +62,46 @@ class TestMergeHelpers < Test::Unit::TestCase
|
|
62
62
|
@result2 = SimpleCov::Result.new(@resultset2)
|
63
63
|
@result2.command_name = "result2"
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
context "with stored results" do
|
67
67
|
setup do
|
68
68
|
assert SimpleCov::ResultMerger.store_result(@result1)
|
69
69
|
assert SimpleCov::ResultMerger.store_result(@result2)
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
should "have stored data in resultset_path yaml file" do
|
73
73
|
assert File.readlines(SimpleCov::ResultMerger.resultset_path).length > 50
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
should "return a hash containing keys ['result1' and 'result2'] for resultset" do
|
77
77
|
assert_equal ['result1', 'result2'], SimpleCov::ResultMerger.resultset.keys.sort
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
should "return proper values for merged_result" do
|
81
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)
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
context "with second result way above the merge_timeout" do
|
85
|
-
setup do
|
85
|
+
setup do
|
86
86
|
@result2.created_at = Time.now - 172800 # two days ago
|
87
87
|
assert SimpleCov::ResultMerger.store_result(@result2)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
should "have only one result in SimpleCov::ResultMerger.results" do
|
91
91
|
assert_equal 1, SimpleCov::ResultMerger.results.length
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
context "with merging disabled" do
|
96
96
|
setup { SimpleCov.use_merging false }
|
97
|
-
|
97
|
+
|
98
98
|
should "return nil for SimpleCov.result" do
|
99
99
|
assert_nil SimpleCov.result
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
107
|
-
end
|
107
|
+
end
|
data/test/test_result.rb
CHANGED
@@ -11,74 +11,77 @@ class TestResult < Test::Unit::TestCase
|
|
11
11
|
source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
12
12
|
source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]}
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
context "a simple cov result initialized from that" do
|
16
16
|
setup { @result = SimpleCov::Result.new(@original_result) }
|
17
|
-
|
17
|
+
|
18
18
|
should "have 3 filenames" do
|
19
19
|
assert_equal 3, @result.filenames.count
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
should "have 3 source files" do
|
23
23
|
assert_equal 3, @result.source_files.count
|
24
24
|
assert @result.source_files.all? {|s| s.instance_of?(SimpleCov::SourceFile)}, "Not alL instances are of SimpleCov::SourceFile type"
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
should "return an instance of SimpleCov::FileList for source_files and files" do
|
28
|
+
assert_equal SimpleCov::FileList, @result.source_files.class
|
29
|
+
assert_equal SimpleCov::FileList, @result.files.class
|
30
|
+
end
|
31
|
+
|
27
32
|
should "have files equal to source_files" do
|
28
33
|
assert_equal @result.files, @result.source_files
|
29
34
|
end
|
30
|
-
|
35
|
+
|
31
36
|
should "have accurate covered percent" do
|
32
37
|
# in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil)
|
33
38
|
assert_equal 100.0*13/15, @result.covered_percent
|
34
39
|
end
|
35
|
-
|
36
|
-
context "dumped with
|
37
|
-
setup { @
|
38
|
-
should("be a
|
39
|
-
|
40
|
+
|
41
|
+
context "dumped with to_hash" do
|
42
|
+
setup { @hash = @result.to_hash }
|
43
|
+
should("be a hash") { assert_equal Hash, @hash.class }
|
44
|
+
|
40
45
|
context "loaded back with from_yaml" do
|
41
|
-
setup { @dumped_result = SimpleCov::Result.
|
42
|
-
|
46
|
+
setup { @dumped_result = SimpleCov::Result.from_hash(@hash) }
|
47
|
+
|
43
48
|
should "have 3 source files" do
|
44
49
|
assert_equal @result.source_files.count, @dumped_result.source_files.count
|
45
50
|
end
|
46
|
-
|
51
|
+
|
47
52
|
should "have the same covered_percent" do
|
48
53
|
assert_equal @result.covered_percent, @dumped_result.covered_percent
|
49
54
|
end
|
50
|
-
|
51
|
-
should "have the same
|
52
|
-
# Using to_i here since direct comparison seems to fail on 64-bit architecture because
|
53
|
-
# of fraction difference...
|
55
|
+
|
56
|
+
should "have the same timestamp" do
|
54
57
|
assert_equal @result.created_at.to_i, @dumped_result.created_at.to_i
|
55
58
|
end
|
56
|
-
|
59
|
+
|
57
60
|
should "have the same command_name" do
|
58
61
|
assert_equal @result.command_name, @dumped_result.command_name
|
59
62
|
end
|
60
|
-
|
63
|
+
|
61
64
|
should "have the same original_result" do
|
62
65
|
assert_equal @result.original_result, @dumped_result.original_result
|
63
66
|
end
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
67
|
-
|
70
|
+
|
68
71
|
context "with some filters set up" do
|
69
72
|
setup do
|
70
73
|
SimpleCov.add_filter 'sample.rb'
|
71
74
|
end
|
72
|
-
|
75
|
+
|
73
76
|
should "have 2 files in a new simple cov result" do
|
74
77
|
assert_equal 2, SimpleCov::Result.new(@original_result).source_files.length
|
75
78
|
end
|
76
|
-
|
79
|
+
|
77
80
|
should "have 80 covered percent" do
|
78
81
|
assert_equal 80, SimpleCov::Result.new(@original_result).covered_percent
|
79
82
|
end
|
80
83
|
end
|
81
|
-
|
84
|
+
|
82
85
|
context "with groups set up for all files" do
|
83
86
|
setup do
|
84
87
|
SimpleCov.add_group 'Models', 'app/models'
|
@@ -88,28 +91,28 @@ class TestResult < Test::Unit::TestCase
|
|
88
91
|
end
|
89
92
|
@result = SimpleCov::Result.new(@original_result)
|
90
93
|
end
|
91
|
-
|
94
|
+
|
92
95
|
should "have 3 groups" do
|
93
96
|
assert_equal 3, @result.groups.length
|
94
97
|
end
|
95
|
-
|
98
|
+
|
96
99
|
should "have user.rb in 'Models' group" do
|
97
100
|
assert_equal 'user.rb', File.basename(@result.groups['Models'].first.filename)
|
98
101
|
end
|
99
|
-
|
102
|
+
|
100
103
|
should "have sample_controller.rb in 'Controllers' group" do
|
101
104
|
assert_equal 'sample_controller.rb', File.basename(@result.groups['Controllers'].first.filename)
|
102
105
|
end
|
103
|
-
|
106
|
+
|
104
107
|
context "and simple formatter being used" do
|
105
108
|
setup {SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter}
|
106
|
-
|
109
|
+
|
107
110
|
should "return a formatted string with result.format!" do
|
108
111
|
assert_equal String, @result.format!.class
|
109
112
|
end
|
110
113
|
end
|
111
114
|
end
|
112
|
-
|
115
|
+
|
113
116
|
context "with groups set up that do not match all files" do
|
114
117
|
setup do
|
115
118
|
SimpleCov.configure do
|
@@ -118,11 +121,11 @@ class TestResult < Test::Unit::TestCase
|
|
118
121
|
end
|
119
122
|
@result = SimpleCov::Result.new(@original_result)
|
120
123
|
end
|
121
|
-
|
124
|
+
|
122
125
|
should "have 3 groups" do
|
123
126
|
assert_equal 3, @result.groups.length
|
124
127
|
end
|
125
|
-
|
128
|
+
|
126
129
|
should "have 1 item per group" do
|
127
130
|
@result.groups.each do |name, files|
|
128
131
|
assert_equal 1, files.length, "Group #{name} should have 1 file"
|
@@ -132,6 +135,12 @@ class TestResult < Test::Unit::TestCase
|
|
132
135
|
should "have sample.rb in 'Ungrouped' group" do
|
133
136
|
assert_equal 'sample.rb', File.basename(@result.groups['Ungrouped'].first.filename)
|
134
137
|
end
|
138
|
+
|
139
|
+
should "return all groups as instances of SimpleCov::FileList" do
|
140
|
+
@result.groups.each do |name, files|
|
141
|
+
assert_equal SimpleCov::FileList, files.class
|
142
|
+
end
|
143
|
+
end
|
135
144
|
end
|
136
145
|
end
|
137
146
|
end
|
data/test/test_return_codes.rb
CHANGED
@@ -15,25 +15,25 @@ class TestReturnCodes < Test::Unit::TestCase
|
|
15
15
|
`ruby testunit_good.rb`
|
16
16
|
assert_equal 0, $?.exitstatus
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
should "have return code 0 when running rspec_good.rb" do
|
20
20
|
`rspec rspec_good.rb`
|
21
21
|
assert_equal 0, $?.exitstatus
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
should "have non-0 return code when running testunit_bad.rb" do
|
25
25
|
`ruby testunit_bad.rb`
|
26
26
|
assert_not_equal 0, $?.exitstatus
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
should "have return code 1 when running rspec_bad.rb" do
|
30
30
|
`rspec rspec_bad.rb`
|
31
31
|
assert_not_equal 0, $?.exitstatus
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
teardown do
|
35
35
|
Dir.chdir(@current_dir)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
|
-
end
|
39
|
+
end
|
data/test/test_source_file.rb
CHANGED
@@ -2,50 +2,74 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestSourceFile < Test::Unit::TestCase
|
4
4
|
on_ruby '1.9' do
|
5
|
+
COVERAGE_FOR_SAMPLE_RB = [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, nil, nil, nil, nil, nil]
|
5
6
|
context "A source file initialized with some coverage data" do
|
6
7
|
setup do
|
7
|
-
@source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'),
|
8
|
+
@source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB)
|
8
9
|
end
|
9
|
-
|
10
|
+
|
10
11
|
should "have a filename" do
|
11
12
|
assert @source_file.filename
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
should "have source equal to src" do
|
15
16
|
assert_equal @source_file.source, @source_file.src
|
16
17
|
end
|
17
|
-
|
18
|
+
|
18
19
|
should "have source_lines equal to lines" do
|
19
20
|
assert_equal @source_file.source_lines, @source_file.lines
|
20
21
|
end
|
21
|
-
|
22
|
-
should "have
|
23
|
-
assert_equal
|
22
|
+
|
23
|
+
should "have 16 source lines" do
|
24
|
+
assert_equal 16, @source_file.lines.count
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
should "have all source lines of type SimpleCov::SourceFile::Line" do
|
27
28
|
assert @source_file.lines.all? {|l| l.instance_of?(SimpleCov::SourceFile::Line)}
|
28
29
|
end
|
29
|
-
|
30
|
+
|
30
31
|
should "have 'class Foo' as line(2).source" do
|
31
32
|
assert_equal "class Foo\n", @source_file.line(2).source
|
32
33
|
end
|
33
|
-
|
34
|
+
|
34
35
|
should "return lines number 2, 3, 4, 7 for covered_lines" do
|
35
36
|
assert_equal [2, 3, 4, 7], @source_file.covered_lines.map(&:line)
|
36
37
|
end
|
37
|
-
|
38
|
+
|
38
39
|
should "return lines number 8 for missed_lines" do
|
39
40
|
assert_equal [8], @source_file.missed_lines.map(&:line)
|
40
41
|
end
|
41
|
-
|
42
|
-
should "return lines number 1, 5, 6, 9, 10 for never_lines" do
|
43
|
-
assert_equal [1, 5, 6, 9, 10], @source_file.never_lines.map(&:line)
|
42
|
+
|
43
|
+
should "return lines number 1, 5, 6, 9, 10, 11, 15, 16 for never_lines" do
|
44
|
+
assert_equal [1, 5, 6, 9, 10, 11, 15, 16], @source_file.never_lines.map(&:line)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "return line numbers 12, 13, 14 for skipped_lines" do
|
48
|
+
assert_equal [12, 13, 14], @source_file.skipped_lines.map(&:line)
|
44
49
|
end
|
45
|
-
|
50
|
+
|
46
51
|
should "have 80% covered_percent" do
|
47
52
|
assert_equal 80.0, @source_file.covered_percent
|
48
53
|
end
|
49
54
|
end
|
55
|
+
|
56
|
+
context "Simulating potential Ruby 1.9 defect -- see Issue #56" do
|
57
|
+
setup do
|
58
|
+
@source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB + [nil])
|
59
|
+
end
|
60
|
+
|
61
|
+
should "have 16 source lines regardless of extra data in coverage array" do
|
62
|
+
# Do not litter test output with known warning
|
63
|
+
capture_stderr { assert_equal 16, @source_file.lines.count }
|
64
|
+
end
|
65
|
+
|
66
|
+
should "print a warning to stderr if coverage array contains more data than lines in the file" do
|
67
|
+
captured_output = capture_stderr do
|
68
|
+
@source_file.lines
|
69
|
+
end
|
70
|
+
|
71
|
+
assert_match /^Warning: coverage data provided/, captured_output
|
72
|
+
end
|
73
|
+
end
|
50
74
|
end
|
51
75
|
end
|