Skip to content

Commit

Permalink
Fixed #10 Scenarios are now isolated one from another. No params or b…
Browse files Browse the repository at this point in the history
…ody will be spilled to next Scenario
  • Loading branch information
AlexeyBuzdin authored and IgorGursky committed Feb 3, 2016
1 parent 4759305 commit 4208c9f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cukes-rest/src/main/java/lv/ctco/cukesrest/CukesRestPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

public interface CukesRestPlugin {

// TODO
void beforeFeature();
void beforeAllTests();

void afterAllTests();

// TODO
void beforeScenario();

// TODO
void beforeStep();
void afterScenario();

void beforeRequest();

void afterRequest();
}
24 changes: 24 additions & 0 deletions cukes-rest/src/main/java/lv/ctco/cukesrest/api/CucumberHooks.java
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();
}
}
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public ResponseWrapper call() throws Exception {
cukesRestPlugin.beforeRequest();
}
response = method.doRequest(specification.value(), url);
for (CukesRestPlugin cukesRestPlugin : pluginSet) {
cukesRestPlugin.afterRequest();
}
return new ResponseWrapper(response);
}
};
Expand Down

0 comments on commit 4208c9f

Please sign in to comment.