|
19 | 19 | public class RerunFormatterTest {
|
20 | 20 |
|
21 | 21 | @Test
|
22 |
| - public void should_leave_report_empty_when_no_scenario_fails() throws Throwable { |
| 22 | + public void should_leave_report_empty_when_exit_code_is_zero() throws Throwable { |
23 | 23 | CucumberFeature feature = TestHelper.feature("path/test.feature", "" +
|
24 | 24 | "Feature: feature name\n" +
|
25 |
| - " Scenario: scenario name\n" + |
26 |
| - " Given first step\n" + |
27 |
| - " When second step\n" + |
28 |
| - " Then third step\n"); |
| 25 | + " Scenario: passed scenario\n" + |
| 26 | + " Given passed step\n" + |
| 27 | + " Scenario: pending scenario\n" + |
| 28 | + " Given pending step\n" + |
| 29 | + " Scenario: undefined scenario\n" + |
| 30 | + " Given undefined step\n"); |
29 | 31 | Map<String, Result> stepsToResult = new HashMap<String, Result>();
|
30 |
| - stepsToResult.put("first step", result("passed")); |
31 |
| - stepsToResult.put("second step", result("passed")); |
32 |
| - stepsToResult.put("third step", result("passed")); |
| 32 | + stepsToResult.put("passed step", result("passed")); |
| 33 | + stepsToResult.put("pending step", result("pending")); |
| 34 | + stepsToResult.put("undefined step", result("undefined")); |
33 | 35 |
|
34 | 36 | String formatterOutput = runFeatureWithRerunFormatter(feature, stepsToResult);
|
35 | 37 |
|
36 | 38 | assertEquals("", formatterOutput);
|
37 | 39 | }
|
38 | 40 |
|
| 41 | + @Test |
| 42 | + public void should_put_data_in_report_when_exit_code_is_non_zero() throws Throwable { |
| 43 | + CucumberFeature feature = TestHelper.feature("path/test.feature", "" + |
| 44 | + "Feature: feature name\n" + |
| 45 | + " Scenario: failed scenario\n" + |
| 46 | + " Given failed step\n" + |
| 47 | + " Scenario: pending scenario\n" + |
| 48 | + " Given pending step\n" + |
| 49 | + " Scenario: undefined scenario\n" + |
| 50 | + " Given undefined step\n"); |
| 51 | + Map<String, Result> stepsToResult = new HashMap<String, Result>(); |
| 52 | + stepsToResult.put("failed step", result("failed")); |
| 53 | + stepsToResult.put("pending step", result("pending")); |
| 54 | + stepsToResult.put("undefined step", result("undefined")); |
| 55 | + |
| 56 | + String formatterOutput = runFeatureWithRerunFormatter(feature, stepsToResult, strict(true)); |
| 57 | + |
| 58 | + assertEquals("path/test.feature:2:4:6", formatterOutput); |
| 59 | + } |
| 60 | + |
39 | 61 | @Test
|
40 | 62 | public void should_use_scenario_location_when_scenario_step_fails() throws Throwable {
|
41 | 63 | CucumberFeature feature = TestHelper.feature("path/test.feature", "" +
|
@@ -180,26 +202,42 @@ public void should_one_entry_for_each_failing_feature() throws Throwable {
|
180 | 202 |
|
181 | 203 | private String runFeatureWithRerunFormatter(final CucumberFeature feature, final Map<String, Result> stepsToResult)
|
182 | 204 | throws Throwable {
|
183 |
| - return runFeatureWithRerunFormatter(feature, stepsToResult, Collections.<SimpleEntry<String, Result>>emptyList()); |
| 205 | + return runFeatureWithRerunFormatter(feature, stepsToResult, Collections.<SimpleEntry<String, Result>>emptyList(), false); |
| 206 | + } |
| 207 | + |
| 208 | + private String runFeatureWithRerunFormatter(final CucumberFeature feature, final Map<String, Result> stepsToResult, boolean isStrict) |
| 209 | + throws Throwable { |
| 210 | + return runFeatureWithRerunFormatter(feature, stepsToResult, Collections.<SimpleEntry<String, Result>>emptyList(), isStrict); |
184 | 211 | }
|
185 | 212 |
|
186 | 213 | private String runFeatureWithRerunFormatter(final CucumberFeature feature, final Map<String, Result> stepsToResult,
|
187 | 214 | final List<SimpleEntry<String, Result>> hooks) throws Throwable {
|
188 |
| - return runFeaturesWithRerunFormatter(Arrays.asList(feature), stepsToResult, hooks); |
| 215 | + return runFeaturesWithRerunFormatter(Arrays.asList(feature), stepsToResult, hooks, strict(false)); |
| 216 | + } |
| 217 | + |
| 218 | + private String runFeatureWithRerunFormatter(final CucumberFeature feature, final Map<String, Result> stepsToResult, |
| 219 | + final List<SimpleEntry<String, Result>> hooks, boolean isStrict) throws Throwable { |
| 220 | + return runFeaturesWithRerunFormatter(Arrays.asList(feature), stepsToResult, hooks, isStrict); |
189 | 221 | }
|
190 | 222 |
|
191 | 223 | private String runFeaturesWithRerunFormatter(final List<CucumberFeature> features, final Map<String, Result> stepsToResult)
|
192 | 224 | throws Throwable {
|
193 |
| - return runFeaturesWithRerunFormatter(features, stepsToResult, Collections.<SimpleEntry<String, Result>>emptyList()); |
| 225 | + return runFeaturesWithRerunFormatter(features, stepsToResult, Collections.<SimpleEntry<String, Result>>emptyList(), strict(false)); |
194 | 226 | }
|
195 | 227 |
|
196 | 228 | private String runFeaturesWithRerunFormatter(final List<CucumberFeature> features, final Map<String, Result> stepsToResult,
|
197 |
| - final List<SimpleEntry<String, Result>> hooks) throws Throwable { |
| 229 | + final List<SimpleEntry<String, Result>> hooks, boolean isStrict) throws Throwable { |
198 | 230 | final StringBuffer buffer = new StringBuffer();
|
199 | 231 | final RerunFormatter rerunFormatter = new RerunFormatter(buffer);
|
| 232 | + if (isStrict) { |
| 233 | + rerunFormatter.setStrict(isStrict); |
| 234 | + } |
200 | 235 | final long stepHookDuration = 0;
|
201 | 236 | TestHelper.runFeaturesWithFormatter(features, stepsToResult, hooks, stepHookDuration, rerunFormatter, rerunFormatter);
|
202 | 237 | return buffer.toString();
|
203 | 238 | }
|
204 | 239 |
|
| 240 | + private boolean strict(boolean value) { |
| 241 | + return value; |
| 242 | + } |
205 | 243 | }
|
0 commit comments