A behavior-driven development framework for Swift. Inspired by RSpec, Specta, and Ginkgo.
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.")
}
}
}
}
}
}
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()
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:
- Clone the repository
- Add
Quick.xcodeproj
to your test target - Link
Quick.framework
during your test target'sLink Binary with Libraries
build phase - Start writing specs!
An example project with this complete setup is available in the
Examples
directory.
git clone [email protected]:modocache/Quick.git
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.
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.
If you run into any problems, please file an issue.
MIT license. See the LICENSE
file for details.