simplecov 0.8.0.pre2 → 0.18.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +368 -27
  3. data/CODE_OF_CONDUCT.md +76 -0
  4. data/CONTRIBUTING.md +38 -7
  5. data/ISSUE_TEMPLATE.md +23 -0
  6. data/{MIT-LICENSE → LICENSE} +1 -1
  7. data/README.md +449 -230
  8. data/doc/alternate-formatters.md +61 -0
  9. data/doc/commercial-services.md +20 -0
  10. data/doc/editor-integration.md +18 -0
  11. data/lib/simplecov.rb +294 -59
  12. data/lib/simplecov/combine.rb +30 -0
  13. data/lib/simplecov/combine/branches_combiner.rb +32 -0
  14. data/lib/simplecov/combine/files_combiner.rb +25 -0
  15. data/lib/simplecov/combine/lines_combiner.rb +43 -0
  16. data/lib/simplecov/combine/results_combiner.rb +60 -0
  17. data/lib/simplecov/command_guesser.rb +46 -40
  18. data/lib/simplecov/configuration.rb +346 -221
  19. data/lib/simplecov/defaults.rb +35 -75
  20. data/lib/simplecov/exit_codes.rb +9 -4
  21. data/lib/simplecov/file_list.rb +80 -36
  22. data/lib/simplecov/filter.rb +51 -3
  23. data/lib/simplecov/formatter.rb +4 -2
  24. data/lib/simplecov/formatter/multi_formatter.rb +28 -19
  25. data/lib/simplecov/formatter/simple_formatter.rb +21 -15
  26. data/lib/simplecov/last_run.rb +21 -13
  27. data/lib/simplecov/lines_classifier.rb +48 -0
  28. data/lib/simplecov/load_global_config.rb +8 -0
  29. data/lib/simplecov/no_defaults.rb +4 -2
  30. data/lib/simplecov/profiles.rb +29 -23
  31. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  32. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  33. data/lib/simplecov/profiles/rails.rb +18 -0
  34. data/lib/simplecov/profiles/root_filter.rb +10 -0
  35. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  36. data/lib/simplecov/result.rb +39 -68
  37. data/lib/simplecov/result_adapter.rb +30 -0
  38. data/lib/simplecov/result_merger.rb +110 -60
  39. data/lib/simplecov/simulate_coverage.rb +29 -0
  40. data/lib/simplecov/source_file.rb +261 -135
  41. data/lib/simplecov/source_file/branch.rb +106 -0
  42. data/lib/simplecov/source_file/line.rb +72 -0
  43. data/lib/simplecov/useless_results_remover.rb +16 -0
  44. data/lib/simplecov/version.rb +4 -2
  45. metadata +48 -197
  46. data/.gitignore +0 -32
  47. data/.travis.yml +0 -28
  48. data/.yardopts +0 -1
  49. data/Appraisals +0 -8
  50. data/Gemfile +0 -16
  51. data/Rakefile +0 -32
  52. data/cucumber.yml +0 -13
  53. data/features/config_autoload.feature +0 -46
  54. data/features/config_command_name.feature +0 -45
  55. data/features/config_coverage_dir.feature +0 -33
  56. data/features/config_deactivate_merging.feature +0 -42
  57. data/features/config_formatters.feature +0 -52
  58. data/features/config_merge_timeout.feature +0 -39
  59. data/features/config_nocov_token.feature +0 -79
  60. data/features/config_profiles.feature +0 -44
  61. data/features/config_project_name.feature +0 -27
  62. data/features/config_styles.feature +0 -121
  63. data/features/cucumber_basic.feature +0 -29
  64. data/features/maximum_coverage_drop.feature +0 -36
  65. data/features/merging_test_unit_and_rspec.feature +0 -44
  66. data/features/minimum_coverage.feature +0 -59
  67. data/features/refuse_coverage_drop.feature +0 -35
  68. data/features/rspec_basic.feature +0 -31
  69. data/features/rspec_fails_on_initialization.feature +0 -14
  70. data/features/rspec_groups_and_filters_basic.feature +0 -29
  71. data/features/rspec_groups_and_filters_complex.feature +0 -35
  72. data/features/rspec_groups_using_filter_class.feature +0 -40
  73. data/features/rspec_without_simplecov.feature +0 -20
  74. data/features/skipping_code_blocks_manually.feature +0 -70
  75. data/features/step_definitions/html_steps.rb +0 -45
  76. data/features/step_definitions/simplecov_steps.rb +0 -66
  77. data/features/step_definitions/transformers.rb +0 -13
  78. data/features/step_definitions/web_steps.rb +0 -64
  79. data/features/support/env.rb +0 -44
  80. data/features/test_unit_basic.feature +0 -34
  81. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  82. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  83. data/features/test_unit_groups_using_filter_class.feature +0 -40
  84. data/features/test_unit_without_simplecov.feature +0 -20
  85. data/features/unicode_compatiblity.feature +0 -67
  86. data/gemfiles/multi_json_legacy.gemfile +0 -12
  87. data/gemfiles/multi_json_new.gemfile +0 -12
  88. data/lib/simplecov/jruby16_fix.rb +0 -43
  89. data/lib/simplecov/json.rb +0 -27
  90. data/lib/simplecov/merge_helpers.rb +0 -39
  91. data/lib/simplecov/railtie.rb +0 -7
  92. data/lib/simplecov/railties/tasks.rake +0 -11
  93. data/simplecov.gemspec +0 -30
  94. data/test/faked_project/Gemfile +0 -6
  95. data/test/faked_project/Rakefile +0 -8
  96. data/test/faked_project/cucumber.yml +0 -13
  97. data/test/faked_project/features/step_definitions/my_steps.rb +0 -23
  98. data/test/faked_project/features/support/env.rb +0 -12
  99. data/test/faked_project/features/test_stuff.feature +0 -6
  100. data/test/faked_project/lib/faked_project.rb +0 -11
  101. data/test/faked_project/lib/faked_project/framework_specific.rb +0 -18
  102. data/test/faked_project/lib/faked_project/meta_magic.rb +0 -24
  103. data/test/faked_project/lib/faked_project/some_class.rb +0 -29
  104. data/test/faked_project/spec/faked_spec.rb +0 -11
  105. data/test/faked_project/spec/meta_magic_spec.rb +0 -10
  106. data/test/faked_project/spec/some_class_spec.rb +0 -10
  107. data/test/faked_project/spec/spec_helper.rb +0 -15
  108. data/test/faked_project/test/faked_test.rb +0 -11
  109. data/test/faked_project/test/meta_magic_test.rb +0 -13
  110. data/test/faked_project/test/some_class_test.rb +0 -15
  111. data/test/faked_project/test/test_helper.rb +0 -16
  112. data/test/fixtures/app/controllers/sample_controller.rb +0 -10
  113. data/test/fixtures/app/models/user.rb +0 -10
  114. data/test/fixtures/deleted_source_sample.rb +0 -15
  115. data/test/fixtures/frameworks/rspec_bad.rb +0 -9
  116. data/test/fixtures/frameworks/rspec_good.rb +0 -9
  117. data/test/fixtures/frameworks/testunit_bad.rb +0 -9
  118. data/test/fixtures/frameworks/testunit_good.rb +0 -9
  119. data/test/fixtures/iso-8859.rb +0 -3
  120. data/test/fixtures/resultset1.rb +0 -4
  121. data/test/fixtures/resultset2.rb +0 -5
  122. data/test/fixtures/sample.rb +0 -16
  123. data/test/fixtures/utf-8.rb +0 -3
  124. data/test/helper.rb +0 -34
  125. data/test/shoulda_macros.rb +0 -19
  126. data/test/test_1_8_fallbacks.rb +0 -31
  127. data/test/test_command_guesser.rb +0 -19
  128. data/test/test_deleted_source.rb +0 -14
  129. data/test/test_file_list.rb +0 -22
  130. data/test/test_filters.rb +0 -78
  131. data/test/test_merge_helpers.rb +0 -105
  132. data/test/test_result.rb +0 -160
  133. data/test/test_return_codes.rb +0 -37
  134. data/test/test_source_file.rb +0 -106
  135. data/test/test_source_file_line.rb +0 -106
