Swiftpack.co - Package - kylef/Spectre

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, simply make a type that conforms to Reporter.

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:

| Project | CI | |---------|----| | Stencil | Build Status | | Inquiline | Build Status | | CardKit | Build Status |

Installation / Running

SPM

Check out spectre-build.

Conche

Conche build system has integrated support for Spectre. You can simply add a test_spec to your Conche podspec depending on Spectre and it will run your tests with conche test.

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

Manually

You can build Spectre as a Framework or a library and link against it.

For example, if you clone Spectre and run make it will build a library you can link against:

$ swiftc -I .conche/modules -L .conche/lib -lSpectre -o runner myTests.swift
$ ./runner

Github

link
Stars: 314
Help us keep the lights on

Dependencies

Used By

Total:

Releases

0.9.0 - Sep 10, 2018

Breaking

  • Using Spectre in Xcode has be re-hauled, there are now describe and it methods on XCTestCase which can be used. When used, these tests will be ran directly and reported as XCTest failures and therefore shown in Xcode and Xcode sidebar as XCTest failures.

    Use of the global test context, i.e, global describe and it is no longer permitted when using Spectre with XCTest.

Enhancements

  • Adds support for Swift 4.2.

  • Unhandled errors will now be reported from the invoked cases source map.