You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: docs/VariablesAndValues.md
+65-4Lines changed: 65 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -12,10 +12,14 @@ when the test is broken into separate steps.
12
12
The `let` function is used to initialise a fresh, isolated, object for each spec.
13
13
14
14
### Common Variable Initialization
15
+
#### Let
16
+
The `let` helper function makes it easy to initialize common variables that are used in multiple
17
+
specs. In standard JUnit you might expect to use the initializer list of the class or a `@Before`
18
+
method to achieve the same. As there is no easy way for `beforeAll` or `beforeEach` to instantiate
19
+
a value that will be used in the specs, `let` is the tool of choice.
15
20
16
-
The `let` helper function makes it easy to initialize common variables that are used in multiple specs. In standard JUnit you might expect to use the initializer list of the class or a `@Before` method to achieve the same. As there is no easy way for `beforeAll` or `beforeEach` to instantiate a value that will be used in the specs, `let` is the tool of choice.
17
-
18
-
Values are cached within a spec, and lazily re-initialized between specs as in [RSpec #let](http://rspec.info/documentation/3.5/rspec-core/RSpec/Core/MemoizedHelpers/ClassMethods.html#let-instance_method).
21
+
Values are cached within a spec, and lazily re-initialized between specs as in
For cases where you need to access a shared variable across specs or steps, the `Variable` helper class provides a simple `get`/`set` interface. This may be required, for example, to initialize shared state in a `beforeAll` that is used across multiple specs in that suite. Of course, you should exercise caution when sharing state across tests
49
+
#### Eager Let
50
+
If you need to ensure that a value is initialized at the start of a test, you can use the `eagerLet`
51
+
helper function, which has the same semantics as `let` but is evaluated prior to `beforeEach`. This
52
+
is often useful when you need to initialize values you can use in your `beforeEach` block. The value
53
+
is still initialized after any `beforeAll` blocks.
0 commit comments