allending/Kiwi — Issue #72: Fix Specification Execution Scheme
Author: JohannesRudolph
Created: 2011-11-17 11:38:15+00:00
State: open

The simple suite:

```Objective-C
SPEC_BEGIN(OtherSpec)

describe(@"Outer Descripe", ^{
context(@"Context", ^{

beforeAll(^{
NSLog(@"BEFORE");
});

afterAll(^{
NSLog(@"AFTER");
});

beforeEach(^{
NSLog(@"BEFORE-EACH");
});

afterEach(^{
NSLog(@"AFTER-EACH");
});

it(@"it", ^{

});

it(@"another it", ^{
});

context(@"INNER Context", ^{

beforeAll(^{
NSLog(@" BEFORE");
});

afterAll(^{
NSLog(@" AFTER");
});

beforeEach(^{
NSLog(@" BEFORE-EACH");
});

afterEach(^{
NSLog(@" AFTER-EACH");
});

it(@"nested it", ^{

});

it(@"nested another it", ^{
});

context(@"INNER INNER Context", ^{

beforeAll(^{
NSLog(@" BEFORE");
});

afterAll(^{
NSLog(@" AFTER");
});

beforeEach(^{
NSLog(@" BEFORE-EACH");
});

afterEach(^{
NSLog(@" AFTER-EACH");
});

it(@"nested nested it", ^{

});

it(@"nested nested another it", ^{
});
});
});
});
});

SPEC_END

```

Executes as follows:

```Shell
Test Suite 'OtherSpec' started at 2011-11-17 12:26:20 +0100
Test Case '-[OtherSpec example]' started.
2011-11-17 12:26:20.904 SomeApp BEFORE
2011-11-17 12:26:20.905 SomeApp BEFORE-EACH
2011-11-17 12:26:20.905 SomeApp AFTER-EACH
2011-11-17 12:26:20.906 SomeApp + 'Outer Descripe Context it' [PASSED]
2011-11-17 12:26:20.907 SomeApp BEFORE
2011-11-17 12:26:20.907 SomeApp BEFORE
2011-11-17 12:26:20.918 SomeApp AFTER
2011-11-17 12:26:20.920 SomeApp AFTER
2011-11-17 12:26:20.923 SomeApp AFTER
Test Case '-[OtherSpec example]' passed (0.102 seconds).
Test Case '-[OtherSpec example]' started.
2011-11-17 12:26:20.927 SomeApp BEFORE
2011-11-17 12:26:20.927 SomeApp BEFORE-EACH
2011-11-17 12:26:20.935 SomeApp AFTER-EACH
2011-11-17 12:26:20.935 SomeApp + 'Outer Descripe Context another it' [PASSED]
2011-11-17 12:26:20.936 SomeApp BEFORE
2011-11-17 12:26:20.936 SomeApp BEFORE
2011-11-17 12:26:20.936 SomeApp AFTER
2011-11-17 12:26:20.937 SomeApp AFTER
2011-11-17 12:26:20.937 SomeApp AFTER
Test Case '-[OtherSpec example]' passed (0.012 seconds).
Test Case '-[OtherSpec example]' started.
2011-11-17 12:26:20.938 SomeApp BEFORE
2011-11-17 12:26:20.939 SomeApp BEFORE
2011-11-17 12:26:20.939 SomeApp BEFORE-EACH
2011-11-17 12:26:20.939 SomeApp BEFORE-EACH
2011-11-17 12:26:20.940 SomeApp AFTER-EACH
2011-11-17 12:26:20.944 SomeApp AFTER-EACH
2011-11-17 12:26:20.945 SomeApp + 'Outer Descripe Context INNER Context nested it' [PASSED]
2011-11-17 12:26:20.945 SomeApp BEFORE
2011-11-17 12:26:20.945 SomeApp AFTER
2011-11-17 12:26:20.946 SomeApp AFTER
2011-11-17 12:26:20.946 SomeApp AFTER
Test Case '-[OtherSpec example]' passed (0.009 seconds).
Test Case '-[OtherSpec example]' started.
2011-11-17 12:26:20.947 SomeApp BEFORE
2011-11-17 12:26:20.947 SomeApp BEFORE
2011-11-17 12:26:20.948 SomeApp BEFORE-EACH
2011-11-17 12:26:20.948 SomeApp BEFORE-EACH
2011-11-17 12:26:20.949 SomeApp AFTER-EACH
2011-11-17 12:26:20.949 SomeApp AFTER-EACH
2011-11-17 12:26:20.949 SomeApp + 'Outer Descripe Context INNER Context nested another it' [PASSED]
2011-11-17 12:26:20.950 SomeApp BEFORE
2011-11-17 12:26:20.952 SomeApp AFTER
2011-11-17 12:26:20.954 SomeApp AFTER
2011-11-17 12:26:20.955 SomeApp AFTER
Test Case '-[OtherSpec example]' passed (0.008 seconds).
Test Case '-[OtherSpec example]' started.
2011-11-17 12:26:20.955 SomeApp BEFORE
2011-11-17 12:26:20.956 SomeApp BEFORE
2011-11-17 12:26:20.962 SomeApp BEFORE
2011-11-17 12:26:20.962 SomeApp BEFORE-EACH
2011-11-17 12:26:20.962 SomeApp BEFORE-EACH
2011-11-17 12:26:20.963 SomeApp BEFORE-EACH
2011-11-17 12:26:20.963 SomeApp AFTER-EACH
2011-11-17 12:26:20.963 SomeApp AFTER-EACH
2011-11-17 12:26:20.963 SomeApp AFTER-EACH
2011-11-17 12:26:20.963 SomeApp + 'Outer Descripe Context INNER Context INNER INNER Context nested nested it' [PASSED]
2011-11-17 12:26:20.964 SomeApp AFTER
2011-11-17 12:26:20.964 SomeApp AFTER
2011-11-17 12:26:20.965 SomeApp AFTER
Test Case '-[OtherSpec example]' passed (0.011 seconds).
Test Case '-[OtherSpec example]' started.
2011-11-17 12:26:20.966 SomeApp BEFORE
2011-11-17 12:26:20.967 SomeApp BEFORE
2011-11-17 12:26:20.968 SomeApp BEFORE
2011-11-17 12:26:20.968 SomeApp BEFORE-EACH
2011-11-17 12:26:20.969 SomeApp BEFORE-EACH
2011-11-17 12:26:20.969 SomeApp BEFORE-EACH
2011-11-17 12:26:20.969 SomeApp AFTER-EACH
2011-11-17 12:26:20.970 SomeApp AFTER-EACH
2011-11-17 12:26:20.970 SomeApp AFTER-EACH
2011-11-17 12:26:20.971 SomeApp + 'Outer Descripe Context INNER Context INNER INNER Context nested nested another it' [PASSED]
2011-11-17 12:26:20.971 SomeApp AFTER
2011-11-17 12:26:20.971 SomeApp AFTER
2011-11-17 12:26:20.972 SomeApp AFTER
Test Case '-[OtherSpec example]' passed (0.013 seconds).
Test Suite 'OtherSpec' finished at 2011-11-17 12:26:20 +0100.
Executed 6 tests, with 0 failures (0 unexpected) in 0.155 (0.156) seconds
```

I find it a bit problematic that context blocks from levels below the currently executed "IT"-leaf get executed. And thats all of them! The last drop of Kiwi I used (think from 2 months back or so) did not have this behavior but executed only the required contexts before executing each leaf.

And then theres the problem that the beforeAll block which is supposed to be executed only once for all nested ITs is executed multiple times. Bit of an issue when fixture setup is expensive.