Skip to content
forked from Quick/Quick

A behavior-driven development test framework for Swift.

License

Notifications You must be signed in to change notification settings

zenkimoto/Quick

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quick

A behavior-driven development framework for Swift. Inspired by RSpec, Specta, and Ginkgo.

Syntax

import Quick

class PersonSpec: QuickSpec {
    override class func exampleGroups() {
        describe("Person") {
            var person: Person?
            beforeEach { person = Person() }

            it("is happy but never satisfied") {
                expect(person!.isHappy).to.beTrue()
                expect{person!.isSatisfied}.willNot.beTrue()
            }

            describe("greeting") {
                context("when the person is unhappy") {
                    beforeEach { person!.isHappy = false }
                    it("is lukewarm") {
                        expect(person!.greeting).to.equal("Oh, hi.")
                        expect(person!.greeting).notTo.equal("Hello!")
                    }
                }

                context("when the person is happy") {
                    beforeEach { person!.isHappy = true }
                    it("is enthusiastic") {
                        expect(person!.greeting).to.equal("Hello!")
                        expect(person!.greeting).notTo.equal("Oh, hi.")
                    }
                }
            }
        }
    }
}

Expectations

Quick expectations use the expect(...).to syntax:

expect(person!.greeting).to.equal("Oh, hi.")
expect(person!.greeting).notTo.equal("Hello!")

Quick includes matchers that test whether the subject of an expectation is true, or equal to something, or whether it contains a specific element:

expect(person!.isHappy).to.beTrue()
expect(person!.greeting).to.equal("Hello!")
expect(person!.hopes).to.contain("winning the lottery")

When passing an optional to an expectation there is no need to unwrap the variable using a trailing !: Quick will do that for you.

var optVal: Int?

expect(optVal).to.beNil()

optVal = 123

expect(optVal).toNot.beNil()
expect(optVal).to.equal(123)

Quick also allows for asynchronous expectations, by wrapping the subject in braces instead of parentheses. This allows the subject to be evaluated as a closure. Below is an example of a subject who knows only hunger, and never satisfaction:

expect{person!.isHungry}.will.beTrue()
expect{person!.isSatisfied}.willNot.beTrue()

Asynchronous expectations time out after one second by default. You can extend this by using willBefore. The following times out after 3 seconds:

expect{person!.isHungry}.willBefore(3).beTrue()
expect{person!.isSatisfied}.willNotBefore(3).beTrue()

Installation

This module is beta software, and can only run using the latest, beta version of Xcode.

To use Quick to test your iOS or OS X applications, follow these 4 easy steps:

  1. Clone the repository
  2. Add Quick.xcodeproj to your test target
  3. Link Quick.framework during your test target's Link Binary with Libraries build phase
  4. Start writing specs!

An example project with this complete setup is available in the Examples directory.

1. Clone this repository

git clone git@github.com:modocache/Quick.git

2. Add the Quick.xcodeproj file to your application's test target

Right-click on the group containing your application's tests and select Add Files To YourApp....

Next, select Quick.xcodeproj, which you downloaded in step 1.

Once you've added the Quick project, you should see it in Xcode's project navigator, grouped with your tests.

3. Link the Quick.framework

Finally, link the Quick.framework during your test target's Link Binary with Libraries build phase. You should see two Quick.frameworks; one is for OS X, and the other is for iOS.

4. Start writing specs!

If you run into any problems, please file an issue.

License

MIT license. See the LICENSE file for details.

About

A behavior-driven development test framework for Swift.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published