searls/jasmine-fixture — Issue #2: tidyUp and init() in global beforeEach
Author: kchien
Created: 2011-10-26 16:44:22+00:00
State: open

What are your thoughts in cleaning up in a global beforeEach(), rather than in afterEach()?

My reasons for desiring this feature:
1) The book "Growing Object Oriented Software: Guided by Tests" (aka GOOS) on page 292, discusses tests with databases. In particular, they recommend cleaning up before each test; and one of their reasons is that they can diagnose failures better.
2) Each test will still start with a clean slate if tidyUp() followed by init() is called in a global beforeEach().
3) I made a local modification to do just this, and it came in handy when diagnosing a nasty bug involving applying $(selector).live() multiple times (in beforeEach()) without calling die().

If people prefer to clean up in afterEach(), this could be a configurable option (which I'm leaning towards).
By default, it would clean up in afterEach(), but you could configure it to clean up only in beforeEach().

The only difficult part would be to spec out this behavior and verifying that the specContainer is still around.

Thoughts?