Skip to content

Commit

Permalink
Added tests to verify the selectors present for a given QuickSpec class
Browse files Browse the repository at this point in the history
  • Loading branch information
abbeycode committed Jan 25, 2016
1 parent 7e129ca commit cd368ba
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Quick.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@
8D010A571C11726F00633E2B /* DescribeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D010A561C11726F00633E2B /* DescribeTests.swift */; };
8D010A581C11726F00633E2B /* DescribeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D010A561C11726F00633E2B /* DescribeTests.swift */; };
8D010A591C11726F00633E2B /* DescribeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D010A561C11726F00633E2B /* DescribeTests.swift */; };
96327C631C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.h in Headers */ = {isa = PBXBuildFile; fileRef = 96327C611C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.h */; };
96327C641C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.h in Headers */ = {isa = PBXBuildFile; fileRef = 96327C611C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.h */; };
96327C651C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.h in Headers */ = {isa = PBXBuildFile; fileRef = 96327C611C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.h */; };
96327C661C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.m in Sources */ = {isa = PBXBuildFile; fileRef = 96327C621C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.m */; };
96327C671C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.m in Sources */ = {isa = PBXBuildFile; fileRef = 96327C621C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.m */; };
96327C681C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.m in Sources */ = {isa = PBXBuildFile; fileRef = 96327C621C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.m */; };
DA02C91919A8073100093156 /* ExampleMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA02C91819A8073100093156 /* ExampleMetadata.swift */; };
DA02C91A19A8073100093156 /* ExampleMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA02C91819A8073100093156 /* ExampleMetadata.swift */; };
DA05D61019F73A3800771050 /* AfterEachTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA05D60F19F73A3800771050 /* AfterEachTests.swift */; };
Expand Down Expand Up @@ -412,6 +418,8 @@
5A5D117C19473F2100F6D13D /* Quick.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Quick.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5A5D118619473F2100F6D13D /* Quick-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Quick-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
8D010A561C11726F00633E2B /* DescribeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DescribeTests.swift; sourceTree = "<group>"; };
96327C611C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "QuickSpec+QuickSpec_MethodList.h"; sourceTree = "<group>"; };
96327C621C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "QuickSpec+QuickSpec_MethodList.m"; sourceTree = "<group>"; };
DA02C91819A8073100093156 /* ExampleMetadata.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleMetadata.swift; sourceTree = "<group>"; };
DA05D60F19F73A3800771050 /* AfterEachTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AfterEachTests.swift; sourceTree = "<group>"; };
DA169E4719FF5DF100619816 /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -587,6 +595,8 @@
DA8F919619F31680006F6675 /* QCKSpecRunner.m */,
34ACFB7B1C34859300942064 /* XCTestCaseProvider.swift */,
DA8F919819F31680006F6675 /* XCTestObservationCenter+QCKSuspendObservation.h */,
96327C611C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.h */,
96327C621C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.m */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -773,6 +783,7 @@
files = (
1F118D2B1BDCA5B6005013A2 /* Quick.h in Headers */,
1F118D261BDCA5AF005013A2 /* World+DSL.h in Headers */,
96327C651C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.h in Headers */,
1F118D271BDCA5AF005013A2 /* World.h in Headers */,
1F118D2A1BDCA5B6005013A2 /* QCKDSL.h in Headers */,
1F118D2C1BDCA5B6005013A2 /* QuickSpec.h in Headers */,
Expand All @@ -787,6 +798,7 @@
files = (
34F375B019515CA700CE1B99 /* NSString+QCKSelectorName.h in Headers */,
DAE714FF19FF6A62005905B8 /* QuickConfiguration.h in Headers */,
96327C641C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.h in Headers */,
DA3124E919FCAEE8002858A7 /* QCKDSL.h in Headers */,
DAED1ECB1B110699006F61EC /* World+DSL.h in Headers */,
DAED1EC51B1105BC006F61EC /* World.h in Headers */,
Expand All @@ -801,6 +813,7 @@
files = (
34F375AF19515CA700CE1B99 /* NSString+QCKSelectorName.h in Headers */,
DAE714FE19FF6A62005905B8 /* QuickConfiguration.h in Headers */,
96327C631C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.h in Headers */,
DA3124E819FCAEE8002858A7 /* QCKDSL.h in Headers */,
DAED1ECA1B110699006F61EC /* World+DSL.h in Headers */,
DAED1EC41B1105BC006F61EC /* World.h in Headers */,
Expand Down Expand Up @@ -1133,6 +1146,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
96327C681C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.m in Sources */,
1F118D031BDCA536005013A2 /* World.swift in Sources */,
1F118CFC1BDCA536005013A2 /* Configuration.swift in Sources */,
1F118D021BDCA536005013A2 /* SuiteHooks.swift in Sources */,
Expand Down Expand Up @@ -1202,6 +1216,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
96327C671C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.m in Sources */,
34F375B219515CA700CE1B99 /* NSString+QCKSelectorName.m in Sources */,
DA3124EB19FCAEE8002858A7 /* QCKDSL.m in Sources */,
DA408BE319FF5599005DF92A /* Closures.swift in Sources */,
Expand Down Expand Up @@ -1282,6 +1297,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
96327C661C56E90C00405AB3 /* QuickSpec+QuickSpec_MethodList.m in Sources */,
34F375B119515CA700CE1B99 /* NSString+QCKSelectorName.m in Sources */,
DA3124EA19FCAEE8002858A7 /* QCKDSL.m in Sources */,
DA408BE219FF5599005DF92A /* Closures.swift in Sources */,
Expand Down
10 changes: 9 additions & 1 deletion Sources/QuickTests/FunctionalTests/ItTests+ObjC.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import <Nimble/Nimble.h>

#import "QCKSpecRunner.h"
#import "QuickSpec+QuickSpec_MethodList.h"

QuickSpecBegin(FunctionalTests_ItSpec_ObjC)

Expand All @@ -20,6 +21,13 @@
expect(exampleMetadata.example.name).to(equal(name));
});

it(@"is a test with a unique name", ^{
NSSet<NSString*> *allSelectors = [FunctionalTests_ItSpec_ObjC allSelectors];

expect(allSelectors).to(contain(@"is_a_test_with_a_unique_name"));
expect(allSelectors).toNot(contain(@"is_a_test_with_a_unique_name_2"));
});

QuickSpecEnd

@interface ItTests_ObjC : XCTestCase; @end
Expand All @@ -28,7 +36,7 @@ @implementation ItTests_ObjC

- (void)testAllExamplesAreExecuted {
XCTestRun *result = qck_runSpec([FunctionalTests_ItSpec_ObjC class]);
XCTAssertEqual(result.executionCount, 2);
XCTAssertEqual(result.executionCount, 3);
}

@end
9 changes: 8 additions & 1 deletion Sources/QuickTests/FunctionalTests/ItTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class FunctionalTests_ItSpec: QuickSpec {
let name = "has a description with セレクター名に使えない文字が入っている 👊💥"
expect(exampleMetadata!.example.name).to(equal(name))
}

it("is a test with a unique name") {
let allSelectors: Set<String> = FunctionalTests_ItSpec.allSelectors();

expect(allSelectors).to(contain("is_a_test_with_a_unique_name"));
expect(allSelectors).toNot(contain("is_a_test_with_a_unique_name_2"));
}
}
}

