I set up the following test:
describe("Given a login form") {
var form: Form!
beforeEach {
form = Form()
}
context("When setting a username") {
form.username = "Mickey"
it("Then the form should have a username") {
expect(form.username) == "Mickey"
}
}
context("When setting a password") {
form.password = "IAmMickey"
it("Then the form should have a password") {
expect(form.username) == "IAmMickey"
}
}
}
I expected a new Form
instance to be created before each context would run.
My suite crashed.
List the software versions you're using:
Would it be possible to introduce something like a beforeEachContext
and afterEachContext
method to accommodate a setup like the one I have shared above?
AFAIK, beforeEach
will only trigger when there is a it
block below.
See https://github.com/Quick/Quick/issues/445#issuecomment-260572143
Yes I am aware of that. I guess my issue mostly is that I noticed this and am looking for a way to execute something before a context runs so I can set up my code as I鈥檝e shown in my issue (possibly adding it in a PR if folks agree this could be useful)
I know this issue is a little bit old but I just came across it and I鈥檇 like to verify my thinking. My guess is that the suite was crashing because of form.username = "Mickey"
not being wrapped inside in its own beforeEach
. It caused the line being executed before the shared beforeEach
closure in which you create the form.
AFAIK this is intended behavior and this issue can be closed.
This is correct. However, what I intended to bring to light with this issue is that there is no way to run a block of code before a context block is run.
I too thought beforeEach
and afterEach
would work like this. Is there a possibility that this would be implemented?
https://github.com/Quick/Quick/issues/788#issuecomment-443651565 describes the situation correctly. Closing.
Most helpful comment
This is correct. However, what I intended to bring to light with this issue is that there is no way to run a block of code before a context block is run.