spec/barometer_spec.rb in attack-barometer-0.3.2 vs spec/barometer_spec.rb in attack-barometer-0.5.0
- old
+ new
@@ -1,42 +1,35 @@
require 'spec_helper'
describe "Barometer" do
before(:each) do
- @preference_hash = { 1 => [:wunderground] }
+ @config_hash = { 1 => [:wunderground] }
@key = KEY
end
describe "and class methods" do
it "defines selection" do
- Barometer::Base.respond_to?("selection").should be_true
- Barometer::Base.selection.should == { 1 => [:wunderground] }
- Barometer::Base.selection = { 1 => [:yahoo] }
- Barometer::Base.selection.should == { 1 => [:yahoo] }
- Barometer.selection = @preference_hash
+ Barometer::Base.respond_to?("config").should be_true
+ Barometer::Base.config.should == { 1 => [:wunderground] }
+ Barometer::Base.config = { 1 => [:yahoo] }
+ Barometer::Base.config.should == { 1 => [:yahoo] }
+ Barometer.config = @config_hash
end
it "returns a Weather Service driver" do
- Barometer.source(:wunderground).should == Barometer::Wunderground
+ Barometer.source(:wunderground).should == Barometer::WeatherService::Wunderground
end
it "sets the Graticule Google geocoding API key" do
Barometer.respond_to?("google_geocode_key").should be_true
Barometer.google_geocode_key.should be_nil
Barometer.google_geocode_key = @key
Barometer.google_geocode_key.should == @key
end
- it "skips the use of Graticule" do
- Barometer.respond_to?("skip_graticule").should be_true
- Barometer.skip_graticule.should be_false
- Barometer.skip_graticule = true
- Barometer.skip_graticule.should be_true
- end
-
it "forces the geocoding of queries" do
Barometer.respond_to?("force_geocode").should be_true
Barometer.force_geocode.should be_false
Barometer.force_geocode = true
Barometer.force_geocode.should be_true
@@ -105,45 +98,28 @@
@barometer = Barometer::Base.new(query_term)
@time = Time.now
FakeWeb.register_uri(:get,
"http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=#{CGI.escape(query_term)}",
:string => File.read(File.join(File.dirname(__FILE__),
- 'fixtures',
+ 'fixtures/services/wunderground',
'current_calgary_ab.xml')
)
)
FakeWeb.register_uri(:get,
"http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=#{CGI.escape(query_term)}",
:string => File.read(File.join(File.dirname(__FILE__),
- 'fixtures',
+ 'fixtures/services/wunderground',
'forecast_calgary_ab.xml')
)
)
FakeWeb.register_uri(:get,
"http://maps.google.com:80/maps/geo?gl=&q=Calgary%2CAB&output=xml&key=#{@key}",
:string => File.read(File.join(File.dirname(__FILE__),
- 'fixtures',
- 'geocode_calgary_ab.xml')
+ 'fixtures/geocode',
+ 'calgary_ab.xml')
)
)
-
-
- FakeWeb.register_uri(:get,
- "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=51.055149%2C-114.062438",
- :string => File.read(File.join(File.dirname(__FILE__),
- 'fixtures',
- 'current_calgary_ab.xml')
- )
- )
- FakeWeb.register_uri(:get,
- "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=51.055149%2C-114.062438",
- :string => File.read(File.join(File.dirname(__FILE__),
- 'fixtures',
- 'forecast_calgary_ab.xml')
- )
- )
-
end
it "responds to measure" do
@barometer.respond_to?("measure").should be_true
end
@@ -151,11 +127,17 @@
it "returns a Barometer::Weather object" do
@barometer.measure.is_a?(Barometer::Weather).should be_true
end
it "raises OutOfSources if no services successful" do
- Barometer::Base.selection = { 1 => [] }
+ Barometer::Base.config = { 1 => [] }
lambda { @barometer.measure }.should raise_error(Barometer::OutOfSources)
+ end
+
+ it "sets the weight" do
+ Barometer::Base.config = { 1 => {:wunderground => {:weight => 2}} }
+ @barometer.measure
+ @barometer.weather.measurements.first.weight.should == 2
end
end
end