Using the Gherkin syntax is `Given` not a synonym ...
# spek
r
Using the Gherkin syntax is
Given
not a synonym for
beforeGroup
/
beforeEachTest
? It seems like that would make sense. For example it’s where I’d want to initialize mocks.
r
Just added a section on migrating
given-on-it
to the gherkin style.: https://spekframework.org/migration/#given-on-it (still needs improvement). The two are somewhat similar but not symmetrical.
You setup the context on
Scenario
, if you use
memoized
it caches by scope so
Given/When/Then
will see the same instance.
Think of
Scenario
as a test method in JUnit.
r
cool. I’ll give it a read.
That’g good for testing side effects on a subject (the
set
in the docs) is there a way to generate a memoized value in the
When
portion for testing the return value for something? It’s not clear what the appropriate structure is then unless I just use a
Then
which feels like I’m throwing the grammar out the window and is awkward if there are many
Then
blocks.
I can certainly perform the “action” inside the memoized lambda. e.g.
Copy code
val response by memoized {
  service.getSomeData()
}
but if
service
relies on any mock/stub collaborators set up with
beforeGroup
that won’t work.
r
Interesting, I would probably declare
lateinit var response: Foo
on
Scenario
. Other than that I can't think of any alternatives yet.