simplecov 0.12.0 → 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,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
@@ -1,114 +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
- source_fixture("parallel_tests.rb") => [nil, 0, nil, 0],
13
- }.extend(SimpleCov::HashMergeHelper)
14
-
15
- @resultset2 = {
16
- source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
17
- source_fixture("app/models/user.rb") => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
18
- source_fixture("app/controllers/sample_controller.rb") => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
19
- source_fixture("resultset2.rb") => [nil, 1, 1, nil],
20
- source_fixture("parallel_tests.rb") => [nil, nil, 0, 0],
21
- }
22
- end
23
-
24
- context "a merge" do
25
- subject do
26
- @resultset1.merge_resultset(@resultset2)
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
+ }
27
25
  end
28
26
 
29
- it "has proper results for sample.rb" do
30
- expect(subject[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
31
- end
27
+ context "a merge" do
28
+ subject do
29
+ @resultset1.merge_resultset(@resultset2)
30
+ end
32
31
 
33
- it "has proper results for user.rb" do
34
- expect(subject[source_fixture("app/models/user.rb")]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
35
- 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
36
35
 
37
- it "has proper results for sample_controller.rb" do
38
- expect(subject[source_fixture("app/controllers/sample_controller.rb")]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil])
39
- 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
40
39
 
41
- it "has proper results for resultset1.rb" do
42
- expect(subject[source_fixture("resultset1.rb")]).to eq([1, 1, 1, 1])
43
- 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
44
43
 
45
- it "has proper results for resultset2.rb" do
46
- expect(subject[source_fixture("resultset2.rb")]).to eq([nil, 1, 1, nil])
47
- 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
48
47
 
49
- it "has proper results for parallel_tests.rb" do
50
- expect(subject[source_fixture("parallel_tests.rb")]).to eq([nil, nil, nil, 0])
51
- end
52
- 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
53
51
 
54
- # See Github issue #6
55
- it "returns an empty hash when the resultset cache file is empty" do
56
- File.open(SimpleCov::ResultMerger.resultset_path, "w+") { |f| f.puts "" }
57
- expect(SimpleCov::ResultMerger.resultset).to be_empty
58
- end
52
+ it "has proper results for parallel_tests.rb" do
53
+ expect(subject[source_fixture("parallel_tests.rb")]).to eq([nil, nil, nil, 0])
54
+ end
59
55
 
60
- # See Github issue #6
61
- it "returns an empty hash when the resultset cache file is not present" do
62
- system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
63
- expect(SimpleCov::ResultMerger.resultset).to be_empty
64
- end
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])
58
+ end
65
59
 
66
- context "and results generated from those" do
67
- before do
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])
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
68
73
  system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
69
- @result1 = SimpleCov::Result.new(@resultset1)
70
- @result1.command_name = "result1"
71
- @result2 = SimpleCov::Result.new(@resultset2)
72
- @result2.command_name = "result2"
74
+ expect(SimpleCov::ResultMerger.resultset).to be_empty
73
75
  end
74
76
 
75
- context "with stored results" do
77
+ context "and results generated from those" do
76
78
  before do
77
- SimpleCov::ResultMerger.store_result(@result1)
78
- SimpleCov::ResultMerger.store_result(@result2)
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"
79
84
  end
80
85
 
81
- it "has stored data in resultset_path JSON file" do
82
- expect(File.readlines(SimpleCov::ResultMerger.resultset_path).length).to be > 50
83
- end
86
+ context "with stored results" do
87
+ before do
88
+ SimpleCov::ResultMerger.store_result(@result1)
89
+ SimpleCov::ResultMerger.store_result(@result2)
90
+ end
84
91
 
85
- it "returns a hash containing keys ['result1' and 'result2'] for resultset" do
86
- expect(SimpleCov::ResultMerger.resultset.keys.sort).to eq %w(result1 result2)
87
- end
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
88
95
 
89
- it "returns proper values for merged_result" do
90
- 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])
91
- end
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
92
99
 
93
- context "with second result way above the merge_timeout" do
94
- before do
95
- @result2.created_at = Time.now - 172_800 # two days ago
96
- SimpleCov::ResultMerger.store_result(@result2)
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])
97
102
  end
98
103
 
99
- it "has only one result in SimpleCov::ResultMerger.results" do
100
- expect(SimpleCov::ResultMerger.results.length).to eq(1)
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
101
113
  end
102
- end
103
114
 
104
- context "with merging disabled" do
105
- before { SimpleCov.use_merging false }
115
+ context "with merging disabled" do
116
+ before { SimpleCov.use_merging false }
106
117
 
