Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

GuyPaddock
Copy link
Contributor

@GuyPaddock GuyPaddock commented Mar 8, 2018

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
Copy link

codecov bot commented Mar 8, 2018

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) ⬆️
...m/greghaskins/spectrum/internal/hooks/LetHook.java 100% <100%> (ø) 8 <7> (+5) ⬆️

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).
@GuyPaddock GuyPaddock force-pushed the feature/issue-132--let-should-be-lazy branch 3 times, most recently from af9e80e to 24276b1 Compare March 8, 2018 21:22
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.
@GuyPaddock GuyPaddock force-pushed the feature/issue-132--let-should-be-lazy branch from 24276b1 to 3f73979 Compare March 8, 2018 21:23
@greghaskins
Copy link
Owner

Thanks for the contribution @GuyPaddock. This looks great,

@greghaskins greghaskins merged commit 2f7fd16 into greghaskins:master Mar 18, 2018
@GuyPaddock GuyPaddock deleted the feature/issue-132--let-should-be-lazy branch March 24, 2018 18:38
GuyPaddock pushed a commit to GuyPaddock/spectrum that referenced this pull request Mar 24, 2018
Catches some documentation that wasn't updated in greghaskins#133.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants