Name: Assertions
Owner: Antitypical
Description: Flexible XCTest assertions in Swift.
Created: 2015-02-14 21:12:26.0
Updated: 2017-11-06 17:15:05.0
Pushed: 2015-12-27 16:59:16.0
Homepage: null
Size: 57
Language: Swift
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This is a Swift µframework providing simple, flexible assertions for XCTest in Swift.
Requires Swift 1.2 (Xcode 6.3)
Assert that an optional array is equal to another array:
array: [Int]? = [1, 2, 3]
rt(maybeAnArray(), ==, [1, 2, 3])
If you tried to use XCTAssertEqual
, you?d have to unwrap the optional first:
ssertEqual(array, [1, 2, 3])
> error: value of optional type '[Int]?' not unwrapped; did you mean to use '!' or '?'?
This works great with optionals of other types, too:
string: String? = "hello"
rt(string, ==, "hello")
Here, too, XCTAssertEqual
would force you to unwrap the optional:
ssertEqual(string, "hello")
> error: cannot find an overload for 'XCTAssertEqual' that accepts an argument list of type '(String?, String)'
You can also pass in methods:
set: Set<Int>? = Set([1, 2, 3])
rt(set, Set.contains, 3)
And you can use the predicate form for any other test you might want to write:
string: String? = ""
rt(string, { $0.isEmpty })
These last two are approximately equivalent to using Swift?s optional chaining, but you might find them handy.
Add this repo as a submodule in e.g. External/Assertions
:
git submodule add https://github.com/robrix/Assertions.git External/Assertions
Drag Assertions.xcodeproj
into your .xcworkspace
/.xcodeproj
.
Add Assertions.framework
to your test target?s Link Binary With Libraries
build phase.