$ show jonreid/OCMockito
OCMockito is an Objective-C mocking library modeled after Mockito for Java. It provides mock objects, stubbing, and verification for unit tests. The library is built as a framework or static library, targeting iOS, macOS, tvOS, watchOS, and visionOS. Its architecture is modular: Core (public API), Mocking (NSProxy-based mock classes), Stubbing (invocation containers and answer objects), Verifying (invocation checkers and verification modes), Invocation (invocation matcher, call stack analysis, printing), and Helpers (chain-of-responsibility for argument getters and return value setters). The primary entry point is the OCMockito.h header, which exposes macros like mock(), given(), verify(), etc. Dependencies include OCHamcrest for matchers and failure reporting, and XCTest for test integration. The codebase demonstrates solid software engineering with extensive unit tests (XCTest), though there are minor maintenance concerns such as duplicated public headers, hardcoded paths in examples, and reliance on global singleton swizzling state that may cause cross-test contamination. Overall, it is a well-maintained and widely used testing library.
The LLM identified 5 files worth highlighting for reuse:
Implements a chain-of-responsibility pattern to extract typed argument values from NSInvocation objects by @encode type. Each concrete getter (e.g., MKTIntArgumentGetter) handles a specific type and forwards unknown types to the next link. This design is extensible and could be reused in any project needing to introspect or convert method invocation arguments by type.
Mirror of the argument getter chain for setting return values on NSInvocation objects. Handles all primitive types, structs, pointers, and objects via a chain of responsibility. Demonstrates a clean, testable pattern for type-specific operations that could be extracted for other invocation manipulation libraries.
Parses the backtrace string returned by [NSThread callStackSymbols] into structured MKTCallStackElement objects. Handles both 32-bit and 64-bit address formats. This is a reusable utility for any Objective-C tool needing to analyze stack traces at runtime, applicable in debugging, profiling, or error reporting.
Filters the parsed call stack to remove noise from system frameworks (e.g., Foundation, XCTest) and OCMockito internals, keeping only user test code. This pattern is useful for any library that needs to produce concise, actionable error messages with relevant stack frames, and could be extracted with minimal modifications.
Swizzles the singleton accessor method of a class to return a mock object instead. Uses a global map to manage swizzled methods and restores original implementations on dealloc or stopMocking. This is a non-trivial pattern for mocking singletons in Objective-C, demonstrating careful use of method swizzling and memory management. Could be extracted as a standalone utility for test code.