simplecov 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +7 -7
  2. data/.gitignore +0 -1
  3. data/.rubocop.yml +69 -0
  4. data/.travis.yml +12 -0
  5. data/CHANGELOG.md +59 -21
  6. data/Gemfile +22 -15
  7. data/MIT-LICENSE +1 -1
  8. data/README.md +198 -176
  9. data/Rakefile +17 -8
  10. data/doc/alternate-formatters.md +36 -0
  11. data/doc/commercial-services.md +20 -0
  12. data/doc/editor-integration.md +13 -0
  13. data/features/rspec_basic.feature +3 -2
  14. data/features/rspec_groups_and_filters_complex.feature +2 -0
  15. data/features/rspec_groups_using_filter_class.feature +3 -2
  16. data/features/step_definitions/html_steps.rb +6 -7
  17. data/features/step_definitions/simplecov_steps.rb +18 -16
  18. data/features/step_definitions/transformers.rb +2 -2
  19. data/features/step_definitions/web_steps.rb +4 -4
  20. data/features/support/env.rb +18 -15
  21. data/lib/simplecov/command_guesser.rb +33 -34
  22. data/lib/simplecov/configuration.rb +238 -234
  23. data/lib/simplecov/defaults.rb +37 -36
  24. data/lib/simplecov/exit_codes.rb +7 -5
  25. data/lib/simplecov/file_list.rb +38 -36
  26. data/lib/simplecov/filter.rb +12 -2
  27. data/lib/simplecov/formatter/simple_formatter.rb +1 -1
  28. data/lib/simplecov/formatter.rb +2 -2
  29. data/lib/simplecov/jruby_fix.rb +4 -4
  30. data/lib/simplecov/last_run.rb +15 -13
  31. data/lib/simplecov/merge_helpers.rb +26 -27
  32. data/lib/simplecov/no_defaults.rb +2 -2
  33. data/lib/simplecov/profiles.rb +21 -19
  34. data/lib/simplecov/railtie.rb +1 -1
  35. data/lib/simplecov/railties/tasks.rake +7 -7
  36. data/lib/simplecov/result.rb +5 -5
  37. data/lib/simplecov/result_merger.rb +65 -62
  38. data/lib/simplecov/source_file.rb +23 -24
  39. data/lib/simplecov/version.rb +20 -1
  40. data/lib/simplecov.rb +35 -24
  41. data/simplecov.gemspec +15 -12
  42. data/test/faked_project/Gemfile +5 -5
  43. data/test/faked_project/Rakefile +4 -4
  44. data/test/faked_project/features/step_definitions/my_steps.rb +3 -4
  45. data/test/faked_project/features/support/env.rb +5 -5
  46. data/test/faked_project/lib/faked_project/some_class.rb +3 -4
  47. data/test/faked_project/lib/faked_project.rb +1 -1
  48. data/test/faked_project/spec/faked_spec.rb +2 -2
  49. data/test/faked_project/spec/forking_spec.rb +7 -0
  50. data/test/faked_project/spec/meta_magic_spec.rb +1 -1
  51. data/test/faked_project/spec/some_class_spec.rb +3 -3
  52. data/test/faked_project/spec/spec_helper.rb +4 -8
  53. data/test/faked_project/test/faked_test.rb +2 -2
  54. data/test/faked_project/test/meta_magic_test.rb +1 -1
  55. data/test/faked_project/test/some_class_test.rb +3 -3
  56. data/test/faked_project/test/test_helper.rb +5 -9
  57. data/test/fixtures/app/controllers/sample_controller.rb +1 -1
  58. data/test/fixtures/app/models/user.rb +1 -1
  59. data/test/fixtures/deleted_source_sample.rb +3 -3
  60. data/test/fixtures/frameworks/rspec_bad.rb +4 -4
  61. data/test/fixtures/frameworks/rspec_good.rb +4 -4
  62. data/test/fixtures/frameworks/testunit_bad.rb +3 -3
  63. data/test/fixtures/frameworks/testunit_good.rb +3 -3
  64. data/test/fixtures/resultset2.rb +0 -1
  65. data/test/fixtures/sample.rb +1 -1
  66. data/test/fixtures/utf-8.rb +1 -1
  67. data/test/helper.rb +9 -11
  68. data/test/test_1_8_fallbacks.rb +7 -7
  69. data/test/test_command_guesser.rb +8 -8
  70. data/test/test_deleted_source.rb +3 -3
  71. data/test/test_file_list.rb +9 -7
  72. data/test/test_filters.rb +30 -14
  73. data/test/test_merge_helpers.rb +31 -24
  74. data/test/test_result.rb +32 -23
  75. data/test/test_return_codes.rb +10 -6
  76. data/test/test_source_file.rb +5 -38
  77. data/test/test_source_file_line.rb +17 -17
  78. metadata +146 -64
  79. data/lib/simplecov/json.rb +0 -27
@@ -1,7 +1,7 @@
1
1
  # Foo class
2
2
  class Foo
3
3
  def initialize
4
- @foo = 'baz'
4
+ @foo = "baz"
5
5
  end
6
6
 
7
7
  def bar
@@ -1,3 +1,3 @@
1
1
  # encoding: utf-8
2
2
 
3
- puts '135°C'
3
+ puts "135°C"
data/test/helper.rb CHANGED
@@ -1,18 +1,16 @@
1
- require 'bundler/setup'
2
- require 'simplecov'
3
- require 'test/unit'
4
- require 'shoulda'
1
+ require "bundler/setup"
2
+ require "simplecov"
3
+ require "minitest/autorun"
4
+ require "shoulda"
5
5
 
6
- SimpleCov.coverage_dir('tmp/coverage')
6
+ SimpleCov.coverage_dir("tmp/coverage")
7
7
 
8
- class Test::Unit::TestCase
9
- def source_fixture(filename)
10
- File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', filename))
11
- end
8
+ def source_fixture(filename)
9
+ File.expand_path(File.join(File.dirname(__FILE__), "fixtures", filename))
12
10
  end
13
11
 
14
- require 'shoulda_macros'
15
- Test::Unit::TestCase.send :extend, ShouldaMacros
12
+ require "shoulda_macros"
13
+ Minitest::Test.send :extend, ShouldaMacros
16
14
 
17
15
  # Taken from http://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby
18
16
  require "stringio"
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
3
  # Tests that verify that on 1.8 versions of ruby, simplecov simply
4
4
  # does not launch and does not cause errors on the way
@@ -6,26 +6,26 @@ require 'helper'
6
6
  # TODO: This should be expanded upon all methods that could potentially
7
7
  # be called in a test/spec-helper simplecov config block
8
8
  #
9
- class Test18FallBacks < Test::Unit::TestCase
9
+ class Test18FallBacks < Minitest::Test
10
10
  should "return false when calling SimpleCov.start" do
11
11
  assert_equal false, SimpleCov.start
12
12
  end
13
13
 
14
14
  should "return false when calling SimpleCov.start with a block" do
15
- assert_equal false, SimpleCov.start { raise "Shouldn't reach this!?" }
15
+ assert_equal false, SimpleCov.start { fail "Shouldn't reach this!?" }
16
16
  end
17
17
 
18
18
  should "return false when calling SimpleCov.configure with a block" do
19
- assert_equal false, SimpleCov.configure { raise "Shouldn't reach this!?" }
19
+ assert_equal false, SimpleCov.configure { fail "Shouldn't reach this!?" }
20
20
  end
21
21
 
22
22
  should "allow to define a profile" do
23
23
  begin
24
- SimpleCov.profiles.define 'testprofile' do
25
- add_filter '/config/'
24
+ SimpleCov.profiles.define "testprofile" do
25
+ add_filter "/config/"
26
26
  end
27
27
  rescue => err
28
28
  assert false, "Profile definition should have been fine, but raised #{err}"
29
29
  end
30
30
  end
31
- end if RUBY_VERSION.start_with? '1.8'
31
+ end if RUBY_VERSION.start_with? "1.8"
@@ -1,6 +1,6 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
- class TestCommandGuesser < Test::Unit::TestCase
3
+ class TestCommandGuesser < Minitest::Test
4
4
  def self.should_guess_command_name(expectation, *argv)
5
5
  argv.each do |args|
6
6
  should "return '#{expectation}' for '#{args}'" do
@@ -10,10 +10,10 @@ class TestCommandGuesser < Test::Unit::TestCase
10
10
  end
11
11
  end
12
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!
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
19
  end if SimpleCov.usable?
@@ -1,11 +1,11 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
3
  # Test to verify correct handling of deleted files,
4
4
  # see issue #9 on github
5
- class TestDeletedSource < Test::Unit::TestCase
5
+ class TestDeletedSource < Minitest::Test
6
6
  context "A source file which is subsequently deleted" do
7
7
  should "not cause an error" do
8
- Dir.chdir(File.join(File.dirname(__FILE__), 'fixtures')) do
8
+ Dir.chdir(File.join(File.dirname(__FILE__), "fixtures")) do
9
9
  `ruby deleted_source_sample.rb`
10
10
  assert_equal 0, $?.exitstatus
11
11
  end
@@ -1,11 +1,13 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
- class TestFileList < Test::Unit::TestCase
3
+ class TestFileList < Minitest::Test
4
4
  context "With a file list from a result" do
5
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, 2, 2, 0, nil, nil, 0, nil, nil, nil]}
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
+ }
9
11
  @file_list = SimpleCov::Result.new(original_result).files
10
12
  end
11
13
 
@@ -15,7 +17,7 @@ class TestFileList < Test::Unit::TestCase
15
17
  should("have 14 lines_of_code") { assert_equal 14, @file_list.lines_of_code }
16
18
  should("have 3 skipped_lines") { assert_equal 3, @file_list.skipped_lines }
17
19
 
18
- should("have correct covered_percent") { assert_equal 100.0*11/14, @file_list.covered_percent }
19
- should("have correct covered_strength") { assert_equal 13.to_f/14, @file_list.covered_strength }
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 }
20
22
  end
21
23
  end if SimpleCov.usable?
data/test/test_filters.rb CHANGED
@@ -1,44 +1,60 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
- class TestFilters < Test::Unit::TestCase
3
+ class TestFilters < Minitest::Test
4
4
  context "A source file initialized with some coverage data" do
5
5
  setup do
6
- @source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
6
+ @source_file = SimpleCov::SourceFile.new(source_fixture("sample.rb"), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
7
7
  end
8
8
 
9
9
  should "not match a new SimpleCov::StringFilter 'foobar'" do
10
- assert !SimpleCov::StringFilter.new('foobar').matches?(@source_file)
10
+ assert !SimpleCov::StringFilter.new("foobar").matches?(@source_file)
11
11
  end
12
12
 
13
13
  should "not match a new SimpleCov::StringFilter 'some/path'" do
14
- assert !SimpleCov::StringFilter.new('some/path').matches?(@source_file)
14
+ assert !SimpleCov::StringFilter.new("some/path").matches?(@source_file)
15
15
  end
16
16
 
17
17
  should "match a new SimpleCov::StringFilter 'test/fixtures'" do
18
- assert SimpleCov::StringFilter.new('test/fixtures').matches?(@source_file)
18
+ assert SimpleCov::StringFilter.new("test/fixtures").matches?(@source_file)
19
19
  end
20
20
 
21
21
  should "match a new SimpleCov::StringFilter 'test/fixtures/sample.rb'" do
22
- assert SimpleCov::StringFilter.new('test/fixtures/sample.rb').matches?(@source_file)
22
+ assert SimpleCov::StringFilter.new("test/fixtures/sample.rb").matches?(@source_file)
23
23
  end
24
24
 
25
25
  should "match a new SimpleCov::StringFilter 'sample.rb'" do
26
- assert SimpleCov::StringFilter.new('sample.rb').matches?(@source_file)
26
+ assert SimpleCov::StringFilter.new("sample.rb").matches?(@source_file)
27
27
  end
28
28
 
29
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)
30
+ assert !SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "foo.rb" }).matches?(@source_file)
31
31
  end
32
32
 
33
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)
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)
35
47
  end
36
48
  end
37
49
 
38
50
  context "with no filters set up and a basic source file in an array" do
39
51
  setup do
