|
124 | 124 | it_behaves_like "setting coverage expectations", :minimum_coverage_by_file
|
125 | 125 | end
|
126 | 126 |
|
| 127 | + describe "#minimum_coverage_by_group" do |
| 128 | + after do |
| 129 | + config.clear_coverage_criteria |
| 130 | + end |
| 131 | + |
| 132 | + it "does not warn you about your usage" do |
| 133 | + expect(config).not_to receive(:warn) |
| 134 | + config.minimum_coverage_by_group({"Test Group 1" => 100.00}) |
| 135 | + end |
| 136 | + |
| 137 | + it "warns you about your usage" do |
| 138 | + expect(config).to receive(:warn).with("The coverage you set for minimum_coverage_by_group is greater than 100%") |
| 139 | + config.minimum_coverage_by_group({"Test Group 1" => 100.01}) |
| 140 | + end |
| 141 | + |
| 142 | + it "sets the right coverage value when called with a number" do |
| 143 | + config.minimum_coverage_by_group({"Test Group 1" => 80}) |
| 144 | + |
| 145 | + expect(config.minimum_coverage_by_group).to eq({"Test Group 1" => {line: 80}}) |
| 146 | + end |
| 147 | + |
| 148 | + it "sets the right coverage when called with a hash of just line" do |
| 149 | + config.minimum_coverage_by_group({"Test Group 1" => {line: 85.0}}) |
| 150 | + |
| 151 | + expect(config.minimum_coverage_by_group).to eq({"Test Group 1" => {line: 85.0}}) |
| 152 | + end |
| 153 | + |
| 154 | + it "sets the right coverage when called with a hash of just branch" do |
| 155 | + config.enable_coverage :branch |
| 156 | + config.minimum_coverage_by_group({"Test Group 1" => {branch: 85.0}}) |
| 157 | + |
| 158 | + expect(config.minimum_coverage_by_group).to eq({"Test Group 1" => {branch: 85.0}}) |
| 159 | + end |
| 160 | + |
| 161 | + it "sets the right coverage when called with both line and branch" do |
| 162 | + config.enable_coverage :branch |
| 163 | + config.minimum_coverage_by_group({"Test Group 1" => {branch: 85.0, line: 95.4}}) |
| 164 | + |
| 165 | + expect(config.minimum_coverage_by_group).to eq({"Test Group 1" => {branch: 85.0, line: 95.4}}) |
| 166 | + end |
| 167 | + |
| 168 | + it "raises when trying to set branch coverage but not enabled" do |
| 169 | + expect do |
| 170 | + config.minimum_coverage_by_group({"Test Group 1" => {branch: 42}}) |
| 171 | + end.to raise_error(/branch.*disabled/i) |
| 172 | + end |
| 173 | + |
| 174 | + it "raises when unknown coverage criteria provided" do |
| 175 | + expect do |
| 176 | + config.minimum_coverage_by_group({"Test Group 1" => {unknown: 42}}) |
| 177 | + end.to raise_error(/unsupported.*unknown/i) |
| 178 | + end |
| 179 | + |
| 180 | + context "when primary coverage is set" do |
| 181 | + before do |
| 182 | + config.enable_coverage :branch |
| 183 | + config.primary_coverage :branch |
| 184 | + end |
| 185 | + |
| 186 | + it "sets the right coverage value when called with a number" do |
| 187 | + config.minimum_coverage_by_group({"Test Group 1" => 80}) |
| 188 | + |
| 189 | + expect(config.minimum_coverage_by_group).to eq({"Test Group 1" => {branch: 80}}) |
| 190 | + end |
| 191 | + end |
| 192 | + end |
| 193 | + |
127 | 194 | describe "#maximum_coverage_drop" do
|
128 | 195 | it_behaves_like "setting coverage expectations", :maximum_coverage_drop
|
129 | 196 | end
|
|
0 commit comments