specta/specta — pull request #86 by cimbul (2014-06-17 14:40:29+00:00)
Title: Fix OCMock 3 incompatibility by adding required protocol for global beforeEach/afterEach

#21 introduced functionality to run `+beforeEach` or `+afterEach` methods from any class around every example in the test target. This causes crashes when stubbing class methods with OCMock 3, because the `ClassesWithClassMethod` function in `SPTExampleGroup.m` looks for those methods on OCMock's stubbed classes before they are properly set up.

I've looked at several ways to fix the incompatibility (from the OCMock side as well as Specta), but this one seems like the best approach: instead of looking for `+beforeEach` or `+afterEach` on _any_ class, Specta will look for classes that conform to a new protocol: `SPTGlobalBeforeAfterEach`. It probably should have been implemented this way from the start:
* Adding the protocol signals the programmer's intent more clearly and makes it marginally easier to find these classes.
* While the chances of having non-test-related methods named `+beforeEach` or `+afterEach` are low, it can certainly happen. There is already a special case to avoid the `UIAccessibilitySafeCategory__NSObject` class, and using a protocol makes that unnecessary.

This is a backwards-incompatible change, but the fix is extremely easy. On any class that has these methods,

```objective-c
@interface SomeSharedTestSetup : NSObject
+ (void)beforeEach;
+ (void)afterEach;
@end
```

just add the protocol to the interface declaration:

```objective-c
@interface SomeSharedTestSetup : NSObject
+ (void)beforeEach;
+ (void)afterEach;
@end
```