simplecov 0.6.4 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +378 -12
  3. data/CONTRIBUTING.md +51 -0
  4. data/ISSUE_TEMPLATE.md +23 -0
  5. data/LICENSE +1 -1
  6. data/README.md +456 -252
  7. data/doc/alternate-formatters.md +56 -0
  8. data/doc/commercial-services.md +20 -0
  9. data/doc/editor-integration.md +18 -0
  10. data/lib/simplecov.rb +223 -44
  11. data/lib/simplecov/command_guesser.rb +47 -35
  12. data/lib/simplecov/configuration.rb +281 -191
  13. data/lib/simplecov/defaults.rb +38 -43
  14. data/lib/simplecov/exit_codes.rb +10 -0
  15. data/lib/simplecov/file_list.rb +51 -34
  16. data/lib/simplecov/filter.rb +50 -3
  17. data/lib/simplecov/formatter.rb +4 -1
  18. data/lib/simplecov/formatter/multi_formatter.rb +34 -0
  19. data/lib/simplecov/formatter/simple_formatter.rb +18 -12
  20. data/lib/simplecov/jruby_fix.rb +44 -0
  21. data/lib/simplecov/last_run.rb +26 -0
  22. data/lib/simplecov/lines_classifier.rb +48 -0
  23. data/lib/simplecov/load_global_config.rb +8 -0
  24. data/lib/simplecov/no_defaults.rb +4 -0
  25. data/lib/simplecov/profiles.rb +33 -0
  26. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  27. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  28. data/lib/simplecov/profiles/rails.rb +18 -0
  29. data/lib/simplecov/profiles/root_filter.rb +10 -0
  30. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  31. data/lib/simplecov/railtie.rb +3 -1
  32. data/lib/simplecov/railties/tasks.rake +9 -7
  33. data/lib/simplecov/raw_coverage.rb +41 -0
  34. data/lib/simplecov/result.rb +17 -55
  35. data/lib/simplecov/result_merger.rb +100 -67
  36. data/lib/simplecov/source_file.rb +82 -67
  37. data/lib/simplecov/version.rb +4 -2
  38. metadata +153 -222
  39. data/.gitignore +0 -31
  40. data/.travis.yml +0 -15
  41. data/Appraisals +0 -8
  42. data/Gemfile +0 -5
  43. data/Rakefile +0 -19
  44. data/cucumber.yml +0 -13
  45. data/features/config_adapters.feature +0 -44
  46. data/features/config_autoload.feature +0 -46
  47. data/features/config_command_name.feature +0 -33
  48. data/features/config_coverage_dir.feature +0 -20
  49. data/features/config_deactivate_merging.feature +0 -42
  50. data/features/config_merge_timeout.feature +0 -39
  51. data/features/config_nocov_token.feature +0 -79
  52. data/features/config_project_name.feature +0 -27
  53. data/features/config_styles.feature +0 -93
  54. data/features/cucumber_basic.feature +0 -29
  55. data/features/merging_test_unit_and_rspec.feature +0 -44
  56. data/features/rspec_basic.feature +0 -31
  57. data/features/rspec_fails_on_initialization.feature +0 -14
  58. data/features/rspec_groups_and_filters_basic.feature +0 -29
  59. data/features/rspec_groups_and_filters_complex.feature +0 -35
  60. data/features/rspec_groups_using_filter_class.feature +0 -40
  61. data/features/rspec_without_simplecov.feature +0 -20
  62. data/features/skipping_code_blocks_manually.feature +0 -70
  63. data/features/step_definitions/html_steps.rb +0 -45
  64. data/features/step_definitions/simplecov_steps.rb +0 -66
  65. data/features/step_definitions/transformers.rb +0 -13
  66. data/features/step_definitions/web_steps.rb +0 -64
  67. data/features/support/env.rb +0 -26
  68. data/features/test_unit_basic.feature +0 -34
  69. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  70. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  71. data/features/test_unit_groups_using_filter_class.feature +0 -40
  72. data/features/test_unit_without_simplecov.feature +0 -20
  73. data/features/unicode_compatiblity.feature +0 -67
  74. data/gemfiles/multi_json-legacy.gemfile +0 -7
  75. data/gemfiles/multi_json-legacy.gemfile.lock +0 -85
  76. data/gemfiles/multi_json-new.gemfile +0 -7
  77. data/gemfiles/multi_json-new.gemfile.lock +0 -85
  78. data/lib/simplecov/adapters.rb +0 -29
  79. data/lib/simplecov/merge_helpers.rb +0 -39
  80. data/simplecov.gemspec +0 -29
  81. data/test/faked_project/Gemfile +0 -6
  82. data/test/faked_project/Rakefile +0 -8
  83. data/test/faked_project/cucumber.yml +0 -13
  84. data/test/faked_project/features/step_definitions/my_steps.rb +0 -23
  85. data/test/faked_project/features/support/env.rb +0 -12
  86. data/test/faked_project/features/test_stuff.feature +0 -6
  87. data/test/faked_project/lib/faked_project.rb +0 -11
  88. data/test/faked_project/lib/faked_project/framework_specific.rb +0 -18
  89. data/test/faked_project/lib/faked_project/meta_magic.rb +0 -24
  90. data/test/faked_project/lib/faked_project/some_class.rb +0 -29
  91. data/test/faked_project/spec/faked_spec.rb +0 -11
  92. data/test/faked_project/spec/meta_magic_spec.rb +0 -10
  93. data/test/faked_project/spec/some_class_spec.rb +0 -10
  94. data/test/faked_project/spec/spec_helper.rb +0 -15
  95. data/test/faked_project/test/faked_test.rb +0 -11
  96. data/test/faked_project/test/meta_magic_test.rb +0 -13
  97. data/test/faked_project/test/some_class_test.rb +0 -15
  98. data/test/faked_project/test/test_helper.rb +0 -16
  99. data/test/fixtures/app/controllers/sample_controller.rb +0 -10
  100. data/test/fixtures/app/models/user.rb +0 -10
  101. data/test/fixtures/deleted_source_sample.rb +0 -15
  102. data/test/fixtures/frameworks/rspec_bad.rb +0 -9
  103. data/test/fixtures/frameworks/rspec_good.rb +0 -9
  104. data/test/fixtures/frameworks/testunit_bad.rb +0 -9
  105. data/test/fixtures/frameworks/testunit_good.rb +0 -9
  106. data/test/fixtures/iso-8859.rb +0 -3
  107. data/test/fixtures/resultset1.rb +0 -4
  108. data/test/fixtures/resultset2.rb +0 -5
  109. data/test/fixtures/sample.rb +0 -16
  110. data/test/fixtures/utf-8.rb +0 -3
  111. data/test/helper.rb +0 -35
  112. data/test/shoulda_macros.rb +0 -29
  113. data/test/test_1_8_fallbacks.rb +0 -33
  114. data/test/test_command_guesser.rb +0 -21
  115. data/test/test_deleted_source.rb +0 -16
  116. data/test/test_file_list.rb +0 -24
  117. data/test/test_filters.rb +0 -80
  118. data/test/test_merge_helpers.rb +0 -107
  119. data/test/test_result.rb +0 -147
  120. data/test/test_return_codes.rb +0 -39
  121. data/test/test_source_file.rb +0 -95
  122. data/test/test_source_file_line.rb +0 -110
data/test/test_result.rb DELETED
@@ -1,147 +0,0 @@
1
- require 'helper'
2
-
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
14
-
15
- context "a simple cov result initialized from that" do
16
- setup { @result = SimpleCov::Result.new(@original_result) }
17
-
18
- should "have 3 filenames" do
19
- assert_equal 3, @result.filenames.count
20
- end
21
-
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
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
-
32
- should "have files equal to source_files" do
33
- assert_equal @result.files, @result.source_files
34
- end
35
-
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
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
-
45
- context "loaded back with from_yaml" do
46
- setup { @dumped_result = SimpleCov::Result.from_hash(@hash) }
47
-
48
- should "have 3 source files" do
49
- assert_equal @result.source_files.count, @dumped_result.source_files.count
50
- end
51
-
52
- should "have the same covered_percent" do
53
- assert_equal @result.covered_percent, @dumped_result.covered_percent
54
- end
55
-
56
- should "have the same timestamp" do
57
- assert_equal @result.created_at.to_i, @dumped_result.created_at.to_i
58
- end
59
-
60
- should "have the same command_name" do
61
- assert_equal @result.command_name, @dumped_result.command_name
62
- end
63
-
64
- should "have the same original_result" do
65
- assert_equal @result.original_result, @dumped_result.original_result
66
- end
67
- end
68
- end
69
- end
70
-
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
83
- end
84
-
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
94
-
95
- should "have 3 groups" do
96
- assert_equal 3, @result.groups.length
97
- end
98
-
99
- should "have user.rb in 'Models' group" do
100
- assert_equal 'user.rb', File.basename(@result.groups['Models'].first.filename)
101
- end
102
-
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
106
-
107
- context "and simple formatter being used" do
108
- setup {SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter}
109
-
110
- should "return a formatted string with result.format!" do
111
- assert_equal String, @result.format!.class
112
- end
113
- end
114
- end
115
-
116
- context "with groups set up that do not match all files" do
117
- setup do
118
- SimpleCov.configure do
119
- add_group 'Models', 'app/models'
120
- add_group 'Controllers', 'app/controllers'
121
- end
122
- @result = SimpleCov::Result.new(@original_result)
123
- end
124
-
125
- should "have 3 groups" do
126
- assert_equal 3, @result.groups.length
127
- end
128
-
129
- should "have 1 item per group" do
130
- @result.groups.each do |name, files|
131
- assert_equal 1, files.length, "Group #{name} should have 1 file"
132
- end
133
- end
134
-
135
- should "have sample.rb in 'Ungrouped' group" do
136
- assert_equal 'sample.rb', File.basename(@result.groups['Ungrouped'].first.filename)
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
144
- end
145
- end
146
- end
147
- end
@@ -1,39 +0,0 @@
1
- require 'helper'
2
-
3
- # Make sure that exit codes of tests are propagated properly when using
4
- # simplecov. See github issue #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
13
-
14
- should "have return code 0 when running testunit_good.rb" do
15
- `ruby testunit_good.rb`
16
- assert_equal 0, $?.exitstatus
17
- end
18
-
19
- should "have return code 0 when running rspec_good.rb" do
20
- `rspec rspec_good.rb`
21
- assert_equal 0, $?.exitstatus
22
- end
23
-
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
28
-
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
33
-
34
- teardown do
35
- Dir.chdir(@current_dir)
36
- end
37
- end
38
- end
39
- end
@@ -1,95 +0,0 @@
1
- require 'helper'
2
-
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
10
-
11
- should "have a filename" do
12
- assert @source_file.filename
13
- end
14
-
15
- should "have source equal to src" do
16
- assert_equal @source_file.source, @source_file.src
17
- end
18
-
19
- should "have source_lines equal to lines" do
20
- assert_equal @source_file.source_lines, @source_file.lines
21
- end
22
-
23
- should "have 16 source lines" do
24
- assert_equal 16, @source_file.lines.count
25
- end
26
-
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
30
-
31
- should "have 'class Foo' as line(2).source" do
32
- assert_equal "class Foo\n", @source_file.line(2).source
33
- end
34
-
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
38
-
39
- should "return lines number 8 for missed_lines" do
40
- assert_equal [8], @source_file.missed_lines.map(&:line)
41
- end
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)
49
- end
50
-
51
- should "have 80% covered_percent" do
52
- assert_equal 80.0, @source_file.covered_percent
53
- end
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
74
-
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])
78
-
79
- assert_nothing_raised do
80
- source_file.process_skipped_lines!
81
- end
82
- end
83
-
84
- should "handle iso-8859 encoded source files" do
85
- source_file = SimpleCov::SourceFile.new(source_fixture('iso-8859.rb'), [nil, nil, 1])
86
-
87
- assert_nothing_raised do
88
- source_file.process_skipped_lines!
89
- end
90
- end
91
- end
92
-
93
- end
94
- end
95
-
@@ -1,110 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSourceFileLine < Test::Unit::TestCase
4
-
5
-
6
- on_ruby '1.9' do
7
- context "A source line" do
8
- setup do
9
- @line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, 3)
10
- end
11
- subject { @line }
12
-
13
- should 'return "# the ruby source" as src' do
14
- assert_equal '# the ruby source', @line.src
15
- end
16
-
17
- should 'return the same for source as for src' do
18
- assert_equal @line.src, @line.source
19
- end
20
-
21
- should 'have line number 5' do
22
- assert_equal 5, @line.line_number
23
- end
24
-
25
- should 'have equal line_number, line and number' do
26
- assert_equal @line.line_number, @line.line
27
- assert_equal @line.line_number, @line.number
28
- end
29
-
30
- context "flagged as skipped!" do
31
- setup { @line.skipped! }
32
-
33
- should_not_be :covered?
34
- should_be :skipped?
35
- should_not_be :missed?
36
- should_not_be :never?
37
- should_have :status, 'skipped'
38
- end
39
- end
40
-
41
- context "A source line with coverage" do
42
- setup do
43
- @line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, 3)
44
- end
45
- subject { @line }
46
-
47
- should "have coverage of 3" do
48
- assert_equal 3, @line.coverage
49
- end
50
-
51
- should_be :covered?
52
- should_not_be :skipped?
53
- should_not_be :missed?
54
- should_not_be :never?
55
- should_have :status, 'covered'
56
- end
57
-
58
- context "A source line without coverage" do
59
- setup do
60
- @line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, 0)
61
- end
62
- subject { @line }
63
-
64
- should "have coverage of 0" do
65
- assert_equal 0, @line.coverage
66
- end
67
-
68
- should_not_be :covered?
69
- should_not_be :skipped?
70
- should_be :missed?
71
- should_not_be :never?
72
- should_have :status, 'missed'
73
- end
74
-
75
- context "A source line with no code" do
76
- setup do
77
- @line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, nil)
78
- end
79
- subject { @line }
80
-
81
- should "have nil coverage" do
82
- assert_nil @line.coverage
83
- end
84
-
85
- should_not_be :covered?
86
- should_not_be :skipped?
87
- should_not_be :missed?
88
- should_be :never?
89
- should_have :status, 'never'
90
- end
91
-
92
- should "raise ArgumentError when initialized with invalid src" do
93
- assert_raise ArgumentError do
94
- SimpleCov::SourceFile::Line.new(:symbol, 5, 3)
95
- end
96
- end
97
-
98
- should "raise ArgumentError when initialized with invalid line_number" do
99
- assert_raise ArgumentError do
100
- SimpleCov::SourceFile::Line.new("some source", "five", 3)
101
- end
102
- end
103
-
104
- should "raise ArgumentError when initialized with invalid coverage" do
105
- assert_raise ArgumentError do
106
- SimpleCov::SourceFile::Line.new("some source", 5, "three")
107
- end
108
- end
109
- end
110
- end