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.
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"
}
}
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
- Dot Reporter (
-t
) - Tap Reporter (
--tap)
- Test Anything Protocol-compatible output
The standard reporter produces output as follows:
Using the -t
argument, you can use the dot reporter.
try expect(name) == "Kyle"
try expect(name) != "Kyle"
try expect(alive).to.beTrue()
try expect(alive).to.beFalse()
try expect(alive).to.beNil()
try expect(try write()).toThrow()
try expect(try write()).toThrow(FileError.NoPermission)
try expect(5) > 2
try expect(5) >= 2
try expect(5) < 10
try expect(5) <= 10
try expect("kyle").to.beOfType(String.self)
throw failure("Everything is broken.")
You can easily provide your own assertions, you just need to throw a failure when the assertion does not meet expectaions.
The following projects use Spectre:
Project | CI |
---|---|
Stencil | |
Inquiline | |
CardKit |
Check out spectre-build.
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
.
You can use Spectre in an Xcode Playground, open Spectre.playground
in
this repository, failures are printed in the console.
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