Permalink
Browse files

Added test coverage for LSStubRequest#matchesRequest

  • Loading branch information...
1 parent 1f4a1cf commit 8b60589193fda9ad1064102a98abe0659b8df392 @luisobo committed Sep 10, 2012
Showing with 169 additions and 0 deletions.
  1. +12 −0 Nocilla.xcodeproj/project.pbxproj
  2. +157 −0 NocillaTests/Stubs/LSStubRequestSpec.m
@@ -47,6 +47,7 @@
A0BB870115FE7C2E0090236F /* AFNetworkingStubbingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = A085B85915E30749007D33C1 /* AFNetworkingStubbingSpec.m */; };
A0BB870215FE7C320090236F /* NSURLRequestHookSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = A0055F0115EFFA8B005D6C85 /* NSURLRequestHookSpec.m */; };
A0BB870315FE7C350090236F /* LSHTTPStubURLProtocolSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = A060B22415FE680900BEAD54 /* LSHTTPStubURLProtocolSpec.m */; };
+ A0BB870615FE7D8F0090236F /* LSStubRequestSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = A0BB870515FE7D8F0090236F /* LSStubRequestSpec.m */; };
A0EE630715EC217A00009A08 /* LSHTTPRequestDiff.h in Headers */ = {isa = PBXBuildFile; fileRef = A0EE630515EC217A00009A08 /* LSHTTPRequestDiff.h */; };
A0EE630815EC217A00009A08 /* LSHTTPRequestDiff.m in Sources */ = {isa = PBXBuildFile; fileRef = A0EE630615EC217A00009A08 /* LSHTTPRequestDiff.m */; };
A0EE631515ECD8B900009A08 /* NSURLRequest+LSHTTPRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A0EE631315ECD8B900009A08 /* NSURLRequest+LSHTTPRequest.h */; };
@@ -116,6 +117,7 @@
A085B85415E30749007D33C1 /* NocillaTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "NocillaTests-Info.plist"; sourceTree = "<group>"; };
A085B85615E30749007D33C1 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
A085B85915E30749007D33C1 /* AFNetworkingStubbingSpec.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = AFNetworkingStubbingSpec.m; path = Hooks/NSURLRequest/AFNetworkingStubbingSpec.m; sourceTree = "<group>"; };
+ A0BB870515FE7D8F0090236F /* LSStubRequestSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LSStubRequestSpec.m; path = Stubs/LSStubRequestSpec.m; sourceTree = "<group>"; };
A0EE630515EC217A00009A08 /* LSHTTPRequestDiff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LSHTTPRequestDiff.h; path = Diff/LSHTTPRequestDiff.h; sourceTree = "<group>"; };
A0EE630615EC217A00009A08 /* LSHTTPRequestDiff.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LSHTTPRequestDiff.m; path = Diff/LSHTTPRequestDiff.m; sourceTree = "<group>"; };
A0EE630915ECCCBD00009A08 /* LSHTTPRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = LSHTTPRequest.h; path = Model/LSHTTPRequest.h; sourceTree = "<group>"; };
@@ -324,6 +326,7 @@
A085B85215E30749007D33C1 /* NocillaTests */ = {
isa = PBXGroup;
children = (
+ A0BB870415FE7D7E0090236F /* Stubs */,
A0055EE515EEAF73005D6C85 /* Support */,
A02C7B0D15EE66250061FCEE /* Diff */,
A02C7B0B15EE65E50061FCEE /* Hooks */,
@@ -342,6 +345,14 @@
name = "Supporting Files";
sourceTree = "<group>";
};
+ A0BB870415FE7D7E0090236F /* Stubs */ = {
+ isa = PBXGroup;
+ children = (
+ A0BB870515FE7D8F0090236F /* LSStubRequestSpec.m */,
+ );
+ name = Stubs;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
@@ -523,6 +534,7 @@
A0BB870115FE7C2E0090236F /* AFNetworkingStubbingSpec.m in Sources */,
A0BB870215FE7C320090236F /* NSURLRequestHookSpec.m in Sources */,
A0BB870315FE7C350090236F /* LSHTTPStubURLProtocolSpec.m in Sources */,
+ A0BB870615FE7D8F0090236F /* LSStubRequestSpec.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,157 @@
+#import "Kiwi.h"
+#import "LSStubRequest.h"
+
+SPEC_BEGIN(LSStubRequestSpec)
+
+describe(@"#matchesRequest:", ^{
+ context(@"when the method and the URL are equal", ^{
+ it(@"should match", ^{
+ LSStubRequest *stubRequest = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ LSStubRequest *other = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ [[theValue([stubRequest matchesRequest:other]) should] beYes];
+ [[theValue([other matchesRequest:stubRequest]) should] beYes];
+ });
+ });
+ context(@"when the method is different", ^{
+ it(@"should not match", ^{
+ LSStubRequest *stubRequest = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ LSStubRequest *other = [[LSStubRequest alloc] initWithMethod:@"GET" url:@"https://api.example.com/cats/whiskas.json"];
+
+ [[theValue([stubRequest matchesRequest:other]) should] beNo];
+ [[theValue([other matchesRequest:stubRequest]) should] beNo];
+ });
+ });
+ context(@"when the URL is different", ^{
+ it(@"should not match", ^{
+ LSStubRequest *stubRequest = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ LSStubRequest *other = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/dogs/barky.json"];
+
+ [[theValue([stubRequest matchesRequest:other]) should] beNo];
+ [[theValue([other matchesRequest:stubRequest]) should] beNo];
+ });
+ });
+
+ context(@"when the left request has a subset of header of the right request", ^{
+ __block LSStubRequest *left = nil;
+ __block LSStubRequest *right = nil;
+ beforeEach(^{
+ left = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ right = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ [left setHeader:@"Content-Type" value:@"application/json"];
+
+ [right setHeader:@"Content-Type" value:@"application/json"];
+ [right setHeader:@"X-API-TOKEN" value:@"123abc"];
+ });
+ describe(@"the left request", ^{
+ it(@"should match the right request", ^{
+ [[theValue([left matchesRequest:right]) should] beYes];
+ });
+ });
+ describe(@"the right request", ^{
+ it(@"should not match the left request", ^{
+ [[theValue([right matchesRequest:left]) should] beNo];
+ });
+ });
+ });
+ context(@"when the both requests have the same headers", ^{
+ __block LSStubRequest *left = nil;
+ __block LSStubRequest *right = nil;
+ beforeEach(^{
+ left = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ right = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ [left setHeader:@"Content-Type" value:@"application/json"];
+ [left setHeader:@"X-API-TOKEN" value:@"123abc"];
+
+ [right setHeader:@"Content-Type" value:@"application/json"];
+ [right setHeader:@"X-API-TOKEN" value:@"123abc"];
+ });
+ it(@"should match each other", ^{
+ [[theValue([left matchesRequest:right]) should] beYes];
+ [[theValue([right matchesRequest:left]) should] beYes];
+ });
+ });
+
+ context(@"when both requests have the same body", ^{
+ __block LSStubRequest *left = nil;
+ __block LSStubRequest *right = nil;
+ beforeEach(^{
+ left = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ right = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ [left setHeader:@"Content-Type" value:@"application/json"];
+ [left setHeader:@"X-API-TOKEN" value:@"123abc"];
+
+ [right setHeader:@"Content-Type" value:@"application/json"];
+ [right setHeader:@"X-API-TOKEN" value:@"123abc"];
+
+ [left setBody:[@"Hola, this is a body" dataUsingEncoding:NSUTF8StringEncoding]];
+ [right setBody:[@"Hola, this is a body" dataUsingEncoding:NSUTF8StringEncoding]];
+ });
+ it(@"should match each other", ^{
+ [[theValue([left matchesRequest:right]) should] beYes];
+ [[theValue([right matchesRequest:left]) should] beYes];
+ });
+ });
+
+ context(@"when both requests have different bodies", ^{
+ __block LSStubRequest *left = nil;
+ __block LSStubRequest *right = nil;
+ beforeEach(^{
+ left = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ right = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ [left setHeader:@"Content-Type" value:@"application/json"];
+ [left setHeader:@"X-API-TOKEN" value:@"123abc"];
+
+ [right setHeader:@"Content-Type" value:@"application/json"];
+ [right setHeader:@"X-API-TOKEN" value:@"123abc"];
+
+ [left setBody:[@"Hola, this is a body" dataUsingEncoding:NSUTF8StringEncoding]];
+ [right setBody:[@"Adios, this is a body as well" dataUsingEncoding:NSUTF8StringEncoding]];
+ });
+ it(@"should match each other", ^{
+ [[theValue([left matchesRequest:right]) should] beNo];
+ [[theValue([right matchesRequest:left]) should] beNo];
+ });
+ });
+
+ context(@"when the left request has a nil body", ^{
+ __block LSStubRequest *left = nil;
+ __block LSStubRequest *right = nil;
+ beforeEach(^{
+ left = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ right = [[LSStubRequest alloc] initWithMethod:@"PUT" url:@"https://api.example.com/cats/whiskas.json"];
+
+ [left setHeader:@"Content-Type" value:@"application/json"];
+ [left setHeader:@"X-API-TOKEN" value:@"123abc"];
+
+ [right setHeader:@"Content-Type" value:@"application/json"];
+ [right setHeader:@"X-API-TOKEN" value:@"123abc"];
+
+ [right setBody:[@"Adios, this is a body as well" dataUsingEncoding:NSUTF8StringEncoding]];
+ });
+ describe(@"the left request", ^{
+ it(@"should match the right request", ^{
+ [[theValue([left matchesRequest:right]) should] beYes];
+ });
+ });
+ describe(@"the right request", ^{
+ it(@"should not match the left request", ^{
+ [[theValue([right matchesRequest:left]) should] beNo];
+ });
+ });
+ });
+});
+
+SPEC_END

0 comments on commit 8b60589

Please sign in to comment.