|
69 | 69 | end
|
70 | 70 | end
|
71 | 71 |
|
72 |
| - # TODO[@tycooon]: add method cov |
73 | 72 | describe "branch coverage" do
|
74 | 73 | it "has total branches count 0" do
|
75 | 74 | expect(subject.total_branches.size).to eq(0)
|
|
91 | 90 | expect(subject.branches_report).to eq({})
|
92 | 91 | end
|
93 | 92 | end
|
| 93 | + |
| 94 | + describe "method coverage" do |
| 95 | + it "has total methods count 0" do |
| 96 | + expect(subject.total_methods.size).to eq(0) |
| 97 | + end |
| 98 | + |
| 99 | + it "has covered methods count 0" do |
| 100 | + expect(subject.covered_methods.size).to eq(0) |
| 101 | + end |
| 102 | + |
| 103 | + it "has missed methods count 0" do |
| 104 | + expect(subject.missed_methods.size).to eq(0) |
| 105 | + end |
| 106 | + |
| 107 | + it "is considered 100% methods covered" do |
| 108 | + expect(subject.methods_coverage_percent).to eq(100.0) |
| 109 | + end |
| 110 | + end |
94 | 111 | end
|
95 | 112 |
|
96 | 113 | context "file with branches" do
|
97 |
| - COVERAGE_FOR_BRANCHES_RB = { |
98 |
| - lines: [1, 1, 1, nil, 1, nil, 1, 0, nil, 1, nil, nil, nil], |
99 |
| - branches: { |
100 |
| - [:if, 0, 3, 4, 3, 21] => |
101 |
| - {[:then, 1, 3, 4, 3, 10] => 0, [:else, 2, 3, 4, 3, 21] => 1}, |
102 |
| - [:if, 3, 5, 4, 5, 26] => |
103 |
| - {[:then, 4, 5, 16, 5, 20] => 1, [:else, 5, 5, 23, 5, 26] => 0}, |
104 |
| - [:if, 6, 7, 4, 11, 7] => |
105 |
| - {[:then, 7, 8, 6, 8, 10] => 0, [:else, 8, 10, 6, 10, 9] => 1} |
| 114 | + let(:coverage_for_branches_rb) do |
| 115 | + { |
| 116 | + lines: [1, 1, 1, nil, 1, nil, 1, 0, nil, 1, nil, nil, nil], |
| 117 | + branches: { |
| 118 | + [:if, 0, 3, 4, 3, 21] => |
| 119 | + {[:then, 1, 3, 4, 3, 10] => 0, [:else, 2, 3, 4, 3, 21] => 1}, |
| 120 | + [:if, 3, 5, 4, 5, 26] => |
| 121 | + {[:then, 4, 5, 16, 5, 20] => 1, [:else, 5, 5, 23, 5, 26] => 0}, |
| 122 | + [:if, 6, 7, 4, 11, 7] => |
| 123 | + {[:then, 7, 8, 6, 8, 10] => 0, [:else, 8, 10, 6, 10, 9] => 1} |
| 124 | + } |
106 | 125 | }
|
107 |
| - }.freeze |
| 126 | + end |
108 | 127 |
|
109 | 128 | subject do
|
110 |
| - SimpleCov::SourceFile.new(source_fixture("branches.rb"), COVERAGE_FOR_BRANCHES_RB) |
| 129 | + SimpleCov::SourceFile.new(source_fixture("branches.rb"), coverage_for_branches_rb) |
111 | 130 | end
|
112 | 131 |
|
113 | 132 | describe "branch coverage" do
|
|
164 | 183 | end
|
165 | 184 | end
|
166 | 185 |
|
| 186 | + context "file with methods" do |
| 187 | + let(:coverage_for_methods_rb) do |
| 188 | + { |
| 189 | + lines: [1, 1, 1, 1, nil, nil, 1, nil, 1, 1, nil, nil, 1, 0, nil, nil, nil, 1], |
| 190 | + branches: {}, |
| 191 | + methods: { |
| 192 | + ["A", :method3, 13, 2, 15, 5] => 0, |
| 193 | + ["A", :method2, 9, 2, 11, 5] => 1, |
| 194 | + ["A", :method1, 2, 2, 5, 5] => 1 |
| 195 | + } |
| 196 | + } |
| 197 | + end |
| 198 | + |
| 199 | + subject do |
| 200 | + SimpleCov::SourceFile.new(source_fixture("methods.rb"), coverage_for_methods_rb) |
| 201 | + end |
| 202 | + |
| 203 | + describe "method coverage" do |
| 204 | + it "has total methods count 0" do |
| 205 | + expect(subject.total_methods.size).to eq(3) |
| 206 | + end |
| 207 | + |
| 208 | + it "has covered methods count 0" do |
| 209 | + expect(subject.covered_methods.size).to eq(2) |
| 210 | + end |
| 211 | + |
| 212 | + it "has missed methods count 0" do |
| 213 | + expect(subject.missed_methods.size).to eq(1) |
| 214 | + end |
| 215 | + |
| 216 | + it "is considered 66.(6)% methods covered" do |
| 217 | + expect(subject.methods_coverage_percent).to eq(66.66666666666667) |
| 218 | + end |
| 219 | + end |
| 220 | + |
| 221 | + describe "line coverage" do |
| 222 | + it "has line coverage" do |
| 223 | + expect(subject.covered_percent).to eq 90.0 |
| 224 | + end |
| 225 | + |
| 226 | + it "has 9 covered lines" do |
| 227 | + expect(subject.covered_lines.size).to eq 9 |
| 228 | + end |
| 229 | + |
| 230 | + it "has 1 missed line" do |
| 231 | + expect(subject.missed_lines.size).to eq 1 |
| 232 | + end |
| 233 | + |
| 234 | + it "has 10 relevant lines" do |
| 235 | + expect(subject.relevant_lines).to eq 10 |
| 236 | + end |
| 237 | + end |
| 238 | + end |
| 239 | + |
167 | 240 | context "simulating potential Ruby 1.9 defect -- see Issue #56" do
|
168 | 241 | subject do
|
169 | 242 | SimpleCov::SourceFile.new(source_fixture("sample.rb"), COVERAGE_FOR_SAMPLE_RB_WITH_MORE_LINES)
|
|
234 | 307 | it "has 100.0 branch coverage" do
|
235 | 308 | expect(subject.branches_coverage_percent).to eq(100.00)
|
236 | 309 | end
|
| 310 | + |
| 311 | + it "has 100.0 method coverage" do |
| 312 | + expect(subject.methods_coverage_percent).to eq(100.00) |
| 313 | + end |
237 | 314 | end
|
238 | 315 |
|
239 | 316 | context "a file where nothing is ever executed mixed with skipping #563" do
|
|
327 | 404 | expect(subject.covered_branches.size).to eq 0
|
328 | 405 | end
|
329 | 406 | end
|
| 407 | + |
| 408 | + describe "method coverage" do |
| 409 | + it "has no methods" do |
| 410 | + expect(subject.total_methods.size).to eq 0 |
| 411 | + end |
| 412 | + |
| 413 | + it "does has neither covered nor missed methods" do |
| 414 | + expect(subject.missed_methods.size).to eq 0 |
| 415 | + expect(subject.covered_methods.size).to eq 0 |
| 416 | + end |
| 417 | + end |
330 | 418 | end
|
331 | 419 |
|
332 | 420 | context "a file with more complex skipping" do
|
|
0 commit comments