From c932b6b3785ca5ccc139c7ac69c01856f45c0248 Mon Sep 17 00:00:00 2001 From: Phat Le Date: Mon, 24 Feb 2014 14:41:47 +0700 Subject: [PATCH 1/2] Remove duplicated symbols when ran the tests. --- Podfile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Podfile b/Podfile index f078f26..19f089b 100644 --- a/Podfile +++ b/Podfile @@ -11,14 +11,9 @@ pod 'AFImageDownloader', '1.0.0' end target "FRPTests" do - -pod 'ReactiveCocoa', '2.1.4' -pod 'ReactiveViewModel', '0.1.1' -pod 'libextobjc', '0.3' -pod '500px-iOS-api', '1.0.5' + pod 'Specta', '~> 0.2.1' pod 'Expecta', '~> 0.2' pod 'OCMock', '~> 2.2.2' -pod 'AFImageDownloader', '1.0.0' end From ab90c72d9ed13285f759663adbf51b5dbb89451a Mon Sep 17 00:00:00 2001 From: Phat Le Date: Mon, 24 Feb 2014 15:05:13 +0700 Subject: [PATCH 2/2] Add LoginViewModel test --- FRP.xcodeproj/project.pbxproj | 4 ++ FRP/FRPLoginViewModel.m | 12 ++++-- FRPTests/FRPLoginViewModelTests.m | 66 +++++++++++++++++++++++++++++++ FRPTests/FRPPhotoImporterTests.m | 9 +++++ 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 FRPTests/FRPLoginViewModelTests.m create mode 100644 FRPTests/FRPPhotoImporterTests.m diff --git a/FRP.xcodeproj/project.pbxproj b/FRP.xcodeproj/project.pbxproj index cb13609..02aff5d 100644 --- a/FRP.xcodeproj/project.pbxproj +++ b/FRP.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 17A5BBDB18BB2F6D000E2D24 /* FRPLoginViewModelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 17A5BBDA18BB2F6D000E2D24 /* FRPLoginViewModelTests.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 */ + 17A5BBDA18BB2F6D000E2D24 /* FRPLoginViewModelTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPLoginViewModelTests.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 = ( + 17A5BBDA18BB2F6D000E2D24 /* FRPLoginViewModelTests.m */, 5E730B0F1815F78B003FCB43 /* FRPGalleryViewModelTests.m */, 5E93AD99186C781000795C9E /* FRPFullSizePhotoViewModelTests.m */, 5E93AD9B186C80DE00795C9E /* FRPPhotoViewModelTests.m */, @@ -487,6 +490,7 @@ 5E93AD9A186C781000795C9E /* FRPFullSizePhotoViewModelTests.m in Sources */, 5E730B101815F78B003FCB43 /* FRPGalleryViewModelTests.m in Sources */, 5E93AD9C186C80DE00795C9E /* FRPPhotoViewModelTests.m in Sources */, + 17A5BBDB18BB2F6D000E2D24 /* FRPLoginViewModelTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FRP/FRPLoginViewModel.m b/FRP/FRPLoginViewModel.m index 6ba97de..e4ea5e6 100644 --- a/FRP/FRPLoginViewModel.m +++ b/FRP/FRPLoginViewModel.m @@ -22,9 +22,8 @@ if (!self) return nil; @weakify(self); - self.loginCommand = [[RACCommand alloc] initWithEnabled:[RACSignal combineLatest:@[RACObserve(self, username), RACObserve(self, password)] reduce:^id(NSString *username, NSString *password){ - return @(username.length > 0 && password.length > 0); - }] signalBlock:^RACSignal *(id input) { + self.loginCommand = [[RACCommand alloc] initWithEnabled:[self validateLoginInputs] + signalBlock:^RACSignal *(id input) { @strongify(self); return [FRPPhotoImporter logInWithUsername:self.username password:self.password]; }]; @@ -32,4 +31,11 @@ return self; } +- (RACSignal *)validateLoginInputs +{ + return [RACSignal combineLatest:@[RACObserve(self, username), RACObserve(self, password)] reduce:^id(NSString *username, NSString *password){ + return @(username.length > 0 && password.length > 0); + }]; +} + @end diff --git a/FRPTests/FRPLoginViewModelTests.m b/FRPTests/FRPLoginViewModelTests.m new file mode 100644 index 0000000..7437849 --- /dev/null +++ b/FRPTests/FRPLoginViewModelTests.m @@ -0,0 +1,66 @@ +// +// FRPLoginViewModelTests.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 "FRPLoginViewModel.h" + +@interface FRPLoginViewModel() + +- (RACSignal *)validateLoginInputs; + +@end + +SpecBegin(FRPLoginViewModel) + +__block FRPLoginViewModel *viewModel; + +beforeEach(^{ + viewModel = [[FRPLoginViewModel alloc] initWithModel:nil]; +}); + +describe(@"FRPLoginViewModel", ^{ + it(@"disable login command when username is empty", ^{ + viewModel.username = @""; + viewModel.password = @"password"; + __block id result; + [[viewModel validateLoginInputs] subscribeNext:^(id x) { + result = x; + }]; + expect(result).to.equal(@0); + }); + + it(@"disable login command when password is empty", ^{ + viewModel.username = @"username"; + viewModel.password = @""; + __block id result; + [[viewModel validateLoginInputs] subscribeNext:^(id x) { + result = x; + }]; + expect(result).to.equal(@0); + }); + + it(@"enable login command when username and password are available", ^{ + viewModel.username = @"username"; + viewModel.password = @"password"; + __block id result; + [[viewModel validateLoginInputs] subscribeNext:^(id x) { + result = x; + }]; + expect(result).to.equal(@1); + }); +}); + +afterEach(^{ + viewModel = nil; +}); + +SpecEnd \ No newline at end of file diff --git a/FRPTests/FRPPhotoImporterTests.m b/FRPTests/FRPPhotoImporterTests.m new file mode 100644 index 0000000..3c9bc0d --- /dev/null +++ b/FRPTests/FRPPhotoImporterTests.m @@ -0,0 +1,9 @@ +// +// FRPPhotoImporterTests.m +// FRP +// +// Created by Phat, Le Tan on 2/24/14. +// Copyright (c) 2014 Ash Furrow. All rights reserved. +// + +#include