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
data/test/test_result.rb CHANGED
@@ -1,162 +1,160 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestResult < Test::Unit::TestCase
4
- on_ruby "1.9" do
5
- context "With a (mocked) Coverage.result" do
6
- setup do
7
- SimpleCov.filters = []
8
- SimpleCov.groups = {}
9
- SimpleCov.formatter = nil
10
- @original_result = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
11
- source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
12
- source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]}
13
- end
4
+ context "With a (mocked) Coverage.result" do
5
+ setup do
6
+ SimpleCov.filters = []
7
+ SimpleCov.groups = {}
8
+ SimpleCov.formatter = nil
9
+ @original_result = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
10
+ source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
11
+ source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]}
12
+ end
14
13
 
15
- context "a simple cov result initialized from that" do
16
- setup { @result = SimpleCov::Result.new(@original_result) }
14
+ context "a simple cov result initialized from that" do
15
+ setup { @result = SimpleCov::Result.new(@original_result) }
17
16
 
18
- should "have 3 filenames" do
19
- assert_equal 3, @result.filenames.count
20
- end
17
+ should "have 3 filenames" do
18
+ assert_equal 3, @result.filenames.count
19
+ end
21
20
 
22
- should "have 3 source files" do
23
- assert_equal 3, @result.source_files.count
24
- assert @result.source_files.all? {|s| s.instance_of?(SimpleCov::SourceFile)}, "Not all instances are of SimpleCov::SourceFile type"
25
- end
21
+ should "have 3 source files" do
22
+ assert_equal 3, @result.source_files.count
23
+ assert @result.source_files.all? {|s| s.instance_of?(SimpleCov::SourceFile)}, "Not all instances are of SimpleCov::SourceFile type"
24
+ end
26
25
 
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
26
+ should "return an instance of SimpleCov::FileList for source_files and files" do
27
+ assert_equal SimpleCov::FileList, @result.source_files.class
28
+ assert_equal SimpleCov::FileList, @result.files.class
29
+ end
31
30
 
32
- should "have files equal to source_files" do
33
- assert_equal @result.files, @result.source_files
34
- end
31
+ should "have files equal to source_files" do
32
+ assert_equal @result.files, @result.source_files
33
+ end
35
34
 
36
- should "have accurate covered percent" do
37
- # in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil)
38
- assert_equal 100.0*13/15, @result.covered_percent
39
- end
35
+ should "have accurate covered percent" do
36
+ # in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil)
37
+ assert_equal 100.0*13/15, @result.covered_percent
38
+ end
40
39
 
41
- context "dumped with to_hash" do
42
- setup { @hash = @result.to_hash }
43
- should("be a hash") { assert_equal Hash, @hash.class }
40
+ context "dumped with to_hash" do
41
+ setup { @hash = @result.to_hash }
42
+ should("be a hash") { assert_equal Hash, @hash.class }
44
43
 
45
- context "loaded back with from_yaml" do
46
- setup { @dumped_result = SimpleCov::Result.from_hash(@hash) }
44
+ context "loaded back with from_yaml" do
45
+ setup { @dumped_result = SimpleCov::Result.from_hash(@hash) }
47
46
 
48
- should "have 3 source files" do
49
- assert_equal @result.source_files.count, @dumped_result.source_files.count
50
- end
47
+ should "have 3 source files" do
48
+ assert_equal @result.source_files.count, @dumped_result.source_files.count
49
+ end
51
50
 
52
- should "have the same covered_percent" do
53
- assert_equal @result.covered_percent, @dumped_result.covered_percent
54
- end
51
+ should "have the same covered_percent" do
52
+ assert_equal @result.covered_percent, @dumped_result.covered_percent
53
+ end
55
54
 
56
- should "have the same timestamp" do
57
- assert_equal @result.created_at.to_i, @dumped_result.created_at.to_i
58
- end
55
+ should "have the same timestamp" do
56
+ assert_equal @result.created_at.to_i, @dumped_result.created_at.to_i
57
+ end
59
58
 
