Created
June 5, 2015 20:06
-
-
Save dinks/2e8817edc11810babf5b to your computer and use it in GitHub Desktop.
Mock Geocoder
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
# /spec/support/mock_geocoder.rb | |
# Used with ffaker | |
RSpec.configure do |c| | |
class MockResult < ::Geocoder::Result::Base | |
def initialize(data = []) | |
super(data) | |
end | |
end | |
c.before(:each, :mock_geocoder) do | |
options = { | |
address: FFaker::AddressAU.full_address, | |
coordinates: [FFaker::Geolocation.lat, FFaker::Geolocation.lng], | |
state: FFaker::AddressAU.state, | |
state_code: FFaker::AddressAU.state_abbr, | |
country: FFaker::AddressAU.country, | |
country_code: FFaker::AddressAU.country_code | |
} | |
MockResult.new.tap do |result| | |
options.each do |prop, val| | |
allow(result).to receive(prop).and_return(val) | |
end | |
allow(Geocoder).to receive(:search).and_return([result]) | |
end | |
end | |
c.after(:each, :mock_geocoder) do | |
# Nothing to do | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment