simplecov 0.11.2 → 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.
@@ -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
@@ -1,108 +1,126 @@
1
1
  require "helper"
2
2
 
3
- describe "merge helpers" do
4
- describe "with two faked coverage resultsets" do
5
- before do
6
- SimpleCov.use_merging true
7
- @resultset1 = {
8
- source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
9
- source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
10
- source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
11
- source_fixture("resultset1.rb") => [1, 1, 1, 1],
12
- }.extend(SimpleCov::HashMergeHelper)
13
-
14
- @resultset2 = {
15
- source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
16
- source_fixture("app/models/user.rb") => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
17
- source_fixture("app/controllers/sample_controller.rb") => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
18
- source_fixture("resultset2.rb") => [nil, 1, 1, nil],
19
- }
20
- end
21
-
22
- context "a merge" do
23
- subject do
24
- @resultset1.merge_resultset(@resultset2)
25
- end
26
-
27
- it "has proper results for sample.rb" do
28
- expect(subject[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
29
- end
30
-
31
- it "has proper results for user.rb" do
32
- expect(subject[source_fixture("app/models/user.rb")]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
3
+ if SimpleCov.usable?
4
+ describe "merge helpers" do
5
+ describe "with two faked coverage resultsets" do
6
+ before do
7
+ SimpleCov.use_merging true
8
+ @resultset1 = {
9
+ 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
+ source_fixture("resultset1.rb") => [1, 1, 1, 1],
13
+ source_fixture("parallel_tests.rb") => [nil, 0, nil, 0],
14
+ source_fixture("conditionally_loaded_1.rb") => [nil, 0, 1], # loaded only in the first resultset
15
+ }.extend(SimpleCov::HashMergeHelper)
16
+
17
+ @resultset2 = {
18
+ source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
19
+ source_fixture("app/models/user.rb") => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
20
+ source_fixture("app/controllers/sample_controller.rb") => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
21
+ source_fixture("resultset2.rb") => [nil, 1, 1, nil],
22
+ source_fixture("parallel_tests.rb") => [nil, nil, 0, 0],
23
+ source_fixture("conditionally_loaded_2.rb") => [nil, 0, 1], # loaded only in the second resultset
24
+ }
33
25
  end
34
26
 
35
- it "has proper results for sample_controller.rb" do
36
- expect(subject[source_fixture("app/controllers/sample_controller.rb")]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil])
37
- end
27
+ context "a merge" do
28
+ subject do
29
+ @resultset1.merge_resultset(@resultset2)
30
+ end
38
31
 
39
- it "has proper results for resultset1.rb" do
40
- expect(subject[source_fixture("resultset1.rb")]).to eq([1, 1, 1, 1])
41
- end
32
+ it "has proper results for sample.rb" do
33
+ expect(subject[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
34
+ end
42
35
 
43
- it "has proper results for resultset2.rb" do
44
- expect(subject[source_fixture("resultset2.rb")]).to eq([nil, 1, 1, nil])
45
- end
46
- end
36
+ it "has proper results for user.rb" do
37
+ expect(subject[source_fixture("app/models/user.rb")]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
38
+ end
47
39
 
48
- # See Github issue #6
49
- it "returns an empty hash when the resultset cache file is empty" do
50
- File.open(SimpleCov::ResultMerger.resultset_path, "w+") { |f| f.puts "" }
51
- expect(SimpleCov::ResultMerger.resultset).to be_empty
52
- end
40
+ it "has proper results for sample_controller.rb" do
41
+ expect(subject[source_fixture("app/controllers/sample_controller.rb")]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil])
42
+ end
53
43
 
54
- # See Github issue #6
55
- it "returns an empty hash when the resultset cache file is not present" do
56
- system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
57
- expect(SimpleCov::ResultMerger.resultset).to be_empty
58
- end
44
+ it "has proper results for resultset1.rb" do
45
+ expect(subject[source_fixture("resultset1.rb")]).to eq([1, 1, 1, 1])
46
+ end
59
47
 
60
- context "and results generated from those" do
61
- before do
62
- system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
63
- @result1 = SimpleCov::Result.new(@resultset1)
64
- @result1.command_name = "result1"
65
- @result2 = SimpleCov::Result.new(@resultset2)
66
- @result2.command_name = "result2"
67
- end
48
+ it "has proper results for resultset2.rb" do
49
+ expect(subject[source_fixture("resultset2.rb")]).to eq([nil, 1, 1, nil])
50
+ end
68
51
 
69
- context "with stored results" do
70
- before do
71
- SimpleCov::ResultMerger.store_result(@result1)
72
- SimpleCov::ResultMerger.store_result(@result2)
52
+ it "has proper results for parallel_tests.rb" do
53
+ expect(subject[source_fixture("parallel_tests.rb")]).to eq([nil, nil, nil, 0])
73
54
  end
74
55
 
75
- it "has stored data in resultset_path JSON file" do
76
- expect(File.readlines(SimpleCov::ResultMerger.resultset_path).length).to be > 50
56
+ it "has proper results for conditionally_loaded_1.rb" do
57
+ expect(subject[source_fixture("conditionally_loaded_1.rb")]).to eq([nil, 0, 1])
77
58
  end
78
59
 
79
- it "returns a hash containing keys ['result1' and 'result2'] for resultset" do
80
- expect(SimpleCov::ResultMerger.resultset.keys.sort).to eq %w(result1 result2)
60
+ it "has proper results for conditionally_loaded_2.rb" do
61
+ expect(subject[source_fixture("conditionally_loaded_2.rb")]).to eq([nil, 0, 1])
81
62
  end
63
+ end
64
+
65
+ # See Github issue #6
66
+ it "returns an empty hash when the resultset cache file is empty" do
67
+ File.open(SimpleCov::ResultMerger.resultset_path, "w+") { |f| f.puts "" }
68
+ expect(SimpleCov::ResultMerger.resultset).to be_empty
69
+ end
70
+
71
+ # See Github issue #6
72
+ it "returns an empty hash when the resultset cache file is not present" do
73
+ system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
74
+ expect(SimpleCov::ResultMerger.resultset).to be_empty
75
+ end
82
76
 
83
- it "returns proper values for merged_result" do
84
- expect(SimpleCov::ResultMerger.merged_result.source_files.find { |s| s.filename =~ /user/ }.lines.map(&:coverage)).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
77
+ context "and results generated from those" do
78
+ before do
79
+ system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
80
+ @result1 = SimpleCov::Result.new(@resultset1)
81
+ @result1.command_name = "result1"
82
+ @result2 = SimpleCov::Result.new(@resultset2)
83
+ @result2.command_name = "result2"
85
84
  end
86
85
 
87
- context "with second result way above the merge_timeout" do
86
+ context "with stored results" do
88
87
  before do
89
- @result2.created_at = Time.now - 172_800 # two days ago
88
+ SimpleCov::ResultMerger.store_result(@result1)
90
89
  SimpleCov::ResultMerger.store_result(@result2)
91
90
  end
92
91
 
93
- it "has only one result in SimpleCov::ResultMerger.results" do
94
- expect(SimpleCov::ResultMerger.results.length).to eq(1)
92
+ it "has stored data in resultset_path JSON file" do
93
+ expect(File.readlines(SimpleCov::ResultMerger.resultset_path).length).to be > 50
94
+ end
95
+
96
+ it "returns a hash containing keys ['result1' and 'result2'] for resultset" do
97
+ expect(SimpleCov::ResultMerger.resultset.keys.sort).to eq %w(result1 result2)
98
+ end
99
+
100
+ it "returns proper values for merged_result" do
101
+ expect(SimpleCov::ResultMerger.merged_result.source_files.find { |s| s.filename =~ /user/ }.lines.map(&:coverage)).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
102
+ end
103
+
104
+ context "with second result way above the merge_timeout" do
105
+ before do
106
+ @result2.created_at = Time.now - 172_800 # two days ago
107
+ SimpleCov::ResultMerger.store_result(@result2)
108
+ end
109
+
110
+ it "has only one result in SimpleCov::ResultMerger.results" do
111
+ expect(SimpleCov::ResultMerger.results.length).to eq(1)
112
+ end
95
113
  end
96
- end
97
114
 
98
- context "with merging disabled" do
99
- before { SimpleCov.use_merging false }
115
+ context "with merging disabled" do
116
+ before { SimpleCov.use_merging false }
100
117
 
101
- it "returns nil for SimpleCov.result" do
102
- expect(SimpleCov.result).to be_nil
118
+ it "returns nil for SimpleCov.result" do
119
+ expect(SimpleCov.result).to be_nil
120
+ end
103
121
  end
104
122
  end
105
123
  end
106
124
  end
107
125
  end
108
- end if SimpleCov.usable?
126
+ end