Nimble v5.1.0
This release includes new features and shouldn't break backwards compatibility
with 5.0.0. Thus, 5.1.0 supports Swift 3 / Xcode 8. The TL;DR list of changes:
New Features:
- Add
throwAssertion
matcher to test precondition failures. Thanks @mattgallagher and @abbeycode! - Objective-C supports some C literals
Fixes:
- The regular expression
match
matcher is available for Linux. Thanks @ikesyo! - Document about
AsyncDefaults
. Thanks @wongzigii! - Fix
matchError
incorrectly succeeding on any Error type given.
New Feature Details
ThrowAssertion Matcher
Nimble now includes a throwAssertion
matcher to test if a given piece of code
fails precondition
or invokes fatalError
.
// swift
expect { precondition(false, "this will fail") }.to(throwAssertion())
// type-hint that this closure does not return anything
expect { () -> Void in fatalError() }.to(throwAssertion())
Due to the inherit implementation of preconditions and fatalErrors, there are
several limitations:
- This is only available for Swift.
- There is no validation of the failure message.
- This only works for x86 architectures. This means Simulators + macOS only.
- tvOS simulator requires you to disable "Debug executable" in your scheme's test configuration.
Nimble embeds CwlPreconditionTesting to implement throwAssertion
. Special
thanks to @mattgallagher for CwlPreconditionTesting and @abbeycode for the bulk
of the adding the matcher for Nimble.
Go test those assertions!
Objective-C: Limited C-Literals Support
Objective-C version of Nimble now can automatically box certain C types for
you. This means you don't need to wrap them yourself:
// objective-c
expect(1).to(equal(2));
expect(98.6).to(beCloseTo(98.6));
expect(YES).to(beTrue());
expect(@[@1, @2]).to(haveCount(2));
expect("hello").toNot(equal("world"));
expect(NSMakeRange(0, 5)).to(equal(NSMakeRange(0, 5)));
Currently, not all matchers support all types. The following matchers support C types:
equal
beGreaterThan
beGreaterThanOrEqual
beLessThan
beLessThanOrEqual
beCloseTo
beTrue
beFalse
beTruthy
beFalsy
haveCount
The C types each supports is matcher specific. But there's here's the basic heuristics:
- C numeric types are boxed as
NSNumber *
. (eg -uint64_t -> NSNumber *
) - C booleans are boxed as
NSNumber *
. (eg -BOOL -> NSNumber *
) - C strings are boxed as
NSString *
(eg -char * -> NSString *
) NSRange
are boxed asNSValue *
(eg -NSRange -> NSValue *
)
While they shouldn't cause too many suprises in practice, note that you still
can have some gotchas with everything boxing as NSNumber *
(eg -
expect(1).to(beTrue())
passes).
Please file an issue if you want more matchers.
Happy testing! 😁