60
- should "have the same command_name" do
61
- assert_equal @result.command_name, @dumped_result.command_name
62
- end
59
+ should "have the same command_name" do
60
+ assert_equal @result.command_name, @dumped_result.command_name
61
+ end
63
62
 
64
- should "have the same original_result" do
65
- assert_equal @result.original_result, @dumped_result.original_result
66
- end
63
+ should "have the same original_result" do
64
+ assert_equal @result.original_result, @dumped_result.original_result
67
65
  end
68
66
  end
69
67
  end
68
+ end
70
69
 
71
- context "with some filters set up" do
72
- setup do
73
- SimpleCov.add_filter 'sample.rb'
74
- end
75
-
76
- should "have 2 files in a new simple cov result" do
77
- assert_equal 2, SimpleCov::Result.new(@original_result).source_files.length
78
- end
79
-
80
- should "have 80 covered percent" do
81
- assert_equal 80, SimpleCov::Result.new(@original_result).covered_percent
82
- end
70
+ context "with some filters set up" do
71
+ setup do
72
+ SimpleCov.add_filter 'sample.rb'
83
73
  end
84
74
 
85
- context "with groups set up for all files" do
86
- setup do
87
- SimpleCov.add_group 'Models', 'app/models'
88
- SimpleCov.add_group 'Controllers', 'app/controllers'
89
- SimpleCov.add_group 'Other' do |src_file|
90
- File.basename(src_file.filename) == 'sample.rb'
91
- end
92
- @result = SimpleCov::Result.new(@original_result)
93
- end
75
+ should "have 2 files in a new simple cov result" do
76
+ assert_equal 2, SimpleCov::Result.new(@original_result).source_files.length
77
+ end
94
78
 
95
- should "have 3 groups" do
96
- assert_equal 3, @result.groups.length
97
- end
79
+ should "have 80 covered percent" do
80
+ assert_equal 80, SimpleCov::Result.new(@original_result).covered_percent
81
+ end
82
+ end
98
83
 
99
- should "have user.rb in 'Models' group" do
100
- assert_equal 'user.rb', File.basename(@result.groups['Models'].first.filename)
84
+ context "with groups set up for all files" do
85
+ setup do
86
+ SimpleCov.add_group 'Models', 'app/models'
87
+ SimpleCov.add_group 'Controllers', 'app/controllers'
88
+ SimpleCov.add_group 'Other' do |src_file|
89
+ File.basename(src_file.filename) == 'sample.rb'
101
90
  end
91
+ @result = SimpleCov::Result.new(@original_result)
92
+ end
102
93
 
103
- should "have sample_controller.rb in 'Controllers' group" do
104
- assert_equal 'sample_controller.rb', File.basename(@result.groups['Controllers'].first.filename)
105
- end
94
+ should "have 3 groups" do
95
+ assert_equal 3, @result.groups.length
96
+ end
106
97
 
107
- context "and simple formatter being used" do
108
- setup {SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter}
98
+ should "have user.rb in 'Models' group" do
99
+ assert_equal 'user.rb', File.basename(@result.groups['Models'].first.filename)
100
+ end
109
101
 
110
- should "return a formatted string with result.format!" do
111
- assert_equal String, @result.format!.class
112
- end
113
- end
102
+ should "have sample_controller.rb in 'Controllers' group" do
103
+ assert_equal 'sample_controller.rb', File.basename(@result.groups['Controllers'].first.filename)
104
+ end
114
105
 
115
- context "and multi formatter being used" do
116
- setup do
117
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
118
- SimpleCov::Formatter::SimpleFormatter,
119
- SimpleCov::Formatter::SimpleFormatter,
120
- ]
121
- end
106
+ context "and simple formatter being used" do
107
+ setup {SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter}
122
108
 
