Coder Social home page Coder Social logo

spectre's Introduction

Spectre

Build Status

Special Executive for Command-line Test Running and Execution.

A behavior-driven development (BDD) framework and test runner for Swift projects and playgrounds. It's compatible with both OS X and Linux.

Usage

describe("a person") {
  let person = Person(name: "Kyle")

  $0.it("has a name") {
    try expect(person.name) == "Kyle"
  }

  $0.it("returns the name as description") {
    try expect(person.description) == "Kyle"
  }
}

Reporters

Spectre currently has two built-in reporters, Standard and the Dot reporter. Custom reporters are supported, make a type that conforms to Reporter.

The default reporter can be configured via an environment variable. For example:

$ env SPECTRE_REPORTER=dot swift test
$ env SPECTRE_REPORTER=tap swift test

Standard

The standard reporter produces output as follows:

Passing Tests

Standard Reporter Success

Failing Tests

Standard Reporter Failure

Dot

Using the -t argument, you can use the dot reporter.

Passing Tests

Dot Reporter Success

Failing Tests

Dot Reporter Failure

Expectation

Equivalence

try expect(name) == "Kyle"
try expect(name) != "Kyle"

Truthiness

try expect(alive).to.beTrue()
try expect(alive).to.beFalse()
try expect(alive).to.beNil()

Error handling

try expect(try write()).toThrow()
try expect(try write()).toThrow(FileError.NoPermission)

Comparable

try expect(5) > 2
try expect(5) >= 2
try expect(5) < 10
try expect(5) <= 10

Types

try expect("kyle").to.beOfType(String.self)

Causing a failure

throw failure("Everything is broken.")

Custom assertions

You can easily provide your own assertions, you just need to throw a failure when the assertion does not meet expectaions.

Examples

The following projects use Spectre:

Installation / Running

Swift Package Manager

Check out Commander as an example.

Playground

You can use Spectre in an Xcode Playground, open Spectre.playground in this repository, failures are printed in the console.

Spectre in an Xcode Playground

spectre's People

Contributors

christopherweems avatar elliottwilliams avatar hemet avatar iresslercmm avatar kattrali avatar keith avatar kerrmarin-lvmh avatar kylef avatar nrebhun avatar rbukovansky avatar readmecritic avatar stephencelis avatar stupergenius avatar tanner0101 avatar xavi-matos 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.