Created
          January 30, 2014 02:00 
        
      - 
      
- 
        Save clarkbw/8701258 to your computer and use it in GitHub Desktop. 
    FakeWeb loading fixtures for the data. this example uses the geonames service
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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