Skip to content
Browse files

declarative support for device orientation in cuke scenarios

e.g "Given the device is in a landscape orientation"
  • Loading branch information...
1 parent 6f3c8de commit 51a96c69e04916a8b5699e66044b9c3fa93a64c6 @moredip committed Sep 22, 2010
Showing with 80 additions and 1 deletion.
  1. +12 −0 cucumber/frank_helper.rb
  2. +17 −1 cucumber/frankly_steps.rb
  3. +2 −0 src/FrankServer.m
  4. +16 −0 src/OrientationCommand.h
  5. +33 −0 src/OrientationCommand.m
View
12 cucumber/frank_helper.rb
@@ -52,6 +52,18 @@ def frankly_dump
puts JSON.pretty_generate(JSON.parse(res)) rescue puts res #dumping a super-deep DOM causes errors
end
+ def frankly_oriented_portrait?
+ 'portrait' == frankly_current_orientation
+ end
+
+ def frankly_oriented_landscape?
+ 'landscape' == frankly_current_orientation
+ end
+
+ def frankly_current_orientation
+ res = get_to_uispec_server( 'orientation' )
+ JSON.parse( res )['orientation']
+ end
def wait_for_frank_to_come_up
num_consec_successes = 0
View
18 cucumber/frankly_steps.rb
@@ -82,7 +82,23 @@
end
# -- Rotate -- #
-And /^I rotate to the "([^\"]*)"$/ do |direction|
+Given /^the device is in a landscape orientation$/ do
+ unless frankly_oriented_landscape?
+ rotate_simulator_left
+ sleep 1
+ raise "expected orientation to be landscape after rotating left, but it is #{frankly_current_orientation}" unless frankly_oriented_landscape?
+ end
+end
+
+Given /^the device is in a portrait orientation$/ do
+ unless frankly_oriented_portrait?
+ rotate_simulator_left
+ sleep 1
+ raise "expected orientation to be portrait after rotating left, but it is #{frankly_current_orientation}" unless frankly_oriented_portrait?
+ end
+end
+
+Then /^I rotate to the "([^\"]*)"$/ do |direction|
if direction == "right"
rotate_simulator_right
elsif direction == "left"
View
2 src/FrankServer.m
@@ -14,6 +14,7 @@
#import "FrankCommandRoute.h"
#import "DumpCommand.h"
#import "MapOperationCommand.h"
+#import "OrientationCommand.h"
#import "MemoryLogger.h"
void LogToMemory(NSString *format, ...) {
@@ -52,6 +53,7 @@ - (id) initWithStaticFrankBundleNamed:(NSString *)bundleName
FrankCommandRoute *frankCommandRoute = [[[FrankCommandRoute alloc] init] autorelease];
[frankCommandRoute registerCommand:[[[DumpCommand alloc]init]autorelease] withName:@"dump"];
[frankCommandRoute registerCommand:[[[MapOperationCommand alloc]init]autorelease] withName:@"map"];
+ [frankCommandRoute registerCommand:[[[OrientationCommand alloc]init]autorelease] withName:@"orientation"];
[[RequestRouter singleton] registerRoute:frankCommandRoute];
StaticResourcesRoute *staticRoute = [[[StaticResourcesRoute alloc] initWithStaticResourceSubDir:bundleName] autorelease];
View
16 src/OrientationCommand.h
@@ -0,0 +1,16 @@
+//
+// OrientationCommand.h
+// Chase.Mobi
+//
+// Created by Pete Hodgson on 9/21/10.
+// Copyright 2010 ThoughtWorks. See NOTICE file for details.
+//
+
+#import <Foundation/Foundation.h>
+#import "FrankCommandRoute.h"
+
+@interface OrientationCommand : NSObject<FrankCommand> {
+
+}
+
+@end
View
33 src/OrientationCommand.m
@@ -0,0 +1,33 @@
+//
+// OrientationCommand.m
+// Chase.Mobi
+//
+// Created by Pete Hodgson on 9/21/10.
+// Copyright 2010 ThoughtWorks. See NOTICE file for details.
+//
+
+#import "OrientationCommand.h"
+
+
+@implementation OrientationCommand
+
+- (NSString *)handleCommandWithRequestBody:(NSString *)requestBody {
+ NSString *orientationDescription = nil;
+ switch ( [UIDevice currentDevice].orientation ) {
+ case UIDeviceOrientationLandscapeRight:
+ case UIDeviceOrientationLandscapeLeft:
+ orientationDescription = @"landscape";
+ break;
+ case UIDeviceOrientationPortrait:
+ case UIDeviceOrientationPortraitUpsideDown:
+ orientationDescription = @"portrait";
+ break;
+ default:
+ orientationDescription = @"flat";
+ }
+
+ NSDictionary *dom = [NSDictionary dictionaryWithObject:orientationDescription forKey:@"orientation"];
+ return [dom JSONRepresentation];
+}
+
+@end

0 comments on commit 51a96c6

Please sign in to comment.
Something went wrong with that request. Please try again.