123
- should "return an array containing formatted string with result.format!" do
124
- formated = @result.format!
125
- assert_equal 2, formated.count
126
- assert_equal String, formated.first.class
127
- end
109
+ should "return a formatted string with result.format!" do
110
+ assert_equal String, @result.format!.class
128
111
  end
129
112
  end
130
113
 
131
- context "with groups set up that do not match all files" do
114
+ context "and multi formatter being used" do
132
115
  setup do
133
- SimpleCov.configure do
134
- add_group 'Models', 'app/models'
135
- add_group 'Controllers', 'app/controllers'
136
- end
137
- @result = SimpleCov::Result.new(@original_result)
116
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
117
+ SimpleCov::Formatter::SimpleFormatter,
118
+ SimpleCov::Formatter::SimpleFormatter,
119
+ ]
138
120
  end
139
121
 
140
- should "have 3 groups" do
141
- assert_equal 3, @result.groups.length
122
+ should "return an array containing formatted string with result.format!" do
123
+ formated = @result.format!
124
+ assert_equal 2, formated.count
125
+ assert_equal String, formated.first.class
142
126
  end
127
+ end
128
+ end
143
129
 
144
- should "have 1 item per group" do
145
- @result.groups.each do |name, files|
146
- assert_equal 1, files.length, "Group #{name} should have 1 file"
147
- end
130
+ context "with groups set up that do not match all files" do
131
+ setup do
132
+ SimpleCov.configure do
133
+ add_group 'Models', 'app/models'
134
+ add_group 'Controllers', 'app/controllers'
148
135
  end
136
+ @result = SimpleCov::Result.new(@original_result)
137
+ end
149
138
 
150
- should "have sample.rb in 'Ungrouped' group" do
151
- assert_equal 'sample.rb', File.basename(@result.groups['Ungrouped'].first.filename)
139
+ should "have 3 groups" do
140
+ assert_equal 3, @result.groups.length
141
+ end
142
+
143
+ should "have 1 item per group" do
144
+ @result.groups.each do |name, files|
145
+ assert_equal 1, files.length, "Group #{name} should have 1 file"
152
146
  end
147
+ end
153
148
 
154
- should "return all groups as instances of SimpleCov::FileList" do
155
- @result.groups.each do |name, files|
156
- assert_equal SimpleCov::FileList, files.class
157
- end
149
+ should "have sample.rb in 'Ungrouped' group" do
150
+ assert_equal 'sample.rb', File.basename(@result.groups['Ungrouped'].first.filename)
151
+ end
152
+
153
+ should "return all groups as instances of SimpleCov::FileList" do
154
+ @result.groups.each do |name, files|
155
+ assert_equal SimpleCov::FileList, files.class
158
156
  end
159
157
  end
160
158
  end
161
159
  end
162
- end
160
+ end if SimpleCov.usable?
@@ -3,37 +3,35 @@ require 'helper'
3
3
  # Make sure that exit codes of tests are propagated properly when using
4
4
  # simplecov. See github issue #5
5
5
  class TestReturnCodes < Test::Unit::TestCase
6
- on_ruby '1.8', '1.9' do
7
- context "Inside fixtures/frameworks" do
8
- setup do
9
- @current_dir = Dir.getwd
10
- Dir.chdir(File.join(File.dirname(__FILE__), 'fixtures', 'frameworks'))
11
- FileUtils.rm_rf('./coverage')
12
- end
6
+ context "Inside fixtures/frameworks" do
7
+ setup do
8
+ @current_dir = Dir.getwd
9
+ Dir.chdir(File.join(File.dirname(__FILE__), 'fixtures', 'frameworks'))
10
+ FileUtils.rm_rf('./coverage')
11
+ end
13
12
 
14
- should "have return code 0 when running testunit_good.rb" do
15
- `ruby testunit_good.rb`
16
- assert_equal 0, $?.exitstatus
17
- end
13
+ should "have return code 0 when running testunit_good.rb" do
14
+ `ruby testunit_good.rb`
15
+ assert_equal 0, $?.exitstatus
16
+ end
18
17
 
