Created
February 9, 2013 23:17
-
-
Save avit/4747535 to your computer and use it in GitHub Desktop.
Allows for using barometer gem in client app specs without hitting the network.
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
require 'bundler' | |
require 'barometer' | |
require 'fakeweb' | |
module TestStubs | |
module Barometer | |
def self.stub! | |
FakeWeb.register_uri( | |
:get, %r[^http://api\.wunderground\.com/auto/wui/geo/WXCurrentObXML/index\.xml\?query], | |
body: File.read(current_fixture_path) | |
) | |
FakeWeb.register_uri( | |
:get, %r[^http://api\.wunderground\.com/auto/wui/geo/ForecastXML/index\.xml\?query], | |
body: File.read(forecast_fixture_path) | |
) | |
measurement = ::Barometer::Measurement.any_instance | |
[:success, :success?].each do |fn| | |
measurement.stub(fn).and_return(true) | |
end | |
end | |
private | |
def self.gem_path | |
barometer_gem = Bundler.load.specs.find { |s| s.name == 'barometer' } | |
barometer_gem.full_gem_path | |
end | |
def self.current_fixture_path | |
File.join(gem_path, '/spec/fixtures/services/wunderground/current_calgary_ab.xml') | |
end | |
def self.forecast_fixture_path | |
File.join(gem_path, '/spec/fixtures/services/wunderground/forecast_calgary_ab.xml') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment