-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from ashleyfrieze/af-bdd-1
Adding Gherkin-like feature set, see #50
- Loading branch information
Showing
15 changed files
with
610 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.java text eol=lf | ||
*.md text eol=lf | ||
*.gradle text eol=lf |
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
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package com.greghaskins.spectrum; | ||
|
||
/** | ||
* A generic code block with a {@link #run()} method to perform any action. Usually defined by a | ||
* lambda function. | ||
*/ | ||
@FunctionalInterface | ||
interface Block { | ||
public interface Block { | ||
void run() throws Throwable; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/greghaskins/spectrum/FailureDetectingRunListener.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,31 @@ | ||
package com.greghaskins.spectrum; | ||
|
||
import org.junit.runner.notification.Failure; | ||
import org.junit.runner.notification.RunListener; | ||
|
||
/** | ||
* A listener to detect test failure. | ||
*/ | ||
class FailureDetectingRunListener extends RunListener { | ||
private boolean hasFailedYet = false; | ||
|
||
/** | ||
* Has the run failed since we've been listening. | ||
* @return whether any previous failures have been reported | ||
*/ | ||
boolean hasFailedYet() { | ||
return hasFailedYet; | ||
} | ||
|
||
@Override | ||
public void testFailure(Failure failure) throws Exception { | ||
super.testFailure(failure); | ||
hasFailedYet = true; | ||
} | ||
|
||
@Override | ||
public void testAssumptionFailure(Failure failure) { | ||
super.testAssumptionFailure(failure); | ||
hasFailedYet = true; | ||
} | ||
} |
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,68 @@ | ||
package com.greghaskins.spectrum; | ||
|
||
import static com.greghaskins.spectrum.Spectrum.compositeSpec; | ||
import static com.greghaskins.spectrum.Spectrum.describe; | ||
import static com.greghaskins.spectrum.Spectrum.it; | ||
|
||
/** | ||
* A translation from Spectrum describe/it to Gherkin like Feature/Scenario/Given/When/Then syntax | ||
* Note - the beforeEach and afterEach will still be executed between given/when/then steps which | ||
* may not make sense in many situations. | ||
*/ | ||
public class GherkinSyntax { | ||
/** | ||
* Describes a feature of the system. A feature may have many scenarios. | ||
* @param featureName name of feature | ||
* @param block the contents of the feature | ||
*/ | ||
public static void feature(final String featureName, final Block block) { | ||
describe("Feature: " + featureName, block); | ||
} | ||
|
||
/** | ||
* Describes a scenario of the system. These can be at root level, though are best grouped | ||
* inside features. | ||
* @param scenarioName name of scenario | ||
* @param block the contents of the scenario - given/when/then steps | ||
*/ | ||
public static void scenario(final String scenarioName, final Block block) { | ||
compositeSpec("Scenario: " + scenarioName, block); | ||
} | ||
|
||
/** | ||
* A gherkin like given block. | ||
* @param behavior the behaviour to associate with the precondition | ||
* @param block how to execute that precondition | ||
*/ | ||
public static void given(final String behavior, final Block block) { | ||
it("Given " + behavior, block); | ||
} | ||
|
||
/** | ||
* A gherkin like when block. | ||
* @param behavior the behaviour to associate with the manipulation of the system under test | ||
* @param block how to execute that behaviour | ||
*/ | ||
public static void when(final String behavior, final Block block) { | ||
it("When " + behavior, block); | ||
} | ||
|
||
/** | ||
* A gherkin like then block. | ||
* @param behavior the behaviour to associate with the postcondition | ||
* @param block how to execute that postcondition | ||
*/ | ||
public static void then(final String behavior, final Block block) { | ||
it("Then " + behavior, block); | ||
} | ||
|
||
/** | ||
* An and block. | ||
* @param behavior what we would like to describe as an and | ||
* @param block how to achieve the and block | ||
*/ | ||
public static void and(final String behavior, final Block block) { | ||
it("And " + behavior, block); | ||
} | ||
|
||
} |
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
Oops, something went wrong.