• Stars
    star
    402
  • Rank 103,424 (Top 3 %)
  • Language
    Swift
  • License
    BSD 2-Clause "Sim...
  • Created over 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

BDD Framework and test runner for Swift projects and playgrounds

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

More Repositories

1

swiftenv

Swift Version Manager
Shell
1,959
star
2

Commander

Compose beautiful command line interfaces in Swift
Swift
1,527
star
3

Mockingjay

An elegant library for stubbing HTTP requests with ease in Swift
Swift
1,488
star
4

PathKit

Effortless path operations in Swift
Swift
1,432
star
5

JSONWebToken.swift

Swift implementation of JSON Web Token (JWT).
Swift
764
star
6

JSONSchema.swift

JSON Schema validator in Swift
Swift
269
star
7

URITemplate.swift

Swift implementation of URI Template (RFC6570)
Swift
198
star
8

apiblueprint.vim

This vim plugin brings syntax highlighting and linting for API Blueprint.
Vim Script
113
star
9

dotfiles

kylef's dotfile
Vim Script
32
star
10

swiftenv-api

API for swiftenv to return the available versions of Swift
Python
25
star
11

draughtsman

API Blueprint Parser for Python 3
Python
22
star
12

goji

Command line JIRA client
Python
19
star
13

changelog

A formal specification for changelog files and entries
18
star
14

swiftenv-docker

This repository contains swiftenv images for Docker
Makefile
18
star
15

irctk

A Python IRC client library
Python
6
star
16

maintain

A unified interface to maintaining projects of any language.
Python
6
star
17

ucp

A simple and universal command line tool for capturing screenshots and uploading to the web.
Shell
5
star
18

redirector

Simple web server for HTTP redirecting from one domain to another.
Python
4
star
19

pygments-apiblueprint

An API Blueprint Lexer for Pygments
Python
3
star
20

refract.py

A Python library for interacting with Refract
Python
3
star
21

life

This repository is used as a personal issue tracker
2
star
22

homebrew-formulae

Ruby
1
star