Created
March 19, 2014 14:10
-
-
Save alexrothenberg/9642408 to your computer and use it in GitHub Desktop.
stub api calls for rubymotion calabash tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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