file://localhost/Users/matt/Projects/My/MySDK/MySpecs/MyClientSpecs.m: error: runSpec (MyClientSpecs) failed: "MyClient -viewControllerWithTransaction:forceWeb: sets the returned MyViewController's transactionURL" FAILED, expected subject to be identical to https://my.com/ (0x867d080), got http://my.com/touch/signup_to_pay/?app_id=your_app_id&txn=pay&amount=3.45¬e=hello%20world&recipients=kortina,mattdipasquale (0x867d6e0)
file://localhost/Users/matt/Projects/My/MySDK/MySpecs/MyClientSpecs.m: error: runSpec (MyClientSpecs) failed: "MyClient -viewControllerWithTransaction:forceWeb: sets the returned MyViewController's transactionURL" FAILED, expected subject to receive -safariURLWithPath: exactly 1 time, but received it 0 times
file://localhost/Users/matt/Projects/My/MySDK/MySpecs/MyClientSpecs.m: error: runSpec (MyClientSpecs) failed: "MyClient -viewControllerWithTransaction:forceWeb: sets the returned MyViewController's transactionURL" FAILED, expected subject to be identical to https://my.com/ (0x867d080), got http://my.com/touch/signup_to_pay/?app_id=your_app_id&txn=pay&amount=3.45¬e=hello%20world&recipients=kortina,mattdipasquale (0x867d6e0)
file://localhost/Users/matt/Projects/My/MySDK/MySpecs/MyClientSpecs.m: error: runSpec (MyClientSpecs) failed: "MyClient -viewControllerWithTransaction:forceWeb: sets the returned MyViewController's transactionURL" FAILED, expected subject to receive -safariURLWithPath: exactly 1 time, but received it 0 times
__block MyClient *client;
__block NSString *URLPath;
__block MyTransaction *transaction;
beforeEach(^{
client = [[MyClient alloc] initWithAppId:@"your_app_id" secret:@"your_app_secret"];
URLPath = @"/?key=value";
transaction = [[MyTransaction alloc] init];
transaction.type = MyTransactionTypePay;
transaction.amount = 3.45f;
transaction.note = @"hello world";
transaction.recipients = [NSArray arrayWithObjects:@"dudeyo", @"mattdipasquale", nil];
});
describe(@"-viewControllerWithTransaction:", ^{
it(@"calls -viewControllerWithTransaction:forceWeb:NO", ^{
[[client should] receive:@selector(viewControllerWithTransaction:forceWeb:)
withArguments:transaction, theValue(NO)];
[client viewControllerWithTransaction:transaction];
});
});
describe(@"-viewControllerWithTransaction:forceWeb:", ^{
__block UIApplication *app;
beforeEach(^{
app = [UIApplication sharedApplication];
});
context(@"forceWeb:NO", ^{
it(@"checks if app canOpenURL:transactionURL", ^{
NSURL *myURL = [NSURL URLWithString:@"https://my.com/"];
[[client should] receive:@selector(myURLWithPath:) andReturn:myURL];
[[app should] receive:@selector(canOpenURL:) withArguments:myURL];
[client viewControllerWithTransaction:transaction forceWeb:NO];
});
it(@"returns nil if canOpenURL:transactionURL", ^{
[[app should] receive:@selector(canOpenURL:) andReturn:theValue(YES)];
[[app should] receive:@selector(openURL:)];
[[client viewControllerWithTransaction:transaction forceWeb:NO] shouldBeNil];
});
it(@"returns a new MyViewController if not canOpenURL:transactionURL", ^{
[[app should] receive:@selector(canOpenURL:) andReturn:theValue(NO)];
[[[client viewControllerWithTransaction:transaction forceWeb:NO] should]
beKindOfClass:[MyViewController class]];
});
});
context(@"forceWeb:YES", ^{
it(@"bypasses canOpenURL:transactionURL check", ^{
[[app shouldNot] receive:@selector(canOpenURL:)];
[client viewControllerWithTransaction:transaction forceWeb:YES];
});
it(@"always returns a new MyViewController", ^{
[[[client viewControllerWithTransaction:transaction forceWeb:YES] should]
beKindOfClass:[MyViewController class]];
});
});
it(@"sets the returned MyViewController's transactionURL", ^{
NSURL *safariURL = [NSURL URLWithString:@"https://my.com/"];
[[client should] receive:@selector(safariURLWithPath:) andReturn:safariURL];
MyViewController *myController = [client viewControllerWithTransaction:transaction
forceWeb:YES];
[[myController.transactionURL should] beIdenticalTo:safariURL];
});
});