From 8d552ed5854cd16996287b3280b88fcb941925c9 Mon Sep 17 00:00:00 2001 From: Phat Le Date: Mon, 24 Feb 2014 17:39:15 +0700 Subject: [PATCH] Add tests for PhotoImporter - Stub the network requests. - Capture arguments. --- FRP.xcodeproj/project.pbxproj | 4 +++ FRPTests/FRPPhotoImporterTests.m | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 FRPTests/FRPPhotoImporterTests.m diff --git a/FRP.xcodeproj/project.pbxproj b/FRP.xcodeproj/project.pbxproj index cb13609..7c95a15 100644 --- a/FRP.xcodeproj/project.pbxproj +++ b/FRP.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 17E5A10E18BB43C600AFC028 /* FRPPhotoImporterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 17E5A10D18BB43C600AFC028 /* FRPPhotoImporterTests.m */; }; 2826EB375D254DDD8DE6EAA8 /* libPods-FRP.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 772BE9E4C5824F1C8E5CDC45 /* libPods-FRP.a */; }; 5E595111180E065F002F44FA /* FRPFullSizePhotoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */; }; 5E595117180E0C33002F44FA /* FRPPhotoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E595116180E0C33002F44FA /* FRPPhotoViewController.m */; }; @@ -50,6 +51,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 17E5A10D18BB43C600AFC028 /* FRPPhotoImporterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPPhotoImporterTests.m; sourceTree = ""; }; 5E59510F180E065F002F44FA /* FRPFullSizePhotoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPFullSizePhotoViewController.h; sourceTree = ""; }; 5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPFullSizePhotoViewController.m; sourceTree = ""; }; 5E595115180E0C33002F44FA /* FRPPhotoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPPhotoViewController.h; sourceTree = ""; }; @@ -282,6 +284,7 @@ 5EBE2B19180B07D0007B6BF3 /* FRPTests */ = { isa = PBXGroup; children = ( + 17E5A10D18BB43C600AFC028 /* FRPPhotoImporterTests.m */, 5E730B0F1815F78B003FCB43 /* FRPGalleryViewModelTests.m */, 5E93AD99186C781000795C9E /* FRPFullSizePhotoViewModelTests.m */, 5E93AD9B186C80DE00795C9E /* FRPPhotoViewModelTests.m */, @@ -485,6 +488,7 @@ buildActionMask = 2147483647; files = ( 5E93AD9A186C781000795C9E /* FRPFullSizePhotoViewModelTests.m in Sources */, + 17E5A10E18BB43C600AFC028 /* FRPPhotoImporterTests.m in Sources */, 5E730B101815F78B003FCB43 /* FRPGalleryViewModelTests.m in Sources */, 5E93AD9C186C80DE00795C9E /* FRPPhotoViewModelTests.m in Sources */, ); diff --git a/FRPTests/FRPPhotoImporterTests.m b/FRPTests/FRPPhotoImporterTests.m new file mode 100644 index 0000000..5d86ad8 --- /dev/null +++ b/FRPTests/FRPPhotoImporterTests.m @@ -0,0 +1,59 @@ +// +// FRPPhotoImporterTests.m +// FRP +// +// Created by Phat, Le Tan on 2/24/14. +// Copyright (c) 2014 Ash Furrow. All rights reserved. +// + +#import "Specta.h" +#define EXP_SHORTHAND +#import +#import + +#import "FRPPhotoImporter.h" + +SpecBegin(FRPPhotoImporter) + +describe(@"FRPPhotoImporter", ^{ + __block id mock; + beforeEach(^{ + mock = [OCMockObject mockForClass:[PXRequest class]]; + }); + + it(@"logins successfully", ^{ + __block id success = @0; + void (^theBlock)(NSInvocation *) = ^(NSInvocation *invocation) { + void (^passedBlock)( BOOL ); + [invocation getArgument:&passedBlock atIndex:4]; + passedBlock(YES); + }; + [[[mock stub] andDo:theBlock] authenticateWithUserName:[OCMArg any] password:[OCMArg any] completion:[OCMArg any]]; + + [[FRPPhotoImporter logInWithUsername:@"username" password:@"password"] subscribeCompleted:^{ + success = @1; + }]; + expect(success).to.equal(@1); + }); + + it(@"returns error when login unsuccessfully", ^{ + __block id expected_error; + void (^theBlock)(NSInvocation *) = ^(NSInvocation *invocation) { + void (^passedBlock)( BOOL ); + [invocation getArgument:&passedBlock atIndex:4]; + passedBlock(NO); + }; + [[[mock stub] andDo:theBlock] authenticateWithUserName:[OCMArg any] password:[OCMArg any] completion:[OCMArg any]]; + + [[FRPPhotoImporter logInWithUsername:@"username" password:@"password"] subscribeError:^(NSError *error) { + expected_error = error; + }]; + expect([expected_error domain]).to.equal(@"500px API"); + }); + + afterEach(^{ + mock = nil; + }); +}); + +SpecEnd \ No newline at end of file