cedarbdd / cedar

BDD-style testing using Objective-C
http://groups.google.com/group/cedar-discuss
1.19k stars 140 forks source link

Only call +before/afterEach on CDRHooks conformers #387

Closed idoru closed 8 years ago

idoru commented 8 years ago

Rebased from #365, some small refactoring and addition of tests for +afterEach hook.

Tests for +afterEach are performed via asserts that are set up using atexit(3) since Cedar specs don't have visibility outside of their own context. Would like to know if anyone has better ideas for how to test this.

@tjarratt and I debated the inclusion of the test classes in CDRHooksSpec.mm but we ultimately felt it made the distinguishing characteristics clear. Curious to know how others feel about it.

This change also stops special casing for UIAccessibilitySafeCategory__NSObject and SCRCException since we shouldn't expect them to conform to CDRHooks.

tjarratt commented 8 years ago

Interesting point about not having to special case those classes now -- because that if statement should bail out early when those classes don't conform to our protocol, it should be safe to call that function with any Class. That's a great improvement to this bit of code.

idoru commented 8 years ago

Having slept on this, I'm not happy that these tests only really can see if the methods were called, but not when.

In fact, as soon as a single example runs (quite likely before this test), then +beforeEach and +afterEach on the conformant class will already have been called.

idoru commented 8 years ago

2db594b is closer to what I'm thinking but I only realized when I finally ran rake that this doesn't work on suites because the TestObservationHelper relies on XCTest.