-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #10 Scenarios are now isolated one from another. No params or b…
…ody will be spilled to next Scenario
- Loading branch information
1 parent
4759305
commit 4208c9f
Showing
4 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
cukes-rest/src/main/java/lv/ctco/cukesrest/api/CucumberHooks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package lv.ctco.cukesrest.api; | ||
|
||
import com.google.inject.*; | ||
import cucumber.api.java.*; | ||
import lv.ctco.cukesrest.internal.*; | ||
|
||
public class CucumberHooks { | ||
|
||
@Inject | ||
CucumberFacade cucumberFacade; | ||
|
||
@Before | ||
public void beforeScenario() { | ||
if (cucumberFacade.firstScenario()) { | ||
cucumberFacade.beforeAllTests(); | ||
} | ||
cucumberFacade.beforeScenario(); | ||
} | ||
|
||
@After | ||
public void afterScenario() { | ||
cucumberFacade.afterScenario(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
cukes-rest/src/main/java/lv/ctco/cukesrest/internal/CucumberFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package lv.ctco.cukesrest.internal; | ||
|
||
import com.google.inject.*; | ||
import lv.ctco.cukesrest.*; | ||
|
||
import java.util.*; | ||
|
||
@Singleton | ||
public class CucumberFacade { | ||
|
||
/* Ugly Hack proposed by Cucumber developers: https://github.com/cucumber/cucumber-jvm/pull/295 */ | ||
public static boolean firstRun = true; | ||
|
||
@Inject | ||
Set<CukesRestPlugin> pluginSet; | ||
|
||
@Inject | ||
RequestSpecificationFacade requestSpecificationFacade; | ||
|
||
public boolean firstScenario() { | ||
return firstRun; | ||
} | ||
|
||
public void beforeAllTests() { | ||
firstRun = false; | ||
for (CukesRestPlugin cukesRestPlugin : pluginSet) { | ||
cukesRestPlugin.beforeAllTests(); | ||
} | ||
Runtime.getRuntime().addShutdownHook(new Thread() { | ||
@Override | ||
public void run() { | ||
afterAllTests(); | ||
} | ||
}); | ||
} | ||
|
||
public void beforeScenario() { | ||
for (CukesRestPlugin cukesRestPlugin : pluginSet) { | ||
cukesRestPlugin.beforeScenario(); | ||
} | ||
} | ||
|
||
public void afterScenario() { | ||
for (CukesRestPlugin cukesRestPlugin : pluginSet) { | ||
cukesRestPlugin.afterScenario(); | ||
} | ||
requestSpecificationFacade.initNewSpecification(); | ||
} | ||
|
||
public void afterAllTests() { | ||
for (CukesRestPlugin cukesRestPlugin : pluginSet) { | ||
cukesRestPlugin.afterAllTests(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters