Skip to content

Instantly share code, notes, and snippets.

@alexrothenberg
Created March 19, 2014 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexrothenberg/9642408 to your computer and use it in GitHub Desktop.
Save alexrothenberg/9642408 to your computer and use it in GitHub Desktop.
stub api calls for rubymotion calabash tests
class Api
def base_url
if stubbed?
"file://#{App.resources_path.gsub(' ', '%20')}/test_api_data"
else
App.info_plist["API_BASE_URL"]
end
end
def stubbed?
App.info_plist["API_BASE_URL"] == 'http://stub.example.com'
end
def afmotion_client
AFMotion::Client.build(base_url) do
operation :json
end
end
def get(url, parameters={}, &block)
afmotion_client.get(url, parameters) do |response|
if response.success?
block.call true, response.object
else
block.call false, response.error
end
end
end
end
Motion::Project::App.setup do |app|
app.info_plist['API_BASE_URL'] = ENV['API_BASE_URL'] || 'http://api.myserver.com'
end
task :cucumber => [:stub, :'build:simulator', :'calabash:run']
task :stub do
ENV['API_BASE_URL'] = 'http://stub.example.com'
end
# rake cucumber
# 1. at compile time set stub url
# 2. at runtime will afmotion will make api calls to json files in resources/test_api_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment