simplecov-patched 0.14.2

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 (126) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +31 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +88 -0
  5. data/.travis.yml +29 -0
  6. data/.yardopts +1 -0
  7. data/CHANGELOG.md +435 -0
  8. data/CONTRIBUTING.md +48 -0
  9. data/Gemfile +38 -0
  10. data/MIT-LICENSE +20 -0
  11. data/README.md +646 -0
  12. data/Rakefile +41 -0
  13. data/cucumber.yml +13 -0
  14. data/doc/alternate-formatters.md +36 -0
  15. data/doc/commercial-services.md +20 -0
  16. data/doc/editor-integration.md +13 -0
  17. data/features/config_autoload.feature +46 -0
  18. data/features/config_command_name.feature +45 -0
  19. data/features/config_coverage_dir.feature +33 -0
  20. data/features/config_deactivate_merging.feature +42 -0
  21. data/features/config_formatters.feature +77 -0
  22. data/features/config_merge_timeout.feature +39 -0
  23. data/features/config_nocov_token.feature +79 -0
  24. data/features/config_profiles.feature +44 -0
  25. data/features/config_project_name.feature +27 -0
  26. data/features/config_styles.feature +121 -0
  27. data/features/config_tracked_files.feature +29 -0
  28. data/features/cucumber_basic.feature +29 -0
  29. data/features/maximum_coverage_drop.feature +89 -0
  30. data/features/merging_test_unit_and_rspec.feature +44 -0
  31. data/features/minimum_coverage.feature +59 -0
  32. data/features/refuse_coverage_drop.feature +95 -0
  33. data/features/rspec_basic.feature +32 -0
  34. data/features/rspec_fails_on_initialization.feature +14 -0
  35. data/features/rspec_groups_and_filters_basic.feature +29 -0
  36. data/features/rspec_groups_and_filters_complex.feature +37 -0
  37. data/features/rspec_groups_using_filter_class.feature +41 -0
  38. data/features/rspec_without_simplecov.feature +20 -0
  39. data/features/skipping_code_blocks_manually.feature +70 -0
  40. data/features/step_definitions/html_steps.rb +44 -0
  41. data/features/step_definitions/simplecov_steps.rb +68 -0
  42. data/features/step_definitions/transformers.rb +13 -0
  43. data/features/step_definitions/web_steps.rb +64 -0
  44. data/features/support/env.rb +50 -0
  45. data/features/test_unit_basic.feature +34 -0
  46. data/features/test_unit_groups_and_filters_basic.feature +29 -0
  47. data/features/test_unit_groups_and_filters_complex.feature +35 -0
  48. data/features/test_unit_groups_using_filter_class.feature +40 -0
  49. data/features/test_unit_without_simplecov.feature +20 -0
  50. data/features/unicode_compatiblity.feature +67 -0
  51. data/lib/simplecov.rb +189 -0
  52. data/lib/simplecov/command_guesser.rb +59 -0
  53. data/lib/simplecov/configuration.rb +307 -0
  54. data/lib/simplecov/defaults.rb +121 -0
  55. data/lib/simplecov/exit_codes.rb +8 -0
  56. data/lib/simplecov/file_list.rb +59 -0
  57. data/lib/simplecov/filter.rb +54 -0
  58. data/lib/simplecov/formatter.rb +8 -0
  59. data/lib/simplecov/formatter/multi_formatter.rb +32 -0
  60. data/lib/simplecov/formatter/simple_formatter.rb +23 -0
  61. data/lib/simplecov/jruby_fix.rb +42 -0
  62. data/lib/simplecov/last_run.rb +24 -0
  63. data/lib/simplecov/load_global_config.rb +6 -0
  64. data/lib/simplecov/no_defaults.rb +2 -0
  65. data/lib/simplecov/profiles.rb +31 -0
  66. data/lib/simplecov/railtie.rb +7 -0
  67. data/lib/simplecov/railties/tasks.rake +11 -0
  68. data/lib/simplecov/raw_coverage.rb +39 -0
  69. data/lib/simplecov/result.rb +86 -0
  70. data/lib/simplecov/result_merger.rb +95 -0
  71. data/lib/simplecov/source_file.rb +196 -0
  72. data/lib/simplecov/version.rb +25 -0
  73. data/spec/1_8_fallbacks_spec.rb +31 -0
  74. data/spec/command_guesser_spec.rb +48 -0
  75. data/spec/config_loader_spec.rb +14 -0
  76. data/spec/configuration_spec.rb +35 -0
  77. data/spec/deleted_source_spec.rb +12 -0
  78. data/spec/faked_project/Gemfile +6 -0
  79. data/spec/faked_project/Rakefile +8 -0
  80. data/spec/faked_project/cucumber.yml +13 -0
  81. data/spec/faked_project/features/step_definitions/my_steps.rb +22 -0
  82. data/spec/faked_project/features/support/env.rb +12 -0
  83. data/spec/faked_project/features/test_stuff.feature +6 -0
  84. data/spec/faked_project/lib/faked_project.rb +11 -0
  85. data/spec/faked_project/lib/faked_project/framework_specific.rb +18 -0
  86. data/spec/faked_project/lib/faked_project/meta_magic.rb +24 -0
  87. data/spec/faked_project/lib/faked_project/some_class.rb +28 -0
  88. data/spec/faked_project/lib/faked_project/untested_class.rb +11 -0
  89. data/spec/faked_project/spec/faked_spec.rb +11 -0
  90. data/spec/faked_project/spec/forking_spec.rb +8 -0
  91. data/spec/faked_project/spec/meta_magic_spec.rb +15 -0
  92. data/spec/faked_project/spec/some_class_spec.rb +13 -0
  93. data/spec/faked_project/spec/spec_helper.rb +11 -0
  94. data/spec/faked_project/test/faked_test.rb +11 -0
  95. data/spec/faked_project/test/meta_magic_test.rb +13 -0
  96. data/spec/faked_project/test/some_class_test.rb +15 -0
  97. data/spec/faked_project/test/test_helper.rb +12 -0
  98. data/spec/file_list_spec.rb +50 -0
  99. data/spec/filters_spec.rb +98 -0
  100. data/spec/fixtures/app/controllers/sample_controller.rb +10 -0
  101. data/spec/fixtures/app/models/user.rb +10 -0
  102. data/spec/fixtures/deleted_source_sample.rb +15 -0
  103. data/spec/fixtures/frameworks/rspec_bad.rb +9 -0
  104. data/spec/fixtures/frameworks/rspec_good.rb +9 -0
  105. data/spec/fixtures/frameworks/testunit_bad.rb +9 -0
  106. data/spec/fixtures/frameworks/testunit_good.rb +9 -0
  107. data/spec/fixtures/iso-8859.rb +3 -0
  108. data/spec/fixtures/never.rb +2 -0
  109. data/spec/fixtures/resultset1.rb +4 -0
  110. data/spec/fixtures/resultset2.rb +4 -0
  111. data/spec/fixtures/sample.rb +16 -0
  112. data/spec/fixtures/skipped.rb +4 -0
  113. data/spec/fixtures/skipped_and_executed.rb +8 -0
  114. data/spec/fixtures/utf-8.rb +3 -0
  115. data/spec/helper.rb +26 -0
  116. data/spec/last_run_spec.rb +48 -0
  117. data/spec/multi_formatter_spec.rb +20 -0
  118. data/spec/raw_coverage_spec.rb +92 -0
  119. data/spec/result_merger_spec.rb +96 -0
  120. data/spec/result_spec.rb +209 -0
  121. data/spec/return_codes_spec.rb +34 -0
  122. data/spec/simplecov_spec.rb +110 -0
  123. data/spec/source_file_line_spec.rb +155 -0
  124. data/spec/source_file_spec.rb +141 -0
  125. data/spec/support/fail_rspec_on_ruby_warning.rb +75 -0
  126. metadata +320 -0
@@ -0,0 +1,12 @@
1
+ require "helper"
2
+
3
+ # Test to verify correct handling of deleted files
4
+ # See https://github.com/colszowka/simplecov/issues/9
5
+ describe "A source file which is subsequently deleted" do
6
+ it "does not cause an error" do
7
+ Dir.chdir(File.join(File.dirname(__FILE__), "fixtures")) do
8
+ `ruby deleted_source_sample.rb`
9
+ expect($?.exitstatus).to be_zero
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "simplecov", :path => "../../../"
4
+ gem "rake"
5
+ gem "rspec", ">= 2.6.0"
6
+ gem "cucumber"
@@ -0,0 +1,8 @@
1
+ require "bundler"
2
+
3
+ require "rake/testtask"
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << "lib" << "test"
6
+ test.test_files = FileList["test/**/*_test.rb"].sort
7
+ test.verbose = true
8
+ end
@@ -0,0 +1,13 @@
1
+ <%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
5
+ interp_opts = if defined?(RUBY_ENGINE)
6
+ " --tags ~@exclude-#{RUBY_ENGINE}"
7
+ else
8
+ ''
9
+ end
10
+ %>
11
+ default: <%= std_opts %><%= interp_opts %> features
12
+ wip: --tags @wip:30 --wip features<%= interp_opts %>
13
+ rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip<%= interp_opts %>
@@ -0,0 +1,22 @@
1
+ Given /^I want to keep stuff simple$/ do
2
+ expect(1).to eq(1)
3
+ end
4
+
5
+ When /^I write my cukes for the fake project$/ do
6
+ expect(1).to eq(1)
7
+ end
8
+
9
+ Then /^I make all necessary tests in a single step$/ do
10
+ expect(FakedProject.foo).to eq("bar")
11
+
12
+ expect(FrameworkSpecific.cucumber).to eq("Only tested in Cucumber")
13
+
14
+ expect(FakedProject.a_class_method).to eq("this is a mixed-in class method")
15
+
16
+ expect(FakedProject.new.an_instance_method).to eq("this is a mixed-in instance method")
17
+ expect(FakedProject.new.dynamic).to eq("A dynamically defined instance method")
18
+
19
+ something = SomeClass.new("foo")
20
+ expect(something.reverse).to eq("oof")
21
+ expect(something.compare_with("foo")).to be true
22
+ end
@@ -0,0 +1,12 @@
1
+ require "bundler/setup"
2
+
3
+ # We're injecting simplecov_config via aruba in cucumber here
4
+ # depending on what the test case is...
5
+ begin
6
+ require File.join(File.dirname(__FILE__), "simplecov_config")
7
+ rescue LoadError
8
+ $stderr.puts "No SimpleCov config file found!"
9
+ end
10
+
11
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "/../../lib"))
12
+ require "faked_project"
@@ -0,0 +1,6 @@
1
+ Feature: Foo
2
+
3
+ Scenario: Test stuff
4
+ Given I want to keep stuff simple
5
+ When I write my cukes for the fake project
6
+ Then I make all necessary tests in a single step
@@ -0,0 +1,11 @@
1
+ class FakedProject
2
+ def self.foo
3
+ "bar"
4
+ end
5
+ end
6
+
7
+ Dir[File.join(File.dirname(__FILE__), "faked_project/*.rb")].reject { |f| /untested/.match(f) }.each do |file|
8
+ require file # Require all source files in project dynamically so we can inject some stuff depending on test situation
9
+ end
10
+
11
+ FakedProject.send :include, MetaMagic
@@ -0,0 +1,18 @@
1
+ # A pile of methods that only get tested in their frameworks
2
+ # and thus make this file only 100% covered when all framework test
3
+ # results are merged
4
+ module FrameworkSpecific
5
+ class << self
6
+ def cucumber
7
+ "Only tested in Cucumber"
8
+ end
9
+
10
+ def rspec
11
+ "Only tested in RSpec"
12
+ end
13
+
14
+ def test_unit
15
+ "Only tested in Test/Unit"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ module MetaMagic
2
+ module ClassMethods
3
+ def a_class_method
4
+ "this is a mixed-in class method"
5
+ end
6
+ end
7
+
8
+ module InstanceMethods
9
+ def an_instance_method
10
+ "this is a mixed-in instance method"
11
+ end
12
+ end
13
+
14
+ def self.included(base)
15
+ base.send :extend, ClassMethods
16
+ base.send :include, InstanceMethods
17
+
18
+ base.class_eval do
19
+ define_method :dynamic do
20
+ "A dynamically defined instance method"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ class SomeClass
2
+ attr_reader :label
3
+ attr_accessor :some_attr
4
+
5
+ def initialize(label)
6
+ @label = label
7
+ end
8
+
9
+ def reverse
10
+ label.reverse
11
+ end
12
+
13
+ def compare_with(item)
14
+ if item == label
15
+ return true
16
+ else
17
+ raise "Item does not match label"
18
+ end
19
+ rescue
20
+ false
21
+ end
22
+
23
+ private
24
+
25
+ def uncovered
26
+ "private method"
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ class UntestedClass
2
+ def initialize(yogurts)
3
+ @yogurts = yogurts
4
+ end
5
+
6
+ def power_level
7
+ @yogurts.map do |yo|
8
+ yo.experience_points**2
9
+ end.reduce(0, &:+)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe FakedProject do
4
+ it "should return proper foo" do
5
+ expect(FakedProject.foo).to eq("bar")
6
+ end
7
+
8
+ it "should test it's framework specific method" do
9
+ expect(FrameworkSpecific.rspec).to eq("Only tested in RSpec")
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+
3
+ describe "forking" do
4
+ it do
5
+ # TODO: The defined?(RUBY_ENGINE) check can be dropped for simplecov 1.0.0
6
+ Process.waitpid(Kernel.fork {}) unless defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe FakedProject do
4
+ it "should have added a class method to FakedProject" do
5
+ expect(FakedProject.a_class_method).to eq("this is a mixed-in class method")
6
+ end
7
+
8
+ it "should have added a mixed-in instance method to FakedProject" do
9
+ expect(subject.an_instance_method).to eq("this is a mixed-in instance method")
10
+ end
11
+
12
+ it "should have added a dyntamically-defined instance method to FakedProject" do
13
+ expect(subject.dynamic).to eq("A dynamically defined instance method")
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe SomeClass do
4
+ subject { SomeClass.new("foo") }
5
+
6
+ it "should be reversible" do
7
+ expect(subject.reverse).to eq("oof")
8
+ end
9
+
10
+ it "should compare with 'foo'" do
11
+ expect(subject.compare_with("foo")).to be true
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require "bundler/setup"
2
+
3
+ # We're injecting simplecov_config via aruba in cucumber here
4
+ # depending on what the test case is...
5
+ begin
6
+ require File.join(File.dirname(__FILE__), "simplecov_config")
7
+ rescue LoadError
8
+ $stderr.puts "No SimpleCov config file found!"
9
+ end
10
+
11
+ require "faked_project"
@@ -0,0 +1,11 @@
1
+ require "test_helper"
2
+
3
+ class FakedTest < Test::Unit::TestCase
4
+ def test_something
5
+ assert_equal "bar", FakedProject.foo
6
+ end
7
+
8
+ def test_framework_specific
9
+ assert_equal "Only tested in Test/Unit", FrameworkSpecific.test_unit
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require "test_helper"
2
+
3
+ class MetaMagicTest < Test::Unit::TestCase
4
+ def test_class_methods
5
+ assert_equal "this is a mixed-in class method", FakedProject.a_class_method
6
+ end
7
+
8
+ def test_instance_methods
9
+ p = FakedProject.new
10
+ assert_equal "this is a mixed-in instance method", p.an_instance_method
11
+ assert_equal "A dynamically defined instance method", p.dynamic
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require "test_helper"
2
+
3
+ class SomeClassTest < Test::Unit::TestCase
4
+ def setup
5
+ @instance = SomeClass.new("foo")
6
+ end
7
+
8
+ def test_reverse
9
+ assert_equal "oof", @instance.reverse
10
+ end
11
+
12
+ def test_comparison
13
+ assert @instance.compare_with("foo")
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require "bundler/setup"
2
+
3
+ # We're injecting simplecov_config via aruba in cucumber here
4
+ # depending on what the test case is...
5
+ begin
6
+ require File.join(File.dirname(__FILE__), "simplecov_config")
7
+ rescue LoadError
8
+ $stderr.puts "No SimpleCov config file found!"
9
+ end
10
+
11
+ require "faked_project"
12
+ require "test/unit"
@@ -0,0 +1,50 @@
1
+ require "helper"
2
+
3
+ if SimpleCov.usable?
4
+ describe SimpleCov::Result do
5
+ subject do
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
+ }
11
+ SimpleCov::Result.new(original_result).files
12
+ end
13
+
14
+ it "has 11 covered lines" do
15
+ expect(subject.covered_lines).to eq(11)
16
+ end
17
+
18
+ it "has 3 missed lines" do
19
+ expect(subject.missed_lines).to eq(3)
20
+ end
21
+
22
+ it "has 17 never lines" do
23
+ expect(subject.never_lines).to eq(17)
24
+ end
25
+
26
+ it "has 14 lines of code" do
27
+ expect(subject.lines_of_code).to eq(14)
28
+ end
29
+
30
+ it "has 5 skipped lines" do
31
+ expect(subject.skipped_lines).to eq(5)
32
+ end
33
+
34
+ it "has the correct covered percent" do
35
+ expect(subject.covered_percent).to eq(78.57142857142857)
36
+ end
37
+
38
+ it "has the correct covered percentages" do
39
+ expect(subject.covered_percentages).to eq([50.0, 80.0, 100.0])
40
+ end
41
+
42
+ it "has the correct least covered file" do
43
+ expect(subject.least_covered_file).to match(/sample_controller.rb/)
44
+ end
45
+
46
+ it "has the correct covered strength" do
47
+ expect(subject.covered_strength).to eq(0.9285714285714286)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,98 @@
1
+ require "helper"
2
+
3
+ if SimpleCov.usable?
4
+ describe SimpleCov::SourceFile do
5
+ subject do
6
+ SimpleCov::SourceFile.new(source_fixture("sample.rb"), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
7
+ end
8
+
9
+ it "doesn't match a new SimpleCov::StringFilter 'foobar'" do
10
+ expect(SimpleCov::StringFilter.new("foobar")).not_to be_matches subject
11
+ end
12
+
13
+ it "doesn't match a new SimpleCov::StringFilter 'some/path'" do
14
+ expect(SimpleCov::StringFilter.new("some/path")).not_to be_matches subject
15
+ end
16
+
17
+ it "matches a new SimpleCov::StringFilter 'spec/fixtures'" do
18
+ expect(SimpleCov::StringFilter.new("spec/fixtures")).to be_matches subject
19
+ end
20
+
21
+ it "matches a new SimpleCov::StringFilter 'spec/fixtures/sample.rb'" do
22
+ expect(SimpleCov::StringFilter.new("spec/fixtures/sample.rb")).to be_matches subject
23
+ end
24
+
25
+ it "matches a new SimpleCov::StringFilter 'sample.rb'" do
26
+ expect(SimpleCov::StringFilter.new("sample.rb")).to be_matches subject
27
+ end
28
+
29
+ it "doesn't match a new SimpleCov::BlockFilter that is not applicable" do
30
+ expect(SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "foo.rb" })).not_to be_matches subject
31
+ end
32
+
33
+ it "matches a new SimpleCov::BlockFilter that is applicable" do
34
+ expect(SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "sample.rb" })).to be_matches subject
35
+ end
36
+
37
+ it "matches a new SimpleCov::ArrayFilter when 'sample.rb' is passed as array" do
38
+ expect(SimpleCov::ArrayFilter.new(["sample.rb"])).to be_matches subject
39
+ end
40
+
41
+ it "doesn't match a new SimpleCov::ArrayFilter when a file path different than 'sample.rb' is passed as array" do
42
+ expect(SimpleCov::ArrayFilter.new(["other_file.rb"])).not_to be_matches subject
43
+ end
44
+
45
+ it "matches a new SimpleCov::ArrayFilter when two file paths including 'sample.rb' are passed as array" do
46
+ expect(SimpleCov::ArrayFilter.new(["sample.rb", "other_file.rb"])).to be_matches subject
47
+ end
48
+
49
+ context "with no filters set up and a basic source file in an array" do
50
+ before do
51
+ @prev_filters = SimpleCov.filters
52
+ SimpleCov.filters = []
53
+ end
54
+
55
+ subject do
56
+ [SimpleCov::SourceFile.new(source_fixture("sample.rb"), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])]
57
+ end
58
+
59
+ after do
60
+ SimpleCov.filters = @prev_filters
61
+ end
62
+
63
+ it 'returns 0 items after executing SimpleCov.filtered on files when using a "sample" string filter' do
64
+ SimpleCov.add_filter "sample"
65
+ expect(SimpleCov.filtered(subject).count).to be_zero
66
+ end
67
+
68
+ it 'returns 0 items after executing SimpleCov.filtered on files when using a "spec/fixtures" string filter' do
69
+ SimpleCov.add_filter "spec/fixtures"
70
+ expect(SimpleCov.filtered(subject).count).to be_zero
71
+ end
72
+
73
+ it 'returns 1 item after executing SimpleCov.filtered on files when using a "fooo" string filter' do
74
+ SimpleCov.add_filter "fooo"
75
+ expect(SimpleCov.filtered(subject).count).to eq(1)
76
+ end
77
+
78
+ it "returns 0 items after executing SimpleCov.filtered on files when using a block filter that returns true" do
79
+ SimpleCov.add_filter do
80
+ true
81
+ end
82
+ expect(SimpleCov.filtered(subject).count).to be_zero
83
+ end
84
+
85
+ it "returns 1 item after executing SimpleCov.filtered on files when using an always-false block filter" do
86
+ SimpleCov.add_filter do
87
+ false
88
+ end
89
+ expect(SimpleCov.filtered(subject).count).to eq(1)
90
+ end
91
+
92
+ it "returns a FileList after filtering" do
93
+ SimpleCov.add_filter "fooo"
94
+ expect(SimpleCov.filtered(subject)).to be_a SimpleCov::FileList
95
+ end
96
+ end
97
+ end
98
+ end