forked from greghaskins/spectrum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue greghaskins#132 -- Move Old Let Over to Being
eagerLet
The previous implementation is closer to `let!` from RSpec. As such, it's still useful for cases in which a developer needs values to be available in the `beforeEach` block.
- Loading branch information
Guy Paddock
committed
Mar 8, 2018
1 parent
088f773
commit 24276b1
Showing
4 changed files
with
526 additions
and
4 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
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/greghaskins/spectrum/internal/hooks/EagerLetHook.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,26 @@ | ||
package com.greghaskins.spectrum.internal.hooks; | ||
|
||
import com.greghaskins.spectrum.ThrowingSupplier; | ||
|
||
/** | ||
* Implementation of an eager version of {@code let}. | ||
* | ||
* <p>Sematics are the same as with {@link LetHook}, except that all values are calculated at the | ||
* start of the test, rather than on an as-needed basis. | ||
*/ | ||
public class EagerLetHook<T> extends AbstractSupplyingHook<T> { | ||
private final ThrowingSupplier<T> supplier; | ||
|
||
public EagerLetHook(final ThrowingSupplier<T> supplier) { | ||
this.supplier = supplier; | ||
} | ||
|
||
protected T before() { | ||
return supplier.get(); | ||
} | ||
|
||
protected String getExceptionMessageIfUsedAtDeclarationTime() { | ||
return "Cannot use the value from eagerLet() in a suite declaration. " | ||
+ "It may only be used in the context of a running spec."; | ||
} | ||
} |
Oops, something went wrong.