Skip to content

Instantly share code, notes, and snippets.

@avit
Created February 9, 2013 23:17
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 avit/4747535 to your computer and use it in GitHub Desktop.
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.
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