allending/Kiwi — Issue #64: All beforeAll() calls are called before every "it"block no matter which context it was defined in
Author: kglee79
Created: 2011-10-15 05:02:42+00:00
State: open

According to the documentation beforeAll is "is run once before all the inner contexts and it blocks of the context it is in". However, it appears to be running all beforeAll blocks before every "it" block no matter which context it is in. The following code produces the output shown.

Code
-------------
SPEC_BEGIN(TestSpec)

describe(@"Testing", ^{
beforeAll(^{
NSLog(@"Running before all 1");
});

it(@"example 1", ^{
NSLog(@"Running example 1");
});

context(@"Context 1", ^{
beforeAll(^{
NSLog(@"Running before all 1.1");
});

it(@"example 2", ^{
NSLog(@"Running example 1.1");
});

context(@"Context 1.1", ^{
beforeAll(^{
NSLog(@"Running before all 1.1.1");
});

it(@"example 3", ^{
NSLog(@"Running example 1.1.1");
});

context(@"Context 1.1.1", ^{
it(@"example 4", ^{
NSLog(@"Running example 1.1.1.1");
});
});
});
});

context(@"Context 2", ^{
beforeAll(^{
NSLog(@"Running before all 2");
});

it(@"example 2", ^{
NSLog(@"Running example 2");
});

context(@"Context 2.1", ^{
beforeAll(^{
NSLog(@"Running before all 2.1");
});

it(@"example 3", ^{
NSLog(@"Running example 2.1.1");
});

context(@"Context 2.1.1", ^{
it(@"example 4", ^{
NSLog(@"Running example 2.1.1.1");
});
});
});
});
});

SPEC_END

Output
-----------
Test Suite 'TestSpec' started at 2011-10-15 04:56:19 +0000
Test Case '-[TestSpec example]' started.
2011-10-14 21:56:19.748 MyTestApp[42950:207] Running before all 1
2011-10-14 21:56:19.749 MyTestApp[42950:207] Running example 1
2011-10-14 21:56:19.749 MyTestApp[42950:207] + 'Testing example 1' [PASSED]
2011-10-14 21:56:19.750 MyTestApp[42950:207] Running before all 1.1
2011-10-14 21:56:19.758 MyTestApp[42950:207] Running before all 1.1.1
2011-10-14 21:56:19.759 MyTestApp[42950:207] Running before all 2
2011-10-14 21:56:19.760 MyTestApp[42950:207] Running before all 2.1
Test Case '-[TestSpec example]' passed (0.012 seconds).
Test Case '-[TestSpec example]' started.
2011-10-14 21:56:19.761 MyTestApp[42950:207] Running before all 1
2011-10-14 21:56:19.761 MyTestApp[42950:207] Running before all 1.1
2011-10-14 21:56:19.762 MyTestApp[42950:207] Running example 1.1
2011-10-14 21:56:19.762 MyTestApp[42950:207] + 'Testing In Context 1 example 2' [PASSED]
2011-10-14 21:56:19.763 MyTestApp[42950:207] Running before all 1.1.1
2011-10-14 21:56:19.763 MyTestApp[42950:207] Running before all 2
2011-10-14 21:56:19.764 MyTestApp[42950:207] Running before all 2.1
Test Case '-[TestSpec example]' passed (0.004 seconds).
Test Case '-[TestSpec example]' started.
2011-10-14 21:56:19.765 MyTestApp[42950:207] Running before all 1
2011-10-14 21:56:19.796 MyTestApp[42950:207] Running before all 1.1
2011-10-14 21:56:19.797 MyTestApp[42950:207] Running before all 1.1.1
2011-10-14 21:56:19.798 MyTestApp[42950:207] Running example 1.1.1
2011-10-14 21:56:19.799 MyTestApp[42950:207] + 'Testing In Context 1 Context 1.1 example 3' [PASSED]
2011-10-14 21:56:19.800 MyTestApp[42950:207] Running before all 2
2011-10-14 21:56:19.800 MyTestApp[42950:207] Running before all 2.1
Test Case '-[TestSpec example]' passed (0.036 seconds).
Test Case '-[TestSpec example]' started.
2011-10-14 21:56:19.801 MyTestApp[42950:207] Running before all 1
2011-10-14 21:56:19.802 MyTestApp[42950:207] Running before all 1.1
2011-10-14 21:56:19.803 MyTestApp[42950:207] Running before all 1.1.1
2011-10-14 21:56:19.803 MyTestApp[42950:207] Running example 1.1.1.1
2011-10-14 21:56:19.804 MyTestApp[42950:207] + 'Testing In Context 1 Context 1.1 Context 1.1.1 example 4' [PASSED]
2011-10-14 21:56:19.805 MyTestApp[42950:207] Running before all 2
2011-10-14 21:56:19.818 MyTestApp[42950:207] Running before all 2.1
Test Case '-[TestSpec example]' passed (0.018 seconds).
Test Case '-[TestSpec example]' started.
2011-10-14 21:56:19.819 MyTestApp[42950:207] Running before all 1
2011-10-14 21:56:19.820 MyTestApp[42950:207] Running before all 1.1
2011-10-14 21:56:19.821 MyTestApp[42950:207] Running before all 1.1.1
2011-10-14 21:56:19.822 MyTestApp[42950:207] Running before all 2
2011-10-14 21:56:19.822 MyTestApp[42950:207] Running example 2
2011-10-14 21:56:19.823 MyTestApp[42950:207] + 'Testing In Context 2 example 2' [PASSED]
2011-10-14 21:56:19.824 MyTestApp[42950:207] Running before all 2.1
Test Case '-[TestSpec example]' passed (0.005 seconds).
Test Case '-[TestSpec example]' started.
2011-10-14 21:56:19.824 MyTestApp[42950:207] Running before all 1
2011-10-14 21:56:19.825 MyTestApp[42950:207] Running before all 1.1
2011-10-14 21:56:19.826 MyTestApp[42950:207] Running before all 1.1.1
2011-10-14 21:56:19.826 MyTestApp[42950:207] Running before all 2
2011-10-14 21:56:19.827 MyTestApp[42950:207] Running before all 2.1
2011-10-14 21:56:19.827 MyTestApp[42950:207] Running example 2.1.1
2011-10-14 21:56:19.828 MyTestApp[42950:207] + 'Testing In Context 2 Context 2.1 example 3' [PASSED]
Test Case '-[TestSpec example]' passed (0.005 seconds).
Test Case '-[TestSpec example]' started.
2011-10-14 21:56:19.829 MyTestApp[42950:207] Running before all 1
2011-10-14 21:56:19.830 MyTestApp[42950:207] Running before all 1.1
2011-10-14 21:56:19.830 MyTestApp[42950:207] Running before all 1.1.1
2011-10-14 21:56:19.831 MyTestApp[42950:207] Running before all 2
2011-10-14 21:56:19.831 MyTestApp[42950:207] Running before all 2.1
2011-10-14 21:56:19.832 MyTestApp[42950:207] Running example 2.1.1.1
2011-10-14 21:56:19.832 MyTestApp[42950:207] + 'Testing In Context 2 Context 2.1 Context 2.1.1 example 4' [PASSED]
Test Case '-[TestSpec example]' passed (0.005 seconds).
Test Suite 'TestSpec' finished at 2011-10-15 04:56:19 +0000.
Executed 7 tests, with 0 failures (0 unexpected) in 0.086 (0.086) seconds