40
- SimpleCov.filters = []
41
- @files = [SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])]
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
42
58
  end
43
59
 
44
60
  should "return 0 items after executing SimpleCov.filtered on files when using a 'sample' string filter" do
@@ -57,14 +73,14 @@ class TestFilters < Test::Unit::TestCase
57
73
  end
58
74
 
59
75
  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|
76
+ SimpleCov.add_filter do
61
77
  true
62
78
  end
63
79
  assert_equal 0, SimpleCov.filtered(@files).count
64
80
  end
65
81
 
66
82
  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|
83
+ SimpleCov.add_filter do
68
84
  false
69
85
  end
70
86
  assert_equal 1, SimpleCov.filtered(@files).count
@@ -1,18 +1,26 @@
1
- require 'helper'
1
+ require "helper"
2
+
3
+ class TestMergeHelpers < Minitest::Test
4
+ def self.test_order
5
+ :alpha
6
+ end
2
7
 
3
- class TestMergeHelpers < Test::Unit::TestCase
4
8
  context "With two faked coverage resultsets" do
5
9
  setup do
6
10
  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]}
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
+ }
16
24
  end
17
25
 
18
26
  context "a merge" do
@@ -21,36 +29,36 @@ class TestMergeHelpers < Test::Unit::TestCase
21
29
  end
22
30
 
23
31
  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')]
32
+ assert_equal [1, 1, 2, 2, nil, nil, 2, 2, nil, nil], @merged[source_fixture("sample.rb")]
25
33
  end
26
34
 
27
35
  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')]
36
+ assert_equal [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil], @merged[source_fixture("app/models/user.rb")]
29
37
  end
30
38
 
31
39
  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')]
40
+ assert_equal [nil, 4, 2, 1, nil, nil, 2, 0, nil, nil], @merged[source_fixture("app/controllers/sample_controller.rb")]
33
41
  end
34
42
 
35
43
  should "have proper results for resultset1.rb" do
36
- assert_equal [1, 1, 1, 1], @merged[source_fixture('resultset1.rb')]
44
+ assert_equal [1, 1, 1, 1], @merged[source_fixture("resultset1.rb")]
37
45
  end
38
46
 
39
47
  should "have proper results for resultset2.rb" do
40
- assert_equal [nil, 1, 1, nil], @merged[source_fixture('resultset2.rb')]
48
+ assert_equal [nil, 1, 1, nil], @merged[source_fixture("resultset2.rb")]
41
49
  end
42
50
  end
43
51
 
44
52
  # See Github issue #6
45
53
  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
54
+ File.open(SimpleCov::ResultMerger.resultset_path, "w+") { |f| f.puts "" }
55
+ assert_empty SimpleCov::ResultMerger.resultset
48
56
  end
49
57
 
50
58
  # See Github issue #6
51
59
  should "return an empty hash when the resultset cache file is not present" do
52
60
  system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
53
- assert_equal Hash.new, SimpleCov::ResultMerger.resultset
61
+ assert_empty SimpleCov::ResultMerger.resultset
54
62
  end
55
63
 
56
64
  context "and results generated from those" do
@@ -68,21 +76,21 @@ class TestMergeHelpers < Test::Unit::TestCase
68
76
  assert SimpleCov::ResultMerger.store_result(@result2)
69
77
  end
70
78
 
71
- should "have stored data in resultset_path yaml file" do
79
+ should "have stored data in resultset_path JSON file" do
72
80
  assert File.readlines(SimpleCov::ResultMerger.resultset_path).length > 50
73
81
  end
74
82
 
75
83
  should "return a hash containing keys ['result1' and 'result2'] for resultset" do
76
- assert_equal ['result1', 'result2'], SimpleCov::ResultMerger.resultset.keys.sort
84
+ assert_equal %w(result1 result2), SimpleCov::ResultMerger.resultset.keys.sort
77
85
  end
78
86
 
79
87
  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)
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)
81
89
  end
82
90
 
83
91
  context "with second result way above the merge_timeout" do
84
92
  setup do
85
- @result2.created_at = Time.now - 172800 # two days ago
93
+ @result2.created_at = Time.now - 172_800 # two days ago
86
94
  assert SimpleCov::ResultMerger.store_result(@result2)
87
95
  end
88
96
 
@@ -99,7 +107,6 @@ class TestMergeHelpers < Test::Unit::TestCase
99
107
  end
100
108
  end
101
109
  end
102
-
103
110
  end
104
111
  end
105
112
  end if SimpleCov.usable?
data/test/test_result.rb CHANGED
@@ -1,14 +1,23 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
- class TestResult < Test::Unit::TestCase
3
+ class TestResult < Minitest::Test # rubocop:disable Metrics/ClassLength
4
4
  context "With a (mocked) Coverage.result" do
5
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]}
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
12
21
  end
13
22
 
14
23
  context "a simple cov result initialized from that" do
@@ -20,7 +29,7 @@ class TestResult < Test::Unit::TestCase
20
29
 
21
30
  should "have 3 source files" do
22
31
  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"
32
+ assert @result.source_files.all? { |s| s.instance_of?(SimpleCov::SourceFile) }, "Not all instances are of SimpleCov::SourceFile type"
24
33
  end
25
34
 
26
35
  should "return an instance of SimpleCov::FileList for source_files and files" do
@@ -34,7 +43,7 @@ class TestResult < Test::Unit::TestCase
34
43
 
35
44
  should "have accurate covered percent" do
36
45
  # 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
46
+ assert_equal 100.0 * 13 / 15, @result.covered_percent
38
47
  end
39
48
 
40
49
  [:covered_percent, :covered_strength, :covered_lines, :missed_lines, :total_lines].each do |msg|
@@ -47,7 +56,7 @@ class TestResult < Test::Unit::TestCase
47
56
  setup { @hash = @result.to_hash }
48
57
  should("be a hash") { assert_equal Hash, @hash.class }
49
58
 
50
- context "loaded back with from_yaml" do
59
+ context "loaded back with from_hash" do
51
60
  setup { @dumped_result = SimpleCov::Result.from_hash(@hash) }
52
61
 
53
62
  should "have 3 source files" do
@@ -75,7 +84,7 @@ class TestResult < Test::Unit::TestCase
75
84
 
76
85
  context "with some filters set up" do
77
86
  setup do
78
- SimpleCov.add_filter 'sample.rb'
87
+ SimpleCov.add_filter "sample.rb"
79
88
  end
80
89
 
81
90
  should "have 2 files in a new simple cov result" do
@@ -89,10 +98,10 @@ class TestResult < Test::Unit::TestCase
89
98
 
90
99
  context "with groups set up for all files" do
91
100
  setup do
92
- SimpleCov.add_group 'Models', 'app/models'
93
- SimpleCov.add_group 'Controllers', 'app/controllers'
94
- SimpleCov.add_group 'Other' do |src_file|
95
- File.basename(src_file.filename) == 'sample.rb'
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"
96
105
  end
97
106
  @result = SimpleCov::Result.new(@original_result)
98
107
  end
@@ -102,15 +111,15 @@ class TestResult < Test::Unit::TestCase
102
111
  end
103
112
 
104
113
  should "have user.rb in 'Models' group" do
105
- assert_equal 'user.rb', File.basename(@result.groups['Models'].first.filename)
114
+ assert_equal "user.rb", File.basename(@result.groups["Models"].first.filename)
106
115
  end
107
116
 
108
117
  should "have sample_controller.rb in 'Controllers' group" do
109
- assert_equal 'sample_controller.rb', File.basename(@result.groups['Controllers'].first.filename)
118
+ assert_equal "sample_controller.rb", File.basename(@result.groups["Controllers"].first.filename)
110
119
  end
111
120
 
112
121
  context "and simple formatter being used" do
113
- setup {SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter}
122
+ setup { SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter }
114
123
 
115
124
  should "return a formatted string with result.format!" do
116
125
  assert_equal String, @result.format!.class
@@ -136,8 +145,8 @@ class TestResult < Test::Unit::TestCase
136
145
  context "with groups set up that do not match all files" do
137
146
  setup do
138
147
  SimpleCov.configure do
139
- add_group 'Models', 'app/models'
140
- add_group 'Controllers', 'app/controllers'
148
+ add_group "Models", "app/models"
149
+ add_group "Controllers", "app/controllers"
141
150
  end
