Giter Site home page Giter Site logo

assertions's Introduction

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:

let array: [Int]? = [1, 2, 3]
assert(maybeAnArray(), ==, [1, 2, 3])

If you tried to use XCTAssertEqual, you’d have to unwrap the optional first:

XCTAssertEqual(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:

let string: String? = "hello"
assert(string, ==, "hello")

Here, too, XCTAssertEqual would force you to unwrap the optional:

XCTAssertEqual(string, "hello")
// => error: cannot find an overload for 'XCTAssertEqual' that accepts an argument list of type '(String?, String)'

You can also pass in methods:

let set: Set<Int>? = Set([1, 2, 3])
assert(set, Set.contains, 3)

And you can use the predicate form for any other test you might want to write:

let string: String? = ""
assert(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.

assertions's People

Contributors

neilpa avatar robrix avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.