19
- should "have return code 0 when running rspec_good.rb" do
20
- `rspec rspec_good.rb`
21
- assert_equal 0, $?.exitstatus
22
- end
18
+ should "have return code 0 when running rspec_good.rb" do
19
+ `rspec rspec_good.rb`
20
+ assert_equal 0, $?.exitstatus
21
+ end
23
22
 
24
- should "have non-0 return code when running testunit_bad.rb" do
25
- `ruby testunit_bad.rb`
26
- assert_not_equal 0, $?.exitstatus
27
- end
23
+ should "have non-0 return code when running testunit_bad.rb" do
24
+ `ruby testunit_bad.rb`
25
+ assert_not_equal 0, $?.exitstatus
26
+ end
28
27
 
29
- should "have return code 1 when running rspec_bad.rb" do
30
- `rspec rspec_bad.rb`
31
- assert_not_equal 0, $?.exitstatus
32
- end
28
+ should "have return code 1 when running rspec_bad.rb" do
29
+ `rspec rspec_bad.rb`
30
+ assert_not_equal 0, $?.exitstatus
31
+ end
33
32
 
34
- teardown do
35
- Dir.chdir(@current_dir)
36
- end
33
+ teardown do
34
+ Dir.chdir(@current_dir)
37
35
  end
38
36
  end
39
37
  end
@@ -1,95 +1,106 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestSourceFile < Test::Unit::TestCase
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]
6
- context "A source file initialized with some coverage data" do
7
- setup do
8
- @source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB)
9
- end
4
+ COVERAGE_FOR_SAMPLE_RB = [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, nil, nil, nil, nil, nil]
5
+ context "A source file initialized with some coverage data" do
6
+ setup do
7
+ @source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB)
8
+ end
10
9
 
11
- should "have a filename" do
12
- assert @source_file.filename
13
- end
10
+ should "have a filename" do
11
+ assert @source_file.filename
12
+ end
14
13
 
15
- should "have source equal to src" do
16
- assert_equal @source_file.source, @source_file.src
17
- end
14
+ should "have source equal to src" do
15
+ assert_equal @source_file.source, @source_file.src
16
+ end
18
17
 
19
- should "have source_lines equal to lines" do
20
- assert_equal @source_file.source_lines, @source_file.lines
21
- end
18
+ should "have source_lines equal to lines" do
19
+ assert_equal @source_file.source_lines, @source_file.lines
20
+ end
22
21
 
23
- should "have 16 source lines" do
24
- assert_equal 16, @source_file.lines.count
25
- end
22
+ should "have 16 source lines" do
23
+ assert_equal 16, @source_file.lines.count
24
+ end
26
25
 
27
- should "have all source lines of type SimpleCov::SourceFile::Line" do
28
- assert @source_file.lines.all? {|l| l.instance_of?(SimpleCov::SourceFile::Line)}
29
- end
26
+ should "have all source lines of type SimpleCov::SourceFile::Line" do
27
+ assert @source_file.lines.all? {|l| l.instance_of?(SimpleCov::SourceFile::Line)}
28
+ end
30
29
 
31
- should "have 'class Foo' as line(2).source" do
32
- assert_equal "class Foo\n", @source_file.line(2).source
33
- end
30
+ should "have 'class Foo' as line(2).source" do
31
+ assert_equal "class Foo\n", @source_file.line(2).source
32
+ end
34
33
 
35
- should "return lines number 2, 3, 4, 7 for covered_lines" do
36
- assert_equal [2, 3, 4, 7], @source_file.covered_lines.map(&:line)
37
- end
34
+ should "return lines number 2, 3, 4, 7 for covered_lines" do
35
+ assert_equal [2, 3, 4, 7], @source_file.covered_lines.map(&:line)
36
+ end
38
37
 