Expand All @@ -30,6 +37,6 @@ class ItTests: XCTestCase, XCTestCaseProvider {

func testAllExamplesAreExecuted() {
let result = qck_runSpec(FunctionalTests_ItSpec.self)
XCTAssertEqual(result.executionCount, 2 as UInt)
XCTAssertEqual(result.executionCount, 3 as UInt)
}
}
7 changes: 7 additions & 0 deletions Sources/QuickTests/Helpers/QuickSpec+QuickSpec_MethodList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import <Quick/Quick.h>

@interface QuickSpec (QuickSpec_MethodList)

+ (NSSet<NSString*> *)allSelectors;

@end
23 changes: 23 additions & 0 deletions Sources/QuickTests/Helpers/QuickSpec+QuickSpec_MethodList.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#import "QuickSpec+QuickSpec_MethodList.h"
#import <objc/runtime.h>


@implementation QuickSpec (QuickSpec_MethodList)

+ (NSSet<NSString*> *)allSelectors {
id t = [[[self class] alloc] init];
NSMutableSet<NSString*> *allSelectors = [NSMutableSet set];

unsigned int methodCount = 0;
Method * mlist = class_copyMethodList(object_getClass(t), &methodCount);
NSLog(@"%d methods", methodCount);
for(int i = 0; i<methodCount; i++) {
SEL selector = method_getName(mlist[i]);
NSLog(@"Method no #%d: %s", i, sel_getName(selector));
[allSelectors addObject:NSStringFromSelector(selector)];
}

return [allSelectors copy];
}

@end
1 change: 1 addition & 0 deletions Sources/QuickTests/Helpers/QuickTestsBridgingHeader.h
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#import "QCKSpecRunner.h"
#import "QuickSpec+QuickSpec_MethodList.h"

0 comments on commit cd368ba

Please sign in to comment.