Skip to content

Commit 110940a

Browse files
committed
Fixed regression: PendingException was causing steps to fail instead of pending. Closes #328
1 parent b3b5361 commit 110940a

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [Git master](https://github.com/cucumber/cucumber-jvm/compare/v1.0.7...master)
22

3+
* [Core] Fixed regression: PendingException was causing steps to fail instead of pending. ([#328](https://github.com/cucumber/cucumber-jvm/issues/328) Aslak Hellesøy)
34
* [Java] Missing String.format parameters in DefaultJavaObjectFactory ([#336](https://github.com/cucumber/cucumber-jvm/issues/336) paulkrause88, Aslak Hellesøy)
45
* [Core] Exceptions being swallowed if reported in a Hook ([#133](https://github.com/cucumber/cucumber-jvm/issues/133) David Kowis, Aslak Hellesøy)
56
* [Core] Added `DataTable.asMaps()` and made all returned lists immutable. (Aslak Hellesøy).

core/src/main/java/cucumber/runtime/Utils.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ public static Object invoke(Object target, Method method, Object... args) {
3333
try {
3434
return method.invoke(target, args);
3535
} catch (IllegalArgumentException e) {
36-
throw new CucumberException("Can't invoke " + MethodFormat.FULL.format(method), e);
36+
throw new CucumberException("Failed to invoke " + MethodFormat.FULL.format(method), e);
3737
} catch (InvocationTargetException e) {
38-
throw new CucumberException("Can't invoke " + MethodFormat.FULL.format(method), e.getTargetException());
38+
Throwable targetException = e.getTargetException();
39+
if(targetException instanceof PendingException) {
40+
throw (PendingException) targetException;
41+
} else {
42+
throw new CucumberException("Failed to invoke " + MethodFormat.FULL.format(method), targetException);
43+
}
3944
} catch (IllegalAccessException e) {
40-
throw new CucumberException("Can't invoke " + MethodFormat.FULL.format(method), e);
45+
throw new CucumberException("Failed to invoke " + MethodFormat.FULL.format(method), e);
4146
}
4247
}
4348
}

picocontainer/src/test/java/cucumber/runtime/java/picocontainer/StepDefs.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import cucumber.annotation.Before;
55
import cucumber.annotation.en.Given;
66
import cucumber.annotation.en.Then;
7+
import cucumber.runtime.PendingException;
78
import cucumber.runtime.ScenarioResult;
89

910
import java.util.List;
@@ -21,7 +22,7 @@ public void before() {
2122
public void gh20() {
2223
}
2324

24-
@Given(value = "^I have (\\d+) (.*) in my belly$")
25+
@Given("^I have (\\d+) (.*) in my belly$")
2526
public void I_have_n_things_in_my_belly(int amount, String what) {
2627
this.amount = amount;
2728
}
@@ -30,6 +31,11 @@ public void I_have_n_things_in_my_belly(int amount, String what) {
3031
public void I_have_this_in_my_basket(List<List<String>> stuff) {
3132
}
3233

34+
@Given("something pending")
35+
public void throw_pending() {
36+
throw new PendingException("This should not fail");
37+
}
38+
3339
@Then("^there are (\\d+) cukes in my belly")
3440
public void checkCukes(int n) {
3541
assertEquals(amount, n);

picocontainer/src/test/resources/.cucumber/stepdefs.json

+10
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@
161161
}
162162
]
163163
},
164+
{
165+
"source": "something pending",
166+
"flags": "",
167+
"steps": [
168+
{
169+
"name": "something pending",
170+
"args": []
171+
}
172+
]
173+
},
164174
{
165175
"source": "this is not used",
166176
"flags": "",

picocontainer/src/test/resources/cucumber/runtime/java/picocontainer/cukes.feature

+5
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ Feature: Cukes
2626
And a big basket with cukes
2727
And I have 12 cukes in my belly
2828

29+
Scenario: An undefined step
30+
Given something undefined
31+
32+
Scenario: A pending step
33+
Given something pending

picocontainer/src/test/resources/cucumber/runtime/java/picocontainer/dates.feature

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Feature: Dates
22

3-
43
Scenario Outline: Parsing dates with simple a format (yyyy/MM/dd)
54
Given the simple date is <input date>
65
Then the date should be viewed in <timezone> as <year>, <month>, <day>, <hours>, <minutes>, <seconds>

0 commit comments

Comments
 (0)