require 'json' require 'frank-cucumber/gateway' require 'cfpropertylist' module FWToolkit module Test module ModelHelpers def fwt_app_exec(method_name, *method_args) operation_map = Frank::Cucumber::Gateway.build_operation_map(method_name,method_args) res = frank_server.send_post( 'app_exec', :operation => operation_map ) return Frank::Cucumber::Gateway.evaluate_frankly_response( res, "app_exec #{method_name}" ) end def fwt_simulator_applications_dir File.join(Dir.home, 'Library', 'Application Support', 'iPhone Simulator', fwt_ios_sdk, 'Applications') end def fwt_kill_simulator `echo 'application "iPhone Simulator" quit' | osascript` end def fwt_simulator_reset_data(sdk) fwt_kill_simulator FileUtils.rm_rf(fwt_simulator_applications_dir) end def fwt_launch_app(device='iphone') launch_app fwt_app_path, fwt_ios_sdk, device end def fwt_ios_sdk raise "IOS_SDK not defined. Please define this in your env.rb, i.e. IOS_SDK='5.1'" unless defined?(IOS_SDK) IOS_SDK end def fwt_app_path raise "APP_BUNDLE_PATH not defined. Please define this in your env.rb, i.e. APP_BUNDLE_PATH='File.expand_path( '../../../frankified_build/Frankified.app', __FILE__ )'" unless defined?(APP_BUNDLE_PATH) raise "File defined in APP_BUNDLE_PATH (#{APP_BUNDLE_PATH}) does not exist" unless File.exists?(APP_BUNDLE_PATH) APP_BUNDLE_PATH end def fwt_seed_app(model_names=[]) puts "Deprecated: fwt_seed_app(). Please use fwt_seed_app_with_pickle_models(). Will be changed in 0.6.0 to accept objects." fwt_seed_app_with_pickle_models(model_names) end def fwt_seed_app_with_pickle_models(model_names=[]) objects = model_names.collect{|n| model!(n)} fwt_seed_app_with_objects(objects) end def fwt_seed_app_with_objects(objects = []) fwt_app_exec("seedCoreData:", objects.to_json) end def fwt_set_user_defaults(bundle_identifier, user_defaults) app_dir = Dir.entries(fwt_simulator_applications_dir) app_dir.delete "." app_dir.delete ".." plist_file = File.join(fwt_simulator_applications_dir, app_dir.first, 'Library', 'Preferences', "#{bundle_identifier}.plist") plist = CFPropertyList::List.new(:file => plist_file) data = CFPropertyList.native_types(plist.value) data.merge! user_defaults plist.value = CFPropertyList.guess(data) plist.save(plist_file, CFPropertyList::List::FORMAT_BINARY) end end end end World(FWToolkit::Test::ModelHelpers)