39
- should "return lines number 8 for missed_lines" do
40
- assert_equal [8], @source_file.missed_lines.map(&:line)
41
- end
38
+ should "return lines number 8 for missed_lines" do
39
+ assert_equal [8], @source_file.missed_lines.map(&:line)
40
+ end
42
41
 
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
42
+ should "return lines number 1, 5, 6, 9, 10, 11, 15, 16 for never_lines" do
43
+ assert_equal [1, 5, 6, 9, 10, 11, 15, 16], @source_file.never_lines.map(&:line)
44
+ end
46
45
 
47
- should "return line numbers 12, 13, 14 for skipped_lines" do
48
- assert_equal [12, 13, 14], @source_file.skipped_lines.map(&:line)
49
- end
46
+ should "return line numbers 12, 13, 14 for skipped_lines" do
47
+ assert_equal [12, 13, 14], @source_file.skipped_lines.map(&:line)
48
+ end
50
49
 
51
- should "have 80% covered_percent" do
52
- assert_equal 80.0, @source_file.covered_percent
53
- end
50
+ should "have 80% covered_percent" do
51
+ assert_equal 80.0, @source_file.covered_percent
54
52
  end
53
+ end
55
54
 
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
55
+ context "Simulating potential Ruby 1.9 defect -- see Issue #56" do
56
+ setup do
57
+ @source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB + [nil])
58
+ end
59
+
60
+ should "have 16 source lines regardless of extra data in coverage array" do
61
+ # Do not litter test output with known warning
62
+ capture_stderr { assert_equal 16, @source_file.lines.count }
63
+ end
60
64
 
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 }
65
+ should "print a warning to stderr if coverage array contains more data than lines in the file" do
66
+ captured_output = capture_stderr do
67
+ @source_file.lines
64
68
  end
65
69
 
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
+ assert_match(/^Warning: coverage data provided/, captured_output)
71
+ end
72
+ end
70
73
 
71
- assert_match(/^Warning: coverage data provided/, captured_output)
74
+ context "Encoding" do
75
+ should "handle utf-8 encoded source files" do
76
+ source_file = SimpleCov::SourceFile.new(source_fixture('utf-8.rb'), [nil, nil, 1])
77
+
78
+ assert_nothing_raised do
79
+ source_file.process_skipped_lines!
72
80
  end
73
81
  end
74
82
 
75
- context "Encoding" do
76
- should "handle utf-8 encoded source files" do
77
- source_file = SimpleCov::SourceFile.new(source_fixture('utf-8.rb'), [nil, nil, 1])
83
+ should "handle iso-8859 encoded source files" do
84
+ source_file = SimpleCov::SourceFile.new(source_fixture('iso-8859.rb'), [nil, nil, 1])
78
85
 
79
- assert_nothing_raised do
80
- source_file.process_skipped_lines!
81
- end
86
+ assert_nothing_raised do
87
+ source_file.process_skipped_lines!
82
88
  end
89
+ end
83
90
 
84
- should "handle iso-8859 encoded source files" do
85
- source_file = SimpleCov::SourceFile.new(source_fixture('iso-8859.rb'), [nil, nil, 1])
91
+ should "handle utf-8 encoded source files when the default_internal encoding is binary" do
92
+ original_internal_encoding = Encoding.default_internal
93
+ Encoding.default_internal = "BINARY"
94
+ begin
95
+ source_file = SimpleCov::SourceFile.new(source_fixture('utf-8.rb'), [nil, nil, 1])
96
+ ensure
97
+ Encoding.default_internal = original_internal_encoding
98
+ end
86
99
 
87
- assert_nothing_raised do
88
- source_file.process_skipped_lines!
89
- end
100
+ assert_nothing_raised do
101
+ source_file.process_skipped_lines!
90
102
  end
91
103
  end
92
-
93
104
  end
94
- end
105
+ end if SimpleCov.usable?
95
106