antitypical/Assertions

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Assertions

This is a Swift µframework providing simple, flexible assertions for XCTest in Swift.

Requires Swift 1.2 (Xcode 6.3)

Use

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.

Integration
  1. Add this repo as a submodule in e.g. External/Assertions:

    git submodule add https://github.com/robrix/Assertions.git External/Assertions
    
  2. Drag Assertions.xcodeproj into your .xcworkspace/.xcodeproj.

  3. Add Assertions.framework to your test target?s Link Binary With Libraries build phase.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.