Skip to content

Commit

Permalink
QuickSpec: support assertions in Objective-C specs
Browse files Browse the repository at this point in the history
Because exampleGroups() was defined as a class method, XCTest assetion
macros were unavailable in Objective-C specs (since they expand to
include a reference to `self`, which must be an instance of `XCTestCase`).
Redefine exampleGroups() as an instance method.
  • Loading branch information
modocache committed Jun 11, 2014
1 parent 748484a commit a7fc644
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Examples/Scenester/ScenesterTests/Commit+ErrorSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Scenester
import Quick

class Commit_ErrorSpec: QuickSpec {
override class func exampleGroups() {
override func exampleGroups() {
describe("commitError") {
var code: CommitErrorCode!

Expand All @@ -21,15 +21,15 @@ class Commit_ErrorSpec: QuickSpec {
expect(error.localizedDescription).to.equal("The repo does not have any commits.")
}
}

context("for a code of .InvalidCommit") {
beforeEach { code = CommitErrorCode.InvalidCommit }
it("returns an error") {
let error = Commit.commitError(code)
expect(error.localizedDescription).to.equal("The commit JSON is invalid.")
}
}

context("for a code of .InvalidResponse") {
beforeEach { code = CommitErrorCode.InvalidResponse }
it("returns an error") {
Expand Down
2 changes: 1 addition & 1 deletion Examples/Scenester/ScenesterTests/Commit+NetworkSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Scenester
import Quick

class Commit_NetworkSpec: QuickSpec {
override class func exampleGroups() {
override func exampleGroups() {
describe("latestCommit") {
context("when the request succeeds") {
it("calls the success block with the latest commit") {
Expand Down
4 changes: 2 additions & 2 deletions Examples/Scenester/ScenesterTests/CommitSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import Scenester
import Quick

class CommitSpec: QuickSpec {
override class func exampleGroups() {
override func exampleGroups() {
describe("Commit") {
var commit: Commit!
beforeEach { commit = Commit(message: "debt repaid", author: "jaime-lannister") }

describe("simpleDescription") {
it("returns author: 'commit message'") {
expect(commit.simpleDescription).to.equal("jaime-lannister: 'debt repaid'")
Expand Down
2 changes: 1 addition & 1 deletion Quick/Core/QCKDSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define QuickSpecBegin(name) \
@interface name : QuickSpec; @end \
@implementation name \
+ (void)exampleGroups { \
- (void)exampleGroups { \


#define QuickSpecEnd \
Expand Down
2 changes: 1 addition & 1 deletion Quick/Core/QuickSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
See DSL.swift for more information on what syntax is available.
*/
+ (void)exampleGroups;
- (void)exampleGroups;

@end
5 changes: 3 additions & 2 deletions Quick/Core/QuickSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ @implementation QuickSpec
*/
+ (void)initialize {
[World setCurrentExampleGroup:[World rootExampleGroupForSpecClass:[self class]]];
[self exampleGroups];
QuickSpec *spec = [self new];
[spec exampleGroups];
}

/**
Expand Down Expand Up @@ -76,7 +77,7 @@ - (NSString *)name {

#pragma mark - Public Interface

+ (void)exampleGroups { }
- (void)exampleGroups { }

#pragma mark - Internal Methods

Expand Down
2 changes: 1 addition & 1 deletion QuickTests/FunctionalTests+ObjC.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

qck_describe(@"a describe block", ^{
qck_it(@"contains an it block", ^{
// ...
XCTAssertTrue(true, @"expected to be true");
});
});

Expand Down
4 changes: 2 additions & 2 deletions QuickTests/FunctionalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Quick

class PersonSpec: QuickSpec {
override class func exampleGroups() {
override func exampleGroups() {
describe("Person") {
var person: Person?
beforeEach { person = Person() }
Expand Down Expand Up @@ -54,7 +54,7 @@ class PersonSpec: QuickSpec {
}

class PoetSpec: QuickSpec {
override class func exampleGroups() {
override func exampleGroups() {
describe("Poet") {
// FIXME: Radar worthy? `var poet: Poet?` results in build error:
// "Could not find member 'greeting'"
Expand Down
2 changes: 1 addition & 1 deletion QuickTests/Matchers/BeNilSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Quick

class BeNilSpec : QuickSpec {
override class func exampleGroups() {
override func exampleGroups() {
describe("BeNil") {
var matcher: BeNil!
beforeEach { matcher = BeNil() }
Expand Down
2 changes: 1 addition & 1 deletion QuickTests/Matchers/BeTrueSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Quick

class BeTrueSpec: QuickSpec {
override class func exampleGroups() {
override func exampleGroups() {
describe("BeTrue") {
var matcher: BeTrue?
beforeEach { matcher = BeTrue() }
Expand Down
2 changes: 1 addition & 1 deletion QuickTests/Matchers/ContainSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Quick

class ContainSpec: QuickSpec {
override class func exampleGroups() {
override func exampleGroups() {
describe("Contain") {
var matcher: Contain?
var subject: String[]?
Expand Down
2 changes: 1 addition & 1 deletion QuickTests/Matchers/EqualSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Quick

class EqualSpec: QuickSpec {
override class func exampleGroups() {
override func exampleGroups() {
describe("Equal") {
var matcher: Equal?
beforeEach { matcher = Equal("Sandor Clegane") }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and [Ginkgo](https://github.com/onsi/ginkgo).
import Quick

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

0 comments on commit a7fc644

Please sign in to comment.