greghaskins / spectrum

A BDD-style test runner for Java 8. Inspired by Jasmine, RSpec, and Cucumber.
MIT License
145 stars 23 forks source link

Fix Issue #132 -- Make `let` Lazily Evaluated #133

Closed GuyPaddock closed 6 years ago

GuyPaddock commented 6 years ago

The previous implementation would cause all let blocks to be evaluated at the start of the test rather than on an as-needed basis, which is inconsistent with the behavior developers who are used to RSpec would expect. Now, let only evaluates its block when the test first needs a value, allowing the let block to depend on state that is being setup by other blocks (beforeEach, other let blocks, etc).

Despite this, there was value in preserving the old implementation as Spectrum's equivalent to let! from RSpec. As such, I've moved that implementation over to a new DSL helper called eagerLet. One use case where this is useful is defining values that can be used in a beforeEach block.

Closes #132.

codecov[bot] commented 6 years ago

Codecov Report

Merging #133 into master will increase coverage by 0.01%. The diff coverage is 100%.

@@             Coverage Diff              @@
##             master     #133      +/-   ##
============================================
+ Coverage     99.45%   99.47%   +0.01%     
- Complexity      349      358       +9     
============================================
  Files            43       44       +1     
  Lines           739      763      +24     
  Branches         22       23       +1     
============================================
+ Hits            735      759      +24     
  Partials          4        4
Impacted Files Coverage Δ Complexity Δ
...ghaskins/spectrum/internal/hooks/EagerLetHook.java 100% <100%> (ø) 3 <3> (?)
...kins/spectrum/dsl/specification/Specification.java 100% <100%> (ø) 20 <1> (+1) :arrow_up:
...m/greghaskins/spectrum/internal/hooks/LetHook.java 100% <100%> (ø) 8 <7> (+5) :arrow_up:
greghaskins commented 6 years ago

Thanks for the contribution @GuyPaddock. This looks great,