Skip to content
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

classical BDD interface compatibility support #4

Open
cades opened this issue Jul 4, 2016 · 3 comments
Open

classical BDD interface compatibility support #4

cades opened this issue Jul 4, 2016 · 3 comments

Comments

@cades
Copy link
Owner

cades commented Jul 4, 2016

Given/When/Then doesn't cover the functionality that after covers.

For example,

  • shut down an HTTP server after each test case.
  • reset testdouble
@cades
Copy link
Owner Author

cades commented Jul 4, 2016

Note: there is a same issue in rspec-given.

@cades
Copy link
Owner Author

cades commented Jul 4, 2016

proposal 1: BDD interface

  • before / beforeEach / after / afterEach

if a setup needs to tear down, put it in before instead of Given.

proposal 2: new clause

  • Cleanup, Afterwards, Ensure or Finally

proposal 3: tell Given to clean up

// change this
Given server: -> Server.listen()

// to this
Given server:
  setup: -> App.listen()
  teardown: -> @server.close()
  • rule 1: teardowns are executed in reverse order compared to setups.
  • rule 2: if a setup is executed, the corresponding teardown is guaranteed to be executed no matter this test success or fail.
  • rule 3: if a setup is not executed, the corresponding teardown will not be executed.

Question

what if after / Cleanup / teardown throws? should it fail the test or be silent ignored?

cades added a commit that referenced this issue Jul 13, 2016
this commit is a experimental solution to issue #4
each `Cleanup` is ensured to be executed no matter previous clauses pass or fail.
@cades
Copy link
Owner Author

cades commented Jul 14, 2016

Cleanup clause is implemented in this commit.

Now Given covered beforeEach, Cleanup covered afterEach. But still lack of support to before and after.

Some thoughts:

  1. If the underlying test framework provides before / after hook, it will be much simpler for respec-given to implement this feature

  2. respec-given has no concept of test suite, so if we want to implement it natively, we need to answer these questions:

    1. how many test belongs to this suite?
    2. does this test is the first/last test of this suite? (if so, execute before / after)
  3. need to clearly defined execution order

    Then clause

    1. nearby befores if is the first test in suite
    2. all beforeEachs
    3. all Givens
    4. all Whens
    5. all Invariants
    6. Then
    7. nearby Ands
    8. all Cleanups
    9. all afterEachs
    10. nearby afters if is the last test in suite

    it block

    1. nearby befores if is the first test in suite
    2. all beforeEachs
    3. it
    4. all afterEachs
    5. nearby afters if is the last test in suite

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

No branches or pull requests

1 participant