Skip to content
Browse files

Add support for querying and setting application defaults.

  • Loading branch information...
1 parent 188fb48 commit 7387af611c0ee497279924ae5e4ab5488ea0b420 Rob Holland committed
Showing with 59 additions and 11 deletions.
  1. +18 −0 ext/iCuke/iCukeHTTPConnection.m
  2. +7 −3 lib/icuke/cucumber.rb
  3. +34 −8 lib/icuke/simulator.rb
View
18 ext/iCuke/iCukeHTTPConnection.m
@@ -53,6 +53,24 @@ @implementation iCukeHTTPConnection
} else if ([path hasPrefix:@"/view"]) {
NSData *browseData = [[[Viewer sharedViewer] screen] dataUsingEncoding:NSUTF8StringEncoding];
return [[[HTTPDataResponse alloc] initWithData:browseData] autorelease];
+ } else if ([path hasPrefix:@"/defaults"]) {
+ NSUserDefaults *user_defaults = [NSUserDefaults standardUserDefaults];
+ id json = [[self parseRequestQuery] objectForKey:@"json"];
+
+ if (!json) {
+ NSDictionary *defaults = [user_defaults dictionaryRepresentation];
+
+ NSData *browseData = [[defaults JSONRepresentation] dataUsingEncoding:NSUTF8StringEncoding];
+ return [[[HTTPDataResponse alloc] initWithData:browseData] autorelease];
+ } else {
+ id parsed_json = [json JSONValue];
+
+ NSEnumerator *enumerator = [parsed_json keyEnumerator];
+ id key;
+ while ((key = [enumerator nextObject])) {
+ [user_defaults setObject: [parsed_json objectForKey: key] forKey: key];
+ }
+ }
} else if ([path hasPrefix:@"/record"]) {
[[Recorder sharedRecorder] record];
View
10 lib/icuke/cucumber.rb
@@ -28,11 +28,11 @@ def page
end
def response
- @response ||= Curl::Easy.http_get(BASE_URL + '/view').body_str
+ @response ||= @simulator.view
end
def record
- Curl::Easy.http_get(BASE_URL + "/record")
+ @simulator.record
end
def tap(label, options = {}, &block)
@@ -51,7 +51,7 @@ def tap(label, options = {}, &block)
x = frame['x'].to_f + (frame['width'].to_f / 2)
y = frame['y'].to_f + (frame['height'].to_f / 2)
- Curl::Easy.http_get(BASE_URL + "/event?json=#{Tap.new(x, y, options).to_json}")
+ @simulator.fire_event(Tap.new(x, y, options))
sleep(options[:pause] ? 1 : 0.2)
@@ -85,6 +85,10 @@ def type(textfield, text)
tap('Return')
end
+ def set_application_defaults(defaults)
+ @simulator.set_defaults(defaults)
+ end
+
private
def refresh
View
42 lib/icuke/simulator.rb
@@ -1,12 +1,12 @@
require 'osx/cocoa'
OSX.require_framework '/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/iPhoneSimulatorRemoteClient.framework'
-require 'curb'
+require 'httparty'
module ICuke
class Simulator < OSX::NSObject
include OSX
-
- BASE_URL = 'http://localhost:50000'
+ include HTTParty
+ base_uri 'http://localhost:50000'
class FailedToStart < RuntimeError; end
@@ -66,20 +66,46 @@ def launch(application, options = {})
end
def quit
- Curl::Easy.http_get(BASE_URL + '/quit')
- rescue Curl::Err::GotNothingError
+ get '/quit'
+ rescue EOFError
+ end
+
+ def view
+ get('/view')
+ end
+
+ def record
+ get '/record'
+ end
+
+ def stop
+ get '/stop'
end
def save(path)
- Curl::Easy.http_get(BASE_URL + "/save?file=#{path}")
+ get '/save', :query => { :file => path }
end
def load(path)
- Curl::Easy.http_get(BASE_URL + "/load?file=#{path}")
+ get '/load', :query => { :file => path }
end
def play
- Curl::Easy.http_get(BASE_URL + '/play')
+ get '/play'
+ end
+
+ def fire_event(event)
+ get '/event', :query => { :json => event.to_json }
+ end
+
+ def set_defaults(defaults)
+ get '/defaults', :query => { :json => defaults.to_json }
+ end
+
+ private
+
+ def get(path, options = {})
+ self.class.get(path, options).body
end
end
end

0 comments on commit 7387af6

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