Quick: Running code before each context

Created on 8 May 2018  路  6Comments  路  Source: Quick/Quick

  • [x] I have read CONTRIBUTING and have done my best to follow them.

What did you do?

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"
    }
  }
}

What did you expect to happen?

I expected a new Form instance to be created before each context would run.

What actually happened instead?

My suite crashed.

Environment

List the software versions you're using:

  • Quick: 1.2.0
  • Xcode Version: 9.2
  • Swift Version: 4.0.3

Possible solution

Would it be possible to introduce something like a beforeEachContext and afterEachContext method to accommodate a setup like the one I have shared above?

question

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.

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings