Coder Social home page Coder Social logo

guanaco's Introduction

Guanaco

Build Status

Nimble matchers for LlamaKit.

let result: Result<String, NSError> = success("llama")
expect(result).to(haveSucceeded())
expect(result).to(haveSucceeded(equal("llama")))
let error = NSError(domain: "guanaco", code: 10, userInfo: [NSLocalizedDescriptionKey: "lama guanicoe"])
let result: Result<String, NSError> = failure(error)
expect(result).to(haveFailed())
expect(result).to(haveFailed(beAnError(
  domain: equal("guanaco"),
  code: beGreaterThan(0),
  localizedDescription: match("guanicoe")
)))

Why Use Guanaco: Testing Algebraic Data Types

Swift makes it easy to define ADTs, or "algebraic data types". The canonical example of an algebraic data type is LlamaKit's Result<ValueType, ErrorType> enum, which represents the result of some operation. When the operation is successful, the Result provides a value of type ValueType. When it is not, it provides a value of type ErrorType:

switch result {
 case .Success(let value): /* ... */
 case .Failure(let error): /* ... */
}

Unfortunately, testing algebraic data types like Result can be a pain. For example, if you had a result of type Result<Int, NSError>, and wanted to test that it had a successful value of 10, you'd have to write:

switch result {
 case .Success(let value): XCTAssertEquals(value, 10)
 case .Failure(let error): XCTFail()
}

Tests should be clear, consise, and provide useful failure messages--in other words, the code above isn't going to cut it! Instead, use Guanaco to write:

expect(result).to(haveSucceeded(equal(10)))

How to Install

CocoaPods

# Podfile

pod 'Guanaco', :git => 'https://github.com/modocache/Guanaco.git'
pod 'LlamaKit', :git => 'https://github.com/LlamaKit/LlamaKit.git',
                :tag => 'v0.5.0'

Git Submodules

First, add Guanaco as a Git submodule. From within your Git repository, open the command line and run:

$ git submodule add \
    https://github.com/modocache/Guanaco.git \
    External/Guanaco # Specify any path you like here

Open the .xcworkspace for your project and add Guanaco.xcodeproj to your workspace. Then, add Guanaco-OSX.framework or Guanaco-iOS.framework to your test target's "Link Binary with Libraries" build phase.

guanaco's People

Contributors

modocache avatar

Watchers

 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.