142
151
  @result = SimpleCov::Result.new(@original_result)
143
152
  end
@@ -153,11 +162,11 @@ class TestResult < Test::Unit::TestCase
153
162
  end
154
163
 
155
164
  should "have sample.rb in 'Ungrouped' group" do
156
- assert_equal 'sample.rb', File.basename(@result.groups['Ungrouped'].first.filename)
165
+ assert_equal "sample.rb", File.basename(@result.groups["Ungrouped"].first.filename)
157
166
  end
158
167
 
159
168
  should "return all groups as instances of SimpleCov::FileList" do
160
- @result.groups.each do |name, files|
169
+ @result.groups.each_value do |files|
161
170
  assert_equal SimpleCov::FileList, files.class
162
171
  end
163
172
  end
@@ -1,13 +1,17 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
3
  # Make sure that exit codes of tests are propagated properly when using
4
4
  # simplecov. See github issue #5
5
- class TestReturnCodes < Test::Unit::TestCase
5
+ class TestReturnCodes < Minitest::Test
6
+ def self.test_order
7
+ :alpha
8
+ end
9
+
6
10
  context "Inside fixtures/frameworks" do
7
11
  setup do
8
12
  @current_dir = Dir.getwd
9
- Dir.chdir(File.join(File.dirname(__FILE__), 'fixtures', 'frameworks'))
10
- FileUtils.rm_rf('./coverage')
13
+ Dir.chdir(File.join(File.dirname(__FILE__), "fixtures", "frameworks"))
14
+ FileUtils.rm_rf("./coverage")
11
15
  end
12
16
 
13
17
  should "have return code 0 when running testunit_good.rb" do
@@ -22,12 +26,12 @@ class TestReturnCodes < Test::Unit::TestCase
22
26
 
23
27
  should "have non-0 return code when running testunit_bad.rb" do
24
28
  `ruby testunit_bad.rb`
25
- assert_not_equal 0, $?.exitstatus
29
+ refute_equal 0, $?.exitstatus
26
30
  end
27
31
 
28
32
  should "have return code 1 when running rspec_bad.rb" do
29
33
  `rspec rspec_bad.rb`
30
- assert_not_equal 0, $?.exitstatus
34
+ refute_equal 0, $?.exitstatus
31
35
  end
32
36
 
33
37
  teardown do
@@ -1,10 +1,10 @@
1
- require 'helper'
1
+ require "helper"
2
2
 
3
- class TestSourceFile < Test::Unit::TestCase
3
+ class TestSourceFile < Minitest::Test
4
4
  COVERAGE_FOR_SAMPLE_RB = [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, nil, nil, nil, nil, nil]
5
5
  context "A source file initialized with some coverage data" do
6
6
  setup do
7
- @source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB)
7
+ @source_file = SimpleCov::SourceFile.new(source_fixture("sample.rb"), COVERAGE_FOR_SAMPLE_RB)
8
8
  end
9
9
 
10
10
  should "have a filename" do
@@ -24,7 +24,7 @@ class TestSourceFile < Test::Unit::TestCase
24
24
  end
25
25
 
26
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)}
27
+ assert @source_file.lines.all? { |l| l.instance_of?(SimpleCov::SourceFile::Line) }
28
28
  end
29
29
 
30
30
  should "have 'class Foo' as line(2).source" do
@@ -54,7 +54,7 @@ class TestSourceFile < Test::Unit::TestCase
54
54
 
55
55
  context "Simulating potential Ruby 1.9 defect -- see Issue #56" do
56
56
  setup do
57
- @source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB + [nil])
57
+ @source_file = SimpleCov::SourceFile.new(source_fixture("sample.rb"), COVERAGE_FOR_SAMPLE_RB + [nil])
58
58
  end
59
59
 
60
60
  should "have 16 source lines regardless of extra data in coverage array" do
@@ -70,37 +70,4 @@ class TestSourceFile < Test::Unit::TestCase
70
70
  assert_match(/^Warning: coverage data provided/, captured_output)
71
71
  end
72
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
73
  end if SimpleCov.usable?
106
-