@@ -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 < Test::Unit::TestCase
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
@@ -1,22 +0,0 @@
1
- require 'helper'
2
-
3
- class TestFileList < Test::Unit::TestCase
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
11
-
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 }
17
-
18
- should "have correct covered_percent" do
19
- assert_equal 100.0*13/15, @file_list.covered_percent
20
- end
21
- end
22
- end if SimpleCov.usable?
@@ -1,78 +0,0 @@
1
- require 'helper'
2
-
3
- class TestFilters < Test::Unit::TestCase
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.new {|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.new {|s| File.basename(s.filename) == 'sample.rb'}).matches?(@source_file)
35
- end
36
- end
37
-
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
43
-
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
48
-
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
53
-
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
58
-
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
62
- end
63
- assert_equal 0, SimpleCov.filtered(@files).count
64
- end
65
-
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
69
- end
70
- assert_equal 1, SimpleCov.filtered(@files).count
71
- end
72
-
73
- should "return a FileList after filtering" do
74
- SimpleCov.add_filter "fooo"
75
- assert_equal SimpleCov::FileList, SimpleCov.filtered(@files).class
76
- end
77
- end
78
- end if SimpleCov.usable?
@@ -1,105 +0,0 @@
1
- require 'helper'
2
-
3
- class TestMergeHelpers < Test::Unit::TestCase
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
19
- setup do
20
- assert @merged = @resultset1.merge_resultset(@resultset2)
21
- end
22
-
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
26
-
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
30
-
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
34
-
35
- should "have proper results for resultset1.rb" do
36
- assert_equal [1, 1, 1, 1], @merged[source_fixture('resultset1.rb')]
37
- end
38
-
39
- should "have proper results for resultset2.rb" do
40
- assert_equal [nil, 1, 1, nil], @merged[source_fixture('resultset2.rb')]
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
49
-
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
58
- system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
59
- @result1 = SimpleCov::Result.new(@resultset1)
60
- @result1.command_name = "result1"
61
- @result2 = SimpleCov::Result.new(@resultset2)
62
- @result2.command_name = "result2"
63
- end
64
-
65
- context "with stored results" do
66
- setup do
67
- assert SimpleCov::ResultMerger.store_result(@result1)
68
- assert SimpleCov::ResultMerger.store_result(@result2)
69
- end
70
-
71
- should "have stored data in resultset_path yaml file" do
72
- assert File.readlines(SimpleCov::ResultMerger.resultset_path).length > 50
73
- end
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
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
82
-
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)
87
- end
88
-
89
- should "have only one result in SimpleCov::ResultMerger.results" do
90
- assert_equal 1, SimpleCov::ResultMerger.results.length
91
- end
92
- end
93
-
94
- context "with merging disabled" do
95
- setup { SimpleCov.use_merging false }
96
-
97
- should "return nil for SimpleCov.result" do
98
- assert_nil SimpleCov.result
99
- end
100
- end
101
- end
102
-
103
- end
104
- end
105
- end if SimpleCov.usable?
@@ -1,160 +0,0 @@
1
- require 'helper'
2
-
3
- class TestResult < Test::Unit::TestCase
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
13
-
14
- context "a simple cov result initialized from that" do
15
- setup { @result = SimpleCov::Result.new(@original_result) }
16
-
17
- should "have 3 filenames" do
18
- assert_equal 3, @result.filenames.count
19
- end
20
-
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
25
-
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
30
-
31
- should "have files equal to source_files" do
32
- assert_equal @result.files, @result.source_files
33
- end
34
-
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
39
-
40
- context "dumped with to_hash" do
41
- setup { @hash = @result.to_hash }
42
- should("be a hash") { assert_equal Hash, @hash.class }
43
-
44
- context "loaded back with from_yaml" do
45
- setup { @dumped_result = SimpleCov::Result.from_hash(@hash) }
46
-
47
- should "have 3 source files" do
48
- assert_equal @result.source_files.count, @dumped_result.source_files.count
49
- end
50
-
51
- should "have the same covered_percent" do
52
- assert_equal @result.covered_percent, @dumped_result.covered_percent
53
- end
54
-
55
- should "have the same timestamp" do
56
- assert_equal @result.created_at.to_i, @dumped_result.created_at.to_i
57
- end
58
-
59
- should "have the same command_name" do
60
- assert_equal @result.command_name, @dumped_result.command_name
61
- end
62
-
63
- should "have the same original_result" do
64
- assert_equal @result.original_result, @dumped_result.original_result
65
- end
66
- end
67
- end
68
- end
69
-
70
- context "with some filters set up" do
71
- setup do
72
- SimpleCov.add_filter 'sample.rb'
73
- end
74
-
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
78
-
79
- should "have 80 covered percent" do
80
- assert_equal 80, SimpleCov::Result.new(@original_result).covered_percent
81
- end
82
- end
83
-
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'
90
- end
91
- @result = SimpleCov::Result.new(@original_result)
92
- end
93
-
94
- should "have 3 groups" do
95
- assert_equal 3, @result.groups.length
96
- end
97
-
98
- should "have user.rb in 'Models' group" do
99
- assert_equal 'user.rb', File.basename(@result.groups['Models'].first.filename)
100
- end
101
-
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
105
-
106
- context "and simple formatter being used" do
107
- setup {SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter}
108
-
109
- should "return a formatted string with result.format!" do
110
- assert_equal String, @result.format!.class
111
- end
112
- end
113
-
114
- context "and multi formatter being used" do
115
- setup do
116
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
117
- SimpleCov::Formatter::SimpleFormatter,
118
- SimpleCov::Formatter::SimpleFormatter,
119
- ]
120
- end
121
-
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
126
- end
127
- end
128
- end
129
-
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'
135
- end
136
- @result = SimpleCov::Result.new(@original_result)
137
- end
138
-
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"
146
- end
147
- end
148
-
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
156
- end
157
- end
158
- end
159
- end
160
- end if SimpleCov.usable?
@@ -1,37 +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
- 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
12
-
13
- should "have return code 0 when running testunit_good.rb" do
14
- `ruby testunit_good.rb`
15
- assert_equal 0, $?.exitstatus
16
- end
17
-
18
- should "have return code 0 when running rspec_good.rb" do
19
- `rspec rspec_good.rb`
20
- assert_equal 0, $?.exitstatus
21
- end
22
-
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
27
-
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
32
-
33
- teardown do
34
- Dir.chdir(@current_dir)
35
- end
36
- end
37
- end
@@ -1,106 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSourceFile < Test::Unit::TestCase
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
9
-
10
- should "have a filename" do
11
- assert @source_file.filename
12
- end
13
-
14
- should "have source equal to src" do
15
- assert_equal @source_file.source, @source_file.src
16
- end
17
-
18
- should "have source_lines equal to lines" do
19
- assert_equal @source_file.source_lines, @source_file.lines
20
- end
21
-
22
- should "have 16 source lines" do
23
- assert_equal 16, @source_file.lines.count
24
- end
25
-
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
29
-
30
- should "have 'class Foo' as line(2).source" do
31
- assert_equal "class Foo\n", @source_file.line(2).source
32
- end
33
-
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
37
-
38
- should "return lines number 8 for missed_lines" do
39
- assert_equal [8], @source_file.missed_lines.map(&:line)
40
- end
41
-
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
45
-
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
49
-
50
- should "have 80% covered_percent" do
51
- assert_equal 80.0, @source_file.covered_percent
52
- end
53
- end
54
-
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
64
-
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
68
- end
69
-
70
- assert_match(/^Warning: coverage data provided/, captured_output)
71
- end
72
- end
73
-
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!
80
- end
81
- end
82
-
83
- should "handle iso-8859 encoded source files" do
84
- source_file = SimpleCov::SourceFile.new(source_fixture('iso-8859.rb'), [nil, nil, 1])
85
-
86
- assert_nothing_raised do
87
- source_file.process_skipped_lines!
88
- end
89
- end
90
-
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
99
-
100
- assert_nothing_raised do
101
- source_file.process_skipped_lines!
102
- end
103
- end
104
- end
105
- end if SimpleCov.usable?
106
-