107
- it "returns nil for SimpleCov.result" do
108
- expect(SimpleCov.result).to be_nil
118
+ it "returns nil for SimpleCov.result" do
119
+ expect(SimpleCov.result).to be_nil
120
+ end
109
121
  end
110
122
  end
111
123
  end
112
124
  end
113
125
  end
114
- end if SimpleCov.usable?
126
+ end
@@ -1,207 +1,209 @@
1
1
  require "helper"
2
2
 
3
- describe "result" do
4
- context "with a (mocked) Coverage.result" do
5
- before do
6
- @prev_filters = SimpleCov.filters
7
- SimpleCov.filters = []
8
- @prev_groups = SimpleCov.groups
9
- SimpleCov.groups = {}
10
- @prev_formatter = SimpleCov.formatter
11
- SimpleCov.formatter = nil
12
- end
13
-
14
- after do
15
- SimpleCov.filters = @prev_filters
16
- SimpleCov.groups = @prev_groups
17
- SimpleCov.formatter = @prev_formatter
18
- end
19
-
20
- let(:original_result) do
21
- {
22
- source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
23
- source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
24
- source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
25
- }
26
- end
27
-
28
- context "a simple cov result initialized from that" do
29
- subject { SimpleCov::Result.new(original_result) }
30
-
31
- it "has 3 filenames" do
32
- expect(subject.filenames.count).to eq(3)
33
- end
34
-
35
- it "has 3 source files" do
36
- expect(subject.source_files.count).to eq(3)
37
- subject.source_files.each do |source_file|
38
- expect(source_file).to be_a SimpleCov::SourceFile
39
- end
3
+ if SimpleCov.usable?
4
+ describe "result" do
5
+ context "with a (mocked) Coverage.result" do
6
+ before do
7
+ @prev_filters = SimpleCov.filters
8
+ SimpleCov.filters = []
9
+ @prev_groups = SimpleCov.groups
10
+ SimpleCov.groups = {}
11
+ @prev_formatter = SimpleCov.formatter
12
+ SimpleCov.formatter = nil
40
13
  end
41
14
 
42
- it "returns an instance of SimpleCov::FileList for source_files and files" do
43
- expect(subject.files).to be_a SimpleCov::FileList
44
- expect(subject.source_files).to be_a SimpleCov::FileList
15
+ after do
16
+ SimpleCov.filters = @prev_filters
17
+ SimpleCov.groups = @prev_groups
18
+ SimpleCov.formatter = @prev_formatter
45
19
  end
46
20
 
47
- it "has files equal to source_files" do
48
- expect(subject.files).to eq(subject.source_files)
21
+ let(:original_result) do
22
+ {
23
+ source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
24
+ source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
25
+ source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
26
+ }
49
27
  end
50
28
 
51
- it "has accurate covered percent" do
52
- # in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil)
53
- expect(subject.covered_percent).to eq(86.66666666666667)
54
- end
29
+ context "a simple cov result initialized from that" do
30
+ subject { SimpleCov::Result.new(original_result) }
55
31
 
56
- it "has accurate covered percentages" do
57
- expect(subject.covered_percentages).to eq([80.0, 80.0, 100.0])
58
- end
32
+ it "has 3 filenames" do
33
+ expect(subject.filenames.count).to eq(3)
34
+ end
59
35
 
60
- it "has accurate least covered file" do
61
- expect(subject.least_covered_file).to match(/sample_controller.rb/)
62
- end
36
+ it "has 3 source files" do
37
+ expect(subject.source_files.count).to eq(3)
38
+ subject.source_files.each do |source_file|
39
+ expect(source_file).to be_a SimpleCov::SourceFile
40
+ end
41
+ end
63
42
 
64
- [:covered_percent, :covered_percentages, :least_covered_file, :covered_strength, :covered_lines, :missed_lines, :total_lines].each do |msg|
65
- it "responds to #{msg}" do
66
- expect(subject).to respond_to(msg)
43
+ it "returns an instance of SimpleCov::FileList for source_files and files" do
44
+ expect(subject.files).to be_a SimpleCov::FileList
45
+ expect(subject.source_files).to be_a SimpleCov::FileList
67
46
  end
68
- end
69
47
 
70
- context "dumped with to_hash" do
71
- it "is a hash" do
72
- expect(subject.to_hash).to be_a Hash
48
+ it "has files equal to source_files" do
49
+ expect(subject.files).to eq(subject.source_files)
73
50
  end
74
51
 
75
- context "loaded back with from_hash" do
76
- let(:dumped_result) do
77
- SimpleCov::Result.from_hash(subject.to_hash)
78
- end
52
+ it "has accurate covered percent" do
53
+ # in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil)
54
+ expect(subject.covered_percent).to eq(86.66666666666667)
55
+ end
79
56
 
