cades / respec-given

rspec-given on mocha
MIT License
6 stars 2 forks source link

classical BDD interface compatibility support #4

Open cades opened 8 years ago

cades commented 8 years ago

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

For example,

cades commented 8 years ago

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

cades commented 8 years ago

proposal 1: BDD interface

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

proposal 2: new clause

proposal 3: tell Given to clean up

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

// to this
Given server:
  setup: -> App.listen()
  teardown: -> @server.close()

Question

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

cades commented 8 years ago

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