|
107 | 107 | end |
108 | 108 | end |
109 | 109 |
|
| 110 | + context "with minimum_coverage below threshold" do |
| 111 | + before do |
| 112 | + allow(SimpleCov).to receive(:minimum_coverage).and_return(line: 95) |
| 113 | + end |
| 114 | + |
| 115 | + it "reports the violation in errors" do |
| 116 | + subject.format(result) |
| 117 | + errors = json_output.fetch("errors") |
| 118 | + expect(errors).to eq( |
| 119 | + "minimum_coverage" => {"lines" => {"expected" => 95, "actual" => 90.0}} |
| 120 | + ) |
| 121 | + end |
| 122 | + end |
| 123 | + |
| 124 | + context "with minimum_coverage above threshold" do |
| 125 | + before do |
| 126 | + allow(SimpleCov).to receive(:minimum_coverage).and_return(line: 80) |
| 127 | + end |
| 128 | + |
| 129 | + it "returns empty errors" do |
| 130 | + subject.format(result) |
| 131 | + expect(json_output.fetch("errors")).to eq({}) |
| 132 | + end |
| 133 | + end |
| 134 | + |
| 135 | + context "with minimum_coverage_by_file for lines" do |
| 136 | + before do |
| 137 | + allow(SimpleCov).to receive(:minimum_coverage_by_file).and_return(line: 95) |
| 138 | + end |
| 139 | + |
| 140 | + it "reports files below the threshold in errors" do |
| 141 | + subject.format(result) |
| 142 | + errors = json_output.fetch("errors") |
| 143 | + expect(errors).to eq( |
| 144 | + "minimum_coverage_by_file" => { |
| 145 | + "lines" => {source_fixture("json/sample.rb") => {"expected" => 95, "actual" => 90.0}} |
| 146 | + } |
| 147 | + ) |
| 148 | + end |
| 149 | + end |
| 150 | + |
| 151 | + context "with minimum_coverage_by_file for branches" do |
| 152 | + let(:result) do |
| 153 | + SimpleCov::Result.new({ |
| 154 | + source_fixture("json/sample.rb") => { |
| 155 | + "lines" => [nil, 1, 1, 1, 1, nil, nil, 1, 1, nil, nil, |
| 156 | + 1, 1, 0, nil, 1, nil, nil, nil, nil, 1, 0, nil, nil, nil], |
| 157 | + "branches" => { |
| 158 | + [:if, 0, 13, 4, 17, 7] => { |
| 159 | + [:then, 1, 14, 6, 14, 10] => 0, |
| 160 | + [:else, 2, 16, 6, 16, 10] => 1 |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + }) |
| 165 | + end |
| 166 | + |
| 167 | + before do |
| 168 | + enable_branch_coverage |
| 169 | + allow(SimpleCov).to receive(:minimum_coverage_by_file).and_return(branch: 75) |
| 170 | + end |
| 171 | + |
| 172 | + it "reports files below the threshold in errors" do |
| 173 | + subject.format(result) |
| 174 | + errors = json_output.fetch("errors") |
| 175 | + expect(errors).to eq( |
| 176 | + "minimum_coverage_by_file" => { |
| 177 | + "branches" => {source_fixture("json/sample.rb") => {"expected" => 75, "actual" => 50.0}} |
| 178 | + } |
| 179 | + ) |
| 180 | + end |
| 181 | + end |
| 182 | + |
| 183 | + context "with minimum_coverage_by_file when all files pass" do |
| 184 | + before do |
| 185 | + allow(SimpleCov).to receive(:minimum_coverage_by_file).and_return(line: 80) |
| 186 | + end |
| 187 | + |
| 188 | + it "returns empty errors" do |
| 189 | + subject.format(result) |
| 190 | + expect(json_output.fetch("errors")).to eq({}) |
| 191 | + end |
| 192 | + end |
| 193 | + |
| 194 | + context "with minimum_coverage_by_group below threshold" do |
| 195 | + let(:line_stats) { SimpleCov::CoverageStatistics.new(covered: 7, missed: 3) } |
| 196 | + |
| 197 | + let(:result) do |
| 198 | + res = SimpleCov::Result.new({ |
| 199 | + source_fixture("json/sample.rb") => {"lines" => [ |
| 200 | + nil, 1, 1, 1, 1, nil, nil, 1, 1, nil, nil, |
| 201 | + 1, 1, 0, nil, 1, nil, nil, nil, nil, 1, 0, nil, nil, nil |
| 202 | + ]} |
| 203 | + }) |
| 204 | + |
| 205 | + allow(res).to receive_messages( |
| 206 | + groups: {"Models" => double("File List", coverage_statistics: {line: line_stats})} |
| 207 | + ) |
| 208 | + res |
| 209 | + end |
| 210 | + |
| 211 | + before do |
| 212 | + allow(SimpleCov).to receive(:minimum_coverage_by_group).and_return("Models" => {line: 80}) |
| 213 | + end |
| 214 | + |
| 215 | + it "reports the group violation in errors" do |
| 216 | + subject.format(result) |
| 217 | + errors = json_output.fetch("errors") |
| 218 | + expect(errors).to eq( |
| 219 | + "minimum_coverage_by_group" => { |
| 220 | + "Models" => {"lines" => {"expected" => 80, "actual" => 70.0}} |
| 221 | + } |
| 222 | + ) |
| 223 | + end |
| 224 | + end |
| 225 | + |
| 226 | + context "with maximum_coverage_drop exceeded" do |
| 227 | + before do |
| 228 | + allow(SimpleCov).to receive(:maximum_coverage_drop).and_return(line: 2) |
| 229 | + allow(SimpleCov::LastRun).to receive(:read).and_return({result: {line: 95.0}}) |
| 230 | + end |
| 231 | + |
| 232 | + it "reports the drop in errors" do |
| 233 | + subject.format(result) |
| 234 | + errors = json_output.fetch("errors") |
| 235 | + expect(errors).to eq( |
| 236 | + "maximum_coverage_drop" => { |
| 237 | + "lines" => {"maximum" => 2, "actual" => 5.0} |
| 238 | + } |
| 239 | + ) |
| 240 | + end |
| 241 | + end |
| 242 | + |
| 243 | + context "with maximum_coverage_drop not exceeded" do |
| 244 | + before do |
| 245 | + allow(SimpleCov).to receive(:maximum_coverage_drop).and_return(line: 2) |
| 246 | + allow(SimpleCov::LastRun).to receive(:read).and_return({result: {line: 91.0}}) |
| 247 | + end |
| 248 | + |
| 249 | + it "returns empty errors" do |
| 250 | + subject.format(result) |
| 251 | + expect(json_output.fetch("errors")).to eq({}) |
| 252 | + end |
| 253 | + end |
| 254 | + |
| 255 | + context "with maximum_coverage_drop and no last run" do |
| 256 | + before do |
| 257 | + allow(SimpleCov).to receive(:maximum_coverage_drop).and_return(line: 2) |
| 258 | + allow(SimpleCov::LastRun).to receive(:read).and_return(nil) |
| 259 | + end |
| 260 | + |
| 261 | + it "returns empty errors" do |
| 262 | + subject.format(result) |
| 263 | + expect(json_output.fetch("errors")).to eq({}) |
| 264 | + end |
| 265 | + end |
| 266 | + |
110 | 267 | context "with groups" do |
111 | 268 | let(:line_stats) { SimpleCov::CoverageStatistics.new(covered: 8, missed: 2) } |
112 | 269 |
|
|
0 commit comments