simplecov 0.11.1 → 0.13.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.
data/lib/simplecov.rb CHANGED
@@ -2,13 +2,18 @@
2
2
  # Code coverage for ruby 1.9. Please check out README for a full introduction.
3
3
  #
4
4
  # Coverage may be inaccurate under JRUBY.
5
- if defined?(JRUBY_VERSION)
6
- if ENV["JRUBY_OPTS"].to_s !~ /-Xcli.debug=true/
7
- warn "Coverage may be inaccurate; Try setting JRUBY_OPTS=\"-Xcli.debug=true --debug\""
8
- # see https://github.com/metricfu/metric_fu/pull/226
9
- # https://github.com/jruby/jruby/issues/1196
10
- # https://jira.codehaus.org/browse/JRUBY-6106
11
- # https://github.com/colszowka/simplecov/issues/86
5
+ if defined?(JRUBY_VERSION) && defined?(JRuby)
6
+
7
+ # @see https://github.com/jruby/jruby/issues/1196
8
+ # @see https://github.com/metricfu/metric_fu/pull/226
9
+ # @see https://github.com/colszowka/simplecov/issues/420
10
+ # @see https://github.com/colszowka/simplecov/issues/86
11
+ # @see https://jira.codehaus.org/browse/JRUBY-6106
12
+
13
+ unless org.jruby.RubyInstanceConfig.FULL_TRACE_ENABLED
14
+ warn 'Coverage may be inaccurate; set the "--debug" command line option,' \
15
+ ' or do JRUBY_OPTS="--debug"' \
16
+ ' or set the "debug.fullTrace=true" option in your .jrubyrc'
12
17
  end
13
18
  end
14
19
  module SimpleCov
@@ -53,9 +58,9 @@ module SimpleCov
53
58
  # their coverage to zero.
54
59
  #
55
60
  def add_not_loaded_files(result)
56
- if @track_files_glob
61
+ if track_files
57
62
  result = result.dup
58
- Dir[@track_files_glob].each do |file|
63
+ Dir[track_files].each do |file|
59
64
  absolute = File.expand_path(file)
60
65
 
61
66
  result[absolute] ||= [0] * File.foreach(absolute).count
@@ -70,14 +75,22 @@ module SimpleCov
70
75
  # from cache using SimpleCov::ResultMerger if use_merging is activated (default)
71
76
  #
72
77
  def result
73
- @result ||= SimpleCov::Result.new(add_not_loaded_files(Coverage.result)) if running
78
+ # Ensure the variable is defined to avoid ruby warnings
79
+ @result = nil unless defined?(@result)
80
+
81
+ # Collect our coverage result
82
+ if running && !result?
83
+ @result = SimpleCov::Result.new add_not_loaded_files(Coverage.result)
84
+ end
85
+
74
86
  # If we're using merging of results, store the current result
75
87
  # first, then merge the results and return those
76
88
  if use_merging
77
- SimpleCov::ResultMerger.store_result(@result) if @result
78
- return SimpleCov::ResultMerger.merged_result
89
+ SimpleCov::ResultMerger.store_result(@result) if result?
90
+
91
+ SimpleCov::ResultMerger.merged_result
79
92
  else
80
- return @result if defined? @result
93
+ @result
81
94
  end
82
95
  ensure
83
96
  self.running = false
@@ -112,7 +125,7 @@ module SimpleCov
112
125
  grouped[name] = SimpleCov::FileList.new(files.select { |source_file| filter.matches?(source_file) })
113
126
  grouped_files += grouped[name]
114
127
  end
115
- if groups.length > 0 && (other_files = files.reject { |source_file| grouped_files.include?(source_file) }).length > 0
128
+ if !groups.empty? && !(other_files = files.reject { |source_file| grouped_files.include?(source_file) }).empty?
116
129
  grouped["Ungrouped"] = SimpleCov::FileList.new(other_files)
117
130
  end
118
131
  grouped
data/simplecov.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
 
15
15
  gem.required_ruby_version = ">= 1.8.7"
16
16
 
17
- gem.add_dependency "json", "~> 1.8"
17
+ gem.add_dependency "json", ">= 1.8", "< 3"
18
18
  gem.add_dependency "simplecov-html", "~> 0.10.0"
19
19
  gem.add_dependency "docile", "~> 1.1.0"
20
20
 
@@ -6,24 +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
- describe "Ruby 1.8 fallback" do
10
- it "return false when calling SimpleCov.start" do
11
- expect(SimpleCov.start).to be false
12
- end
9
+ if RUBY_VERSION.start_with? "1.8"
10
+ describe "Ruby 1.8 fallback" do
11
+ it "return false when calling SimpleCov.start" do
12
+ expect(SimpleCov.start).to be false
13
+ end
13
14
 
14
- it "return false when calling SimpleCov.start with a block" do
15
- expect(SimpleCov.start { fail "Shouldn't reach this!" }).to be false
16
- end
15
+ it "return false when calling SimpleCov.start with a block" do
16
+ expect(SimpleCov.start { raise "Shouldn't reach this!" }).to be false
17
+ end
17
18
 
18
- it "return false when calling SimpleCov.configure with a block" do
19
- expect(SimpleCov.configure { fail "Shouldn't reach this!" }).to be false
20
- end
19
+ it "return false when calling SimpleCov.configure with a block" do
20
+ expect(SimpleCov.configure { raise "Shouldn't reach this!" }).to be false
21
+ end
21
22
 
22
- it "allow to define a profile" do
23
- expect do
24
- SimpleCov.profiles.define "testprofile" do
25
- add_filter "/config/"
26
- end
27
- end.not_to raise_error
23
+ it "allow to define a profile" do
24
+ expect do
25
+ SimpleCov.profiles.define "testprofile" do
26
+ add_filter "/config/"
27
+ end
28
+ end.not_to raise_error
29
+ end
28
30
  end
29
- end if RUBY_VERSION.start_with? "1.8"
31
+ end
@@ -1,46 +1,48 @@
1
1
  require "helper"
2
2
 
3
- describe SimpleCov::CommandGuesser do
4
- subject { SimpleCov::CommandGuesser }
5
- it 'correctly guesses "Unit Tests" for unit tests' do
6
- subject.original_run_command = "/some/path/test/units/foo_bar_test.rb"
7
- expect(subject.guess).to eq("Unit Tests")
8
- subject.original_run_command = "test/units/foo.rb"
9
- expect(subject.guess).to eq("Unit Tests")
10
- subject.original_run_command = "test/foo.rb"
11
- expect(subject.guess).to eq("Unit Tests")
12
- subject.original_run_command = "test/{models,helpers,unit}/**/*_test.rb"
13
- expect(subject.guess).to eq("Unit Tests")
14
- end
3
+ if SimpleCov.usable?
4
+ describe SimpleCov::CommandGuesser do
5
+ subject { SimpleCov::CommandGuesser }
6
+ it 'correctly guesses "Unit Tests" for unit tests' do
7
+ subject.original_run_command = "/some/path/test/units/foo_bar_test.rb"
8
+ expect(subject.guess).to eq("Unit Tests")
9
+ subject.original_run_command = "test/units/foo.rb"
10
+ expect(subject.guess).to eq("Unit Tests")
11
+ subject.original_run_command = "test/foo.rb"
12
+ expect(subject.guess).to eq("Unit Tests")
13
+ subject.original_run_command = "test/{models,helpers,unit}/**/*_test.rb"
14
+ expect(subject.guess).to eq("Unit Tests")
15
+ end
15
16
 
16
- it 'correctly guesses "Functional Tests" for functional tests' do
17
- subject.original_run_command = "/some/path/test/functional/foo_bar_controller_test.rb"
18
- expect(subject.guess).to eq("Functional Tests")
19
- subject.original_run_command = "test/{controllers,mailers,functional}/**/*_test.rb"
20
- expect(subject.guess).to eq("Functional Tests")
21
- end
17
+ it 'correctly guesses "Functional Tests" for functional tests' do
18
+ subject.original_run_command = "/some/path/test/functional/foo_bar_controller_test.rb"
19
+ expect(subject.guess).to eq("Functional Tests")
20
+ subject.original_run_command = "test/{controllers,mailers,functional}/**/*_test.rb"
21
+ expect(subject.guess).to eq("Functional Tests")
22
+ end
22
23
 
23
- it 'correctly guesses "Integration Tests" for integration tests' do
24
- subject.original_run_command = "/some/path/test/integration/foo_bar_controller_test.rb"
25
- expect(subject.guess).to eq("Integration Tests")
26
- subject.original_run_command = "test/integration/**/*_test.rb"
27
- expect(subject.guess).to eq("Integration Tests")
28
- end
24
+ it 'correctly guesses "Integration Tests" for integration tests' do
25
+ subject.original_run_command = "/some/path/test/integration/foo_bar_controller_test.rb"
26
+ expect(subject.guess).to eq("Integration Tests")
27
+ subject.original_run_command = "test/integration/**/*_test.rb"
28
+ expect(subject.guess).to eq("Integration Tests")
29
+ end
29
30
 
30
- it 'correctly guesses "Cucumber Features" for cucumber features' do
31
- subject.original_run_command = "features"
32
- expect(subject.guess).to eq("Cucumber Features")
33
- subject.original_run_command = "cucumber"
34
- expect(subject.guess).to eq("Cucumber Features")
35
- end
31
+ it 'correctly guesses "Cucumber Features" for cucumber features' do
32
+ subject.original_run_command = "features"
33
+ expect(subject.guess).to eq("Cucumber Features")
34
+ subject.original_run_command = "cucumber"
35
+ expect(subject.guess).to eq("Cucumber Features")
36
+ end
36
37
 
37
- it 'correctly guesses "RSpec" for RSpec' do
38
- subject.original_run_command = "/some/path/spec/foo.rb"
39
- expect(subject.guess).to eq("RSpec")
40
- end
38
+ it 'correctly guesses "RSpec" for RSpec' do
39
+ subject.original_run_command = "/some/path/spec/foo.rb"
40
+ expect(subject.guess).to eq("RSpec")
41
+ end
41
42
 
42
- it "defaults to RSpec because RSpec constant is defined" do
43
- subject.original_run_command = "some_arbitrary_command with arguments"
44
- expect(subject.guess).to eq("RSpec")
43
+ it "defaults to RSpec because RSpec constant is defined" do
44
+ subject.original_run_command = "some_arbitrary_command with arguments"
45
+ expect(subject.guess).to eq("RSpec")
46
+ end
45
47
  end
46
- end if SimpleCov.usable?
48
+ end
@@ -14,7 +14,7 @@ class SomeClass
14
14
  if item == label
15
15
  return true
16
16
  else
17
- fail "Item does not match label"
17
+ raise "Item does not match label"
18
18
  end
19
19
  rescue
20
20
  false
@@ -2,6 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe "forking" do
4
4
  it do
5
- Process.waitpid(Kernel.fork {})
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"
6
7
  end
7
8
  end
@@ -1,48 +1,50 @@
1
1
  require "helper"
2
2
 
3
- describe SimpleCov::Result do
4
- subject do
5
- original_result = {
6
- 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],
9
- }
10
- SimpleCov::Result.new(original_result).files
11
- end
12
-
13
- it "has 11 covered lines" do
14
- expect(subject.covered_lines).to eq(11)
15
- end
16
-
17
- it "has 3 missed lines" do
18
- expect(subject.missed_lines).to eq(3)
19
- end
20
-
21
- it "has 19 never lines" do
22
- expect(subject.never_lines).to eq(19)
23
- end
24
-
25
- it "has 14 lines of code" do
26
- expect(subject.lines_of_code).to eq(14)
27
- end
28
-
29
- it "has 3 skipped lines" do
30
- expect(subject.skipped_lines).to eq(3)
31
- end
32
-
33
- it "has the correct covered percent" do
34
- expect(subject.covered_percent).to eq(78.57142857142857)
35
- end
36
-
37
- it "has the correct covered percentages" do
38
- expect(subject.covered_percentages).to eq([50.0, 80.0, 100.0])
39
- end
40
-
41
- it "has the correct least covered file" do
42
- expect(subject.least_covered_file).to match(/sample_controller.rb/)
43
- end
44
-
45
- it "has the correct covered strength" do
46
- expect(subject.covered_strength).to eq(0.9285714285714286)
47
- end
48
- end if SimpleCov.usable?
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 19 never lines" do
23
+ expect(subject.never_lines).to eq(19)
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 3 skipped lines" do
31
+ expect(subject.skipped_lines).to eq(3)
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
data/spec/filters_spec.rb CHANGED
@@ -1,96 +1,98 @@
1
1
  require "helper"
2
2
 
3
- describe SimpleCov::SourceFile do
4
- subject do
5
- SimpleCov::SourceFile.new(source_fixture("sample.rb"), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
6
- end
7
-
8
- it "doesn't match a new SimpleCov::StringFilter 'foobar'" do
9
- expect(SimpleCov::StringFilter.new("foobar")).not_to be_matches subject
10
- end
11
-
12
- it "doesn't match a new SimpleCov::StringFilter 'some/path'" do
13
- expect(SimpleCov::StringFilter.new("some/path")).not_to be_matches subject
14
- end
15
-
16
- it "matches a new SimpleCov::StringFilter 'spec/fixtures'" do
17
- expect(SimpleCov::StringFilter.new("spec/fixtures")).to be_matches subject
18
- end
19
-
20
- it "matches a new SimpleCov::StringFilter 'spec/fixtures/sample.rb'" do
21
- expect(SimpleCov::StringFilter.new("spec/fixtures/sample.rb")).to be_matches subject
22
- end
23
-
24
- it "matches a new SimpleCov::StringFilter 'sample.rb'" do
25
- expect(SimpleCov::StringFilter.new("sample.rb")).to be_matches subject
26
- end
27
-
28
- it "doesn't match a new SimpleCov::BlockFilter that is not applicable" do
29
- expect(SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "foo.rb" })).not_to be_matches subject
30
- end
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
31
8
 
32
- it "matches a new SimpleCov::BlockFilter that is applicable" do
33
- expect(SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "sample.rb" })).to be_matches subject
34
- end
9
+ it "doesn't match a new SimpleCov::StringFilter 'foobar'" do
10
+ expect(SimpleCov::StringFilter.new("foobar")).not_to be_matches subject
11
+ end
35
12
 
36
- it "matches a new SimpleCov::ArrayFilter when 'sample.rb' is passed as array" do
37
- expect(SimpleCov::ArrayFilter.new(["sample.rb"])).to be_matches subject
38
- end
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
39
16
 
40
- it "doesn't match a new SimpleCov::ArrayFilter when a file path different than 'sample.rb' is passed as array" do
41
- expect(SimpleCov::ArrayFilter.new(["other_file.rb"])).not_to be_matches subject
42
- end
17
+ it "matches a new SimpleCov::StringFilter 'spec/fixtures'" do
18
+ expect(SimpleCov::StringFilter.new("spec/fixtures")).to be_matches subject
19
+ end
43
20
 
44
- it "matches a new SimpleCov::ArrayFilter when two file paths including 'sample.rb' are passed as array" do
45
- expect(SimpleCov::ArrayFilter.new(["sample.rb", "other_file.rb"])).to be_matches subject
46
- end
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
47
24
 
48
- context "with no filters set up and a basic source file in an array" do
49
- before do
50
- @prev_filters = SimpleCov.filters
51
- SimpleCov.filters = []
25
+ it "matches a new SimpleCov::StringFilter 'sample.rb'" do
26
+ expect(SimpleCov::StringFilter.new("sample.rb")).to be_matches subject
52
27
  end
53
28
 
54
- subject do
55
- [SimpleCov::SourceFile.new(source_fixture("sample.rb"), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])]
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
56
31
  end
57
32
 
58
- after do
59
- SimpleCov.filters = @prev_filters
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
60
35
  end
61
36
 
62
- it 'returns 0 items after executing SimpleCov.filtered on files when using a "sample" string filter' do
63
- SimpleCov.add_filter "sample"
64
- expect(SimpleCov.filtered(subject).count).to be_zero
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
65
39
  end
66
40
 
67
- it 'returns 0 items after executing SimpleCov.filtered on files when using a "spec/fixtures" string filter' do
68
- SimpleCov.add_filter "spec/fixtures"
69
- expect(SimpleCov.filtered(subject).count).to be_zero
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
70
43
  end
71
44
 
72
- it 'returns 1 item after executing SimpleCov.filtered on files when using a "fooo" string filter' do
73
- SimpleCov.add_filter "fooo"
74
- expect(SimpleCov.filtered(subject).count).to eq(1)
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
75
47
  end
76
48
 
77
- it "returns 0 items after executing SimpleCov.filtered on files when using a block filter that returns true" do
78
- SimpleCov.add_filter do
79
- true
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 = []
80
53
  end
81
- expect(SimpleCov.filtered(subject).count).to be_zero
82
- end
83
54
 
84
- it "returns 1 item after executing SimpleCov.filtered on files when using an always-false block filter" do
85
- SimpleCov.add_filter do
86
- false
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
87
66
  end
88
- expect(SimpleCov.filtered(subject).count).to eq(1)
89
- end
90
67
 
91
- it "returns a FileList after filtering" do
92
- SimpleCov.add_filter "fooo"
93
- expect(SimpleCov.filtered(subject)).to be_a SimpleCov::FileList
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
94
96
  end
95
97
  end
96
- end if SimpleCov.usable?
98
+ end
@@ -12,4 +12,4 @@ code = %{
12
12
  File.open(file, "w") { |f| f.print code }
13
13
  load file
14
14
  File.unlink file
15
- fail unless kill_the_buddha(3) == 27
15
+ raise unless kill_the_buddha(3) == 27