80
- it "has 3 source files" do
81
- expect(dumped_result.source_files.count).to eq(subject.source_files.count)
82
- end
57
+ it "has accurate covered percentages" do
58
+ expect(subject.covered_percentages).to eq([80.0, 80.0, 100.0])
59
+ end
83
60
 
84
- it "has the same covered_percent" do
85
- expect(dumped_result.covered_percent).to eq(subject.covered_percent)
86
- end
61
+ it "has accurate least covered file" do
62
+ expect(subject.least_covered_file).to match(/sample_controller.rb/)
63
+ end
87
64
 
88
- it "has the same covered_percentages" do
89
- expect(dumped_result.covered_percentages).to eq(subject.covered_percentages)
65
+ [:covered_percent, :covered_percentages, :least_covered_file, :covered_strength, :covered_lines, :missed_lines, :total_lines].each do |msg|
66
+ it "responds to #{msg}" do
67
+ expect(subject).to respond_to(msg)
90
68
  end
69
+ end
91
70
 
92
- it "has the same timestamp" do
93
- expect(dumped_result.created_at.to_i).to eq(subject.created_at.to_i)
71
+ context "dumped with to_hash" do
72
+ it "is a hash" do
73
+ expect(subject.to_hash).to be_a Hash
94
74
  end
95
75
 
96
- it "has the same command_name" do
97
- expect(dumped_result.command_name).to eq(subject.command_name)
98
- end
76
+ context "loaded back with from_hash" do
77
+ let(:dumped_result) do
78
+ SimpleCov::Result.from_hash(subject.to_hash)
79
+ end
99
80
 
100
- it "has the same original_result" do
101
- expect(dumped_result.original_result).to eq(subject.original_result)
102
- end
103
- end
104
- end
105
- end
81
+ it "has 3 source files" do
82
+ expect(dumped_result.source_files.count).to eq(subject.source_files.count)
83
+ end
106
84
 
107
- context "with some filters set up" do
108
- before do
109
- SimpleCov.add_filter "sample.rb"
110
- end
85
+ it "has the same covered_percent" do
86
+ expect(dumped_result.covered_percent).to eq(subject.covered_percent)
87
+ end
111
88
 
112
- it "has 2 files in a new simple cov result" do
113
- expect(SimpleCov::Result.new(original_result).source_files.length).to eq(2)
114
- end
89
+ it "has the same covered_percentages" do
90
+ expect(dumped_result.covered_percentages).to eq(subject.covered_percentages)
91
+ end
115
92
 
116
- it "has 80 covered percent" do
117
- expect(SimpleCov::Result.new(original_result).covered_percent).to eq(80)
118
- end
93
+ it "has the same timestamp" do
94
+ expect(dumped_result.created_at.to_i).to eq(subject.created_at.to_i)
95
+ end
119
96
 
120
- it "has [80.0, 80.0] covered percentages" do
121
- expect(SimpleCov::Result.new(original_result).covered_percentages).to eq([80.0, 80.0])
122
- end
123
- end
97
+ it "has the same command_name" do
98
+ expect(dumped_result.command_name).to eq(subject.command_name)
99
+ end
124
100
 
125
- context "with groups set up for all files" do
126
- before do
127
- SimpleCov.add_group "Models", "app/models"
128
- SimpleCov.add_group "Controllers", ["app/controllers"]
129
- SimpleCov.add_group "Other" do |src_file|
130
- File.basename(src_file.filename) == "sample.rb"
101
+ it "has the same original_result" do
102
+ expect(dumped_result.original_result).to eq(subject.original_result)
103
+ end
104
+ end
131
105
  end
132
106
  end
133
107
 
134
- subject do
135
- SimpleCov::Result.new(original_result)
136
- end
108
+ context "with some filters set up" do
109
+ before do
110
+ SimpleCov.add_filter "sample.rb"
111
+ end
137
112
 
138
- it "has 3 groups" do
139
- expect(subject.groups.length).to eq(3)
140
- end
113
+ it "has 2 files in a new simple cov result" do
114
+ expect(SimpleCov::Result.new(original_result).source_files.length).to eq(2)
115
+ end
141
116
 
142
- it "has user.rb in 'Models' group" do
143
- expect(File.basename(subject.groups["Models"].first.filename)).to eq("user.rb")
144
- end
117
+ it "has 80 covered percent" do
118
+ expect(SimpleCov::Result.new(original_result).covered_percent).to eq(80)
119
+ end
145
120
 
146
- it "has sample_controller.rb in 'Controllers' group" do
147
- expect(File.basename(subject.groups["Controllers"].first.filename)).to eq("sample_controller.rb")
121
+ it "has [80.0, 80.0] covered percentages" do
122
+ expect(SimpleCov::Result.new(original_result).covered_percentages).to eq([80.0, 80.0])
123
+ end
148
124
  end
149
125
 
150
- context "and simple formatter being used" do
126
+ context "with groups set up for all files" do
151
127
  before do
152
- SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
128
+ SimpleCov.add_group "Models", "app/models"
129
+ SimpleCov.add_group "Controllers", ["app/controllers"]
130
+ SimpleCov.add_group "Other" do |src_file|
131
+ File.basename(src_file.filename) == "sample.rb"
132
+ end
153
133
  end
154
134
 
155
- it "returns a formatted string with result.format!" do
156
- expect(subject.format!).to be_a String
135
+ subject do
136
+ SimpleCov::Result.new(original_result)
157
137
  end
158
- end
159
138
 
160
- context "and multi formatter being used" do
161
- before do
162
- SimpleCov.formatters = [
163
- SimpleCov::Formatter::SimpleFormatter,
164
- SimpleCov::Formatter::SimpleFormatter,
165
- ]
139
+ it "has 3 groups" do
140
+ expect(subject.groups.length).to eq(3)
166
141
  end
167
142
 
168
- it "returns an array containing formatted string with result.format!" do
169
- formatted = subject.format!
170
- expect(formatted.count).to eq(2)
171
- expect(formatted.first).to be_a String
143
+ it "has user.rb in 'Models' group" do
144
+ expect(File.basename(subject.groups["Models"].first.filename)).to eq("user.rb")
172
145
  end
173
- end
174
- end
175
146
 
176
- context "with groups set up that do not match all files" do
177
- before do
178
- SimpleCov.configure do
179
- add_group "Models", "app/models"
180
- add_group "Controllers", "app/controllers"
147
+ it "has sample_controller.rb in 'Controllers' group" do
148
+ expect(File.basename(subject.groups["Controllers"].first.filename)).to eq("sample_controller.rb")
181
149
  end
182
- end
183
150
 
184
- subject { SimpleCov::Result.new(original_result) }
151
+ context "and simple formatter being used" do
152
+ before do
153
+ SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
154
+ end
185
155
 
186
- it "has 3 groups" do
187
- expect(subject.groups.length).to eq(3)
188
- end
156
+ it "returns a formatted string with result.format!" do
157
+ expect(subject.format!).to be_a String
158
+ end
159
+ end
189
160
 
190
- it "has 1 item per group" do
191
- subject.groups.each_value do |files|
192
- expect(files.length).to eq(1)
161
+ context "and multi formatter being used" do
162
+ before do
163
+ SimpleCov.formatters = [
164
+ SimpleCov::Formatter::SimpleFormatter,
165
+ SimpleCov::Formatter::SimpleFormatter,
166
+ ]
167
+ end
168
+
169
+ it "returns an array containing formatted string with result.format!" do
170
+ formatted = subject.format!
171
+ expect(formatted.count).to eq(2)
172
+ expect(formatted.first).to be_a String
173
+ end
193
174
  end
194
175
  end
195
176
 
196
- it 'has sample.rb in "Ungrouped" group' do
197
- expect(File.basename(subject.groups["Ungrouped"].first.filename)).to eq("sample.rb")
198
- end
177
+ context "with groups set up that do not match all files" do
178
+ before do
179
+ SimpleCov.configure do
180
+ add_group "Models", "app/models"
181
+ add_group "Controllers", "app/controllers"
182
+ end
183
+ end
199
184
 
200
- it "returns all groups as instances of SimpleCov::FileList" do
201
- subject.groups.each_value do |files|
202
- expect(files).to be_a SimpleCov::FileList
185
+ subject { SimpleCov::Result.new(original_result) }
186
+
187
+ it "has 3 groups" do
188
+ expect(subject.groups.length).to eq(3)
189
+ end
190
+
191
+ it "has 1 item per group" do
192
+ subject.groups.each_value do |files|
193
+ expect(files.length).to eq(1)
194
+ end
195
+ end
196
+
197
+ it 'has sample.rb in "Ungrouped" group' do
198
+ expect(File.basename(subject.groups["Ungrouped"].first.filename)).to eq("sample.rb")
199
+ end
200
+
201
+ it "returns all groups as instances of SimpleCov::FileList" do
202
+ subject.groups.each_value do |files|
203
+ expect(files).to be_a SimpleCov::FileList
204
+ end
203
205
  end
204
206
  end
205
207
  end
206
208
  end
207
- end if SimpleCov.usable?
209
+ end