Skip to content

Instantly share code, notes, and snippets.

@clarkbw
Created January 30, 2014 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkbw/8701258 to your computer and use it in GitHub Desktop.
Save clarkbw/8701258 to your computer and use it in GitHub Desktop.
FakeWeb loading fixtures for the data. this example uses the geonames service
require 'fakeweb'
require 'yaml'
Rails.logger.info "Using FakeWeb: #{GeoNamesAPI.url}::#{GeoNamesAPI.username}"
# expects a fixture with the following geonames data format:
# 42.93,-71.43:
# json: >
# { "time": "2014-01-12 12:41", "countryName": "United States", "sunset": "2014-01-12 16:33",
# "rawOffset": -5, "dstOffset": -4, "countryCode": "US", "gmtOffset": -5, "lng": -71.43,
# "sunrise": "2014-01-12 07:15", "timezoneId": "America/New_York", "lat": 42.93 }
geonames = YAML.load(File.open('test/services/fixtures/geonames.yml'))
geonames.each_pair do |args, fixture|
lat, lon = args.split(",")
FakeWeb.register_uri(:get,
"#{GeoNamesAPI.url}timezoneJSON?lang=en&username=#{GeoNamesAPI.username}&style=full&lat=#{lat}&lng=#{lon}",
:body => fixture['json'],
:content_type => "application/json")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment