Skip to content

Commit

Permalink
Clarify terminology in javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
greghaskins committed Feb 1, 2016
1 parent 9006571 commit b0a3b44
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions src/main/java/com/greghaskins/spectrum/Spectrum.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ public static interface Block {
}

/**
* Declare a test suite to describe the expected behaviors of the system in a given context.
* Declare a test suite that describes the expected behavior of the system in a given context.
*
* @param context
* Description of the test context
* Description of the context for this suite
* @param block
* {@link Block} with one or more calls to {@link #it(String, Block) it} that define each expected behavior
*
*/
public static void describe(final String context, final Block block) {
final Suite suite = getCurrentContext().addSuite(context);
enterContext(suite, block);
final Suite suite = getCurrentSuite().addSuite(context);
beginDefintion(suite, block);
}

/**
* Declare a test for an expected behavior of the system.
* Declare a spec, or test, for an expected behavior of the system in this suite context.
*
* @param behavior
* Description of the expected behavior
Expand All @@ -47,67 +47,67 @@ public static void describe(final String context, final Block block) {
* if that expectation is not met.
*/
public static void it(final String behavior, final Block block) {
getCurrentContext().addSpec(behavior, block);
getCurrentSuite().addSpec(behavior, block);
}

/**
* Declare a {@link Block} to be run before each test in the current context.
* Declare a {@link Block} to be run before each spec in the suite.
*
* <p>
* Use this to perform setup actions that are common across tests in the context. If multiple {@code beforeEach} blocks are
* declared, they will run in declaration order.
* </p>
*
* @param block
* {@link Block} to run before each test
* {@link Block} to run once before each spec
*/
public static void beforeEach(final Block block) {
getCurrentContext().beforeEach(block);
getCurrentSuite().beforeEach(block);
}

/**
* Declare a {@link Block} to be run after each test in the current context.
* Declare a {@link Block} to be run after each spec in the current suite.
*
* <p>
* Use this to perform teardown or cleanup actions that are common across tests in this context. If multiple
* Use this to perform teardown or cleanup actions that are common across specs in this suite. If multiple
* {@code afterEach} blocks are declared, they will run in declaration order.
* </p>
*
* @param block
* {@link Block} to run after each test
* {@link Block} to run once after each spec
*/
public static void afterEach(final Block block) {
getCurrentContext().afterEach(block);
getCurrentSuite().afterEach(block);
}

/**
* Declare a {@link Block} to be run once before all the tests in the current context.
* Declare a {@link Block} to be run once before all the specs in the current suite begin.
*
* <p>
* Use {@code beforeAll} and {@link #afterAll(Block) afterAll} blocks with caution: since they only run once, shared state
* <strong>will</strong> leak across tests.
* <strong>will</strong> leak across specs.
* </p>
*
* @param block
* {@link Block} to run once before all tests
* {@link Block} to run once before all specs in this suite
*/
public static void beforeAll(final Block block) {
getCurrentContext().beforeAll(block);
getCurrentSuite().beforeAll(block);
}

/**
* Declare a {@link Block} to be run once after all the tests in the current context.
* Declare a {@link Block} to be run once after all the specs in the current suite have run.
*
* <p>
* Use {@link #beforeAll(Block) beforeAll} and {@code afterAll} blocks with caution: since they only run once, shared state
* <strong>will</strong> leak across tests.
* </p>
*
* @param block
* {@link Block} to run once after all tests
* {@link Block} to run once after all specs in this suite
*/
public static void afterAll(final Block block) {
getCurrentContext().afterAll(block);
getCurrentSuite().afterAll(block);
}

public static <T> Value<T> value(@SuppressWarnings("unused") final Class<T> type) {
Expand All @@ -126,41 +126,38 @@ private Value(final T value) {
}
}

private static final Deque<Suite> globalSuites = new ArrayDeque<Suite>();
static {
globalSuites.push(new Suite(Description.createSuiteDescription("Spectrum tests")));
}
private static final Deque<Suite> suiteStack = new ArrayDeque<Suite>();

private final Suite rootContext;
private final Suite rootSuite;

public Spectrum(final Class<?> testClass) {
final Description description = Description.createSuiteDescription(testClass);
this.rootContext = getCurrentContext().addSuite(description);
enterContext(this.rootContext, new ConstructorBlock(testClass));
this.rootSuite = new Suite(description);
beginDefintion(this.rootSuite, new ConstructorBlock(testClass));
}

@Override
public Description getDescription() {
return this.rootContext.getDescription();
return this.rootSuite.getDescription();
}

@Override
public void run(final RunNotifier notifier) {
this.rootContext.run(notifier);
this.rootSuite.run(notifier);
}

private static void enterContext(final Suite suite, final Block block) {
globalSuites.push(suite);
private static void beginDefintion(final Suite suite, final Block definitionBlock) {
suiteStack.push(suite);
try {
block.run();
definitionBlock.run();
} catch (final Throwable e) {
it("encountered an error", new FailingBlock(e));
}
globalSuites.pop();
suiteStack.pop();
}

private static Suite getCurrentContext() {
return globalSuites.peek();
private static Suite getCurrentSuite() {
return suiteStack.peek();
}

}

0 comments on commit b0a3b44

Please sign in to comment.