mirror of
https://github.com/zhigang1992/FunctionalReactivePixels.git
synced 2026-01-12 22:47:31 +08:00
Add tests for PhotoImporter
- Stub the network requests. - Capture arguments.
This commit is contained in:
@@ -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 = "<group>"; };
|
||||
5E59510F180E065F002F44FA /* FRPFullSizePhotoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPFullSizePhotoViewController.h; sourceTree = "<group>"; };
|
||||
5E595110180E065F002F44FA /* FRPFullSizePhotoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPFullSizePhotoViewController.m; sourceTree = "<group>"; };
|
||||
5E595115180E0C33002F44FA /* FRPPhotoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPPhotoViewController.h; sourceTree = "<group>"; };
|
||||
@@ -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 */,
|
||||
);
|
||||
|
||||
59
FRPTests/FRPPhotoImporterTests.m
Normal file
59
FRPTests/FRPPhotoImporterTests.m
Normal file
@@ -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 <Expecta/Expecta.h>
|
||||
#import <OCMock/OCMock.h>
|
||||
|
||||
#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
|
||||
Reference in New Issue
Block a user