spec/weather_spec.rb in barometer-0.3.2 vs spec/weather_spec.rb in barometer-0.5.0
- old
+ new
@@ -36,20 +36,20 @@
describe "with measurements" do
before(:each) do
module Barometer
- class Measurement
+ class Data::Measurement
attr_accessor :success
end
end
@weather = Barometer::Weather.new
- @wunderground = Barometer::Measurement.new(:wunderground)
+ @wunderground = Data::Measurement.new(:wunderground)
@wunderground.success = true
- @yahoo = Barometer::Measurement.new(:yahoo)
+ @yahoo = Data::Measurement.new(:yahoo)
@yahoo.success = true
- @google = Barometer::Measurement.new(:google)
+ @google = Data::Measurement.new(:google)
@weather.measurements << @wunderground
@weather.measurements << @yahoo
@weather.measurements << @google
end
@@ -80,40 +80,51 @@
describe "when calculating averages" do
before(:each) do
@weather = Barometer::Weather.new
- @wunderground = Barometer::Measurement.new(:wunderground)
- @wunderground.current = Barometer::CurrentMeasurement.new
+ @wunderground = Data::Measurement.new(:wunderground)
+ @wunderground.current = Data::CurrentMeasurement.new
@wunderground.success = true
- @yahoo = Barometer::Measurement.new(:yahoo)
- @yahoo.current = Barometer::CurrentMeasurement.new
+ @yahoo = Data::Measurement.new(:yahoo)
+ @yahoo.current = Data::CurrentMeasurement.new
@yahoo.success = true
- @google = Barometer::Measurement.new(:google)
+ @google = Data::Measurement.new(:google)
@weather.measurements << @wunderground
@weather.measurements << @yahoo
@weather.measurements << @google
end
it "doesn't include nil values" do
- @weather.source(:wunderground).current.temperature = Barometer::Temperature.new
+ @weather.source(:wunderground).current.temperature = Data::Temperature.new
@weather.source(:wunderground).current.temperature.c = 10
@weather.temperature.c.should == 10
- @weather.source(:yahoo).current.temperature = Barometer::Temperature.new
+ @weather.source(:yahoo).current.temperature = Data::Temperature.new
@weather.source(:yahoo).current.temperature.c = nil
@weather.temperature.c.should == 10
end
+ it "respects the measurement weight" do
+ @weather.source(:wunderground).current.temperature = Data::Temperature.new
+ @weather.source(:wunderground).current.temperature.c = 10
+ @weather.source(:yahoo).current.temperature = Data::Temperature.new
+ @weather.source(:yahoo).current.temperature.c = 4
+
+ @weather.measurements.first.weight = 2
+
+ @weather.temperature.c.should == 8
+ end
+
describe "for temperature" do
before(:each) do
- @weather.source(:wunderground).current.temperature = Barometer::Temperature.new
+ @weather.source(:wunderground).current.temperature = Data::Temperature.new
@weather.source(:wunderground).current.temperature.c = 10
- @weather.source(:yahoo).current.temperature = Barometer::Temperature.new
+ @weather.source(:yahoo).current.temperature = Data::Temperature.new
@weather.source(:yahoo).current.temperature.c = 6
end
it "returns averages" do
@weather.temperature.c.should == 8
@@ -126,13 +137,13 @@
end
describe "for wind" do
before(:each) do
- @weather.source(:wunderground).current.wind = Barometer::Speed.new
+ @weather.source(:wunderground).current.wind = Data::Speed.new
@weather.source(:wunderground).current.wind.kph = 10
- @weather.source(:yahoo).current.wind = Barometer::Speed.new
+ @weather.source(:yahoo).current.wind = Data::Speed.new
@weather.source(:yahoo).current.wind.kph = 6
end
it "returns averages" do
@weather.wind.kph.should == 8
@@ -162,13 +173,13 @@
end
describe "for pressure" do
before(:each) do
- @weather.source(:wunderground).current.pressure = Barometer::Pressure.new
+ @weather.source(:wunderground).current.pressure = Data::Pressure.new
@weather.source(:wunderground).current.pressure.mb = 10
- @weather.source(:yahoo).current.pressure = Barometer::Pressure.new
+ @weather.source(:yahoo).current.pressure = Data::Pressure.new
@weather.source(:yahoo).current.pressure.mb = 6
end
it "returns averages" do
@weather.pressure.mb.should == 8
@@ -181,13 +192,13 @@
end
describe "for dew_point" do
before(:each) do
- @weather.source(:wunderground).current.dew_point = Barometer::Temperature.new
+ @weather.source(:wunderground).current.dew_point = Data::Temperature.new
@weather.source(:wunderground).current.dew_point.c = 10
- @weather.source(:yahoo).current.dew_point = Barometer::Temperature.new
+ @weather.source(:yahoo).current.dew_point = Data::Temperature.new
@weather.source(:yahoo).current.dew_point.c = 6
end
it "returns averages" do
@weather.dew_point.c.should == 8
@@ -200,13 +211,13 @@
end
describe "for heat_index" do
before(:each) do
- @weather.source(:wunderground).current.heat_index = Barometer::Temperature.new
+ @weather.source(:wunderground).current.heat_index = Data::Temperature.new
@weather.source(:wunderground).current.heat_index.c = 10
- @weather.source(:yahoo).current.heat_index = Barometer::Temperature.new
+ @weather.source(:yahoo).current.heat_index = Data::Temperature.new
@weather.source(:yahoo).current.heat_index.c = 6
end
it "returns averages" do
@weather.heat_index.c.should == 8
@@ -219,13 +230,13 @@
end
describe "for wind_chill" do
before(:each) do
- @weather.source(:wunderground).current.wind_chill = Barometer::Temperature.new
+ @weather.source(:wunderground).current.wind_chill = Data::Temperature.new
@weather.source(:wunderground).current.wind_chill.c = 10
- @weather.source(:yahoo).current.wind_chill = Barometer::Temperature.new
+ @weather.source(:yahoo).current.wind_chill = Data::Temperature.new
@weather.source(:yahoo).current.wind_chill.c = 6
end
it "returns averages" do
@weather.wind_chill.c.should == 8
@@ -238,13 +249,13 @@
end
describe "for visibility" do
before(:each) do
- @weather.source(:wunderground).current.visibility = Barometer::Distance.new
+ @weather.source(:wunderground).current.visibility = Data::Distance.new
@weather.source(:wunderground).current.visibility.km = 10
- @weather.source(:yahoo).current.visibility = Barometer::Distance.new
+ @weather.source(:yahoo).current.visibility = Data::Distance.new
@weather.source(:yahoo).current.visibility.km = 6
end
it "returns averages" do
@weather.visibility.km.should == 8
@@ -260,45 +271,46 @@
describe "when answering the simple questions," do
before(:each) do
@weather = Barometer::Weather.new
+ @now = Data::LocalDateTime.parse("2:05 pm")
end
describe "windy?" do
it "requires threshold as a number" do
lambda { @weather.windy?("a") }.should raise_error(ArgumentError)
lambda { @weather.windy?(1) }.should_not raise_error(ArgumentError)
lambda { @weather.windy?(1.1) }.should_not raise_error(ArgumentError)
end
- it "requires time as a Time object" do
- lambda { @weather.windy?(1,"a") }.should raise_error(ArgumentError)
- lambda { @weather.windy?(1,Time.now.utc) }.should_not raise_error(ArgumentError)
+ it "requires time as a Data::LocalTime object" do
+ #lambda { @weather.windy?(1,"a") }.should raise_error(ArgumentError)
+ lambda { @weather.windy?(1,@now) }.should_not raise_error(ArgumentError)
end
it "returns nil when no measurements" do
@weather.measurements.should be_empty
@weather.windy?.should be_nil
end
it "returns true if a measurement returns true" do
- wunderground = Barometer::Measurement.new(:wunderground)
+ wunderground = Data::Measurement.new(:wunderground)
wunderground.success = true
@weather.measurements << wunderground
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def windy?(a=nil,b=nil); true; end
end; end
@weather.windy?.should be_true
end
it "returns false if a measurement returns false" do
- wunderground = Barometer::Measurement.new(:wunderground)
+ wunderground = Data::Measurement.new(:wunderground)
wunderground.success = true
@weather.measurements << wunderground
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def windy?(a=nil,b=nil); false; end
end; end
@weather.windy?.should be_false
end
@@ -310,130 +322,130 @@
lambda { @weather.wet?("a") }.should raise_error(ArgumentError)
lambda { @weather.wet?(1) }.should_not raise_error(ArgumentError)
lambda { @weather.wet?(1.1) }.should_not raise_error(ArgumentError)
end
- it "requires time as a Time object" do
- lambda { @weather.wet?(1,"a") }.should raise_error(ArgumentError)
- lambda { @weather.wet?(1,Time.now.utc) }.should_not raise_error(ArgumentError)
+ it "requires time as a Data::LocalTime object" do
+ #lambda { @weather.wet?(1,"a") }.should raise_error(ArgumentError)
+ lambda { @weather.wet?(1,@now) }.should_not raise_error(ArgumentError)
end
it "returns nil when no measurements" do
@weather.measurements.should be_empty
@weather.wet?.should be_nil
end
it "returns true if a measurement returns true" do
- wunderground = Barometer::Measurement.new(:wunderground)
+ wunderground = Data::Measurement.new(:wunderground)
wunderground.success = true
@weather.measurements << wunderground
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def wet?(a=nil,b=nil); true; end
end; end
@weather.wet?.should be_true
end
it "returns false if a measurement returns false" do
- wunderground = Barometer::Measurement.new(:wunderground)
+ wunderground = Data::Measurement.new(:wunderground)
wunderground.success = true
@weather.measurements << wunderground
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def wet?(a=nil,b=nil); false; end
end; end
@weather.wet?.should be_false
end
end
describe "day? and night?" do
- it "requires time as a Time object" do
- lambda { @weather.day?("a") }.should raise_error(ArgumentError)
- lambda { @weather.day?(Time.now.utc) }.should_not raise_error(ArgumentError)
+ it "requires time as a Data::LocalTime object" do
+ #lambda { @weather.day?("a") }.should raise_error(ArgumentError)
+ lambda { @weather.day?(@now) }.should_not raise_error(ArgumentError)
end
- it "requires time as a Time object" do
- lambda { @weather.night?("a") }.should raise_error(ArgumentError)
- lambda { @weather.night?(Time.now.utc) }.should_not raise_error(ArgumentError)
+ it "requires time as a Data::LocalTime object" do
+ #lambda { @weather.night?("a") }.should raise_error(ArgumentError)
+ lambda { @weather.night?(@now) }.should_not raise_error(ArgumentError)
end
it "returns nil when no measurements" do
@weather.measurements.should be_empty
@weather.day?.should be_nil
@weather.night?.should be_nil
end
it "returns true if a measurement returns true (night is opposite)" do
- wunderground = Barometer::Measurement.new(:wunderground)
+ wunderground = Data::Measurement.new(:wunderground)
wunderground.success = true
@weather.measurements << wunderground
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def day?(a=nil); true; end
end; end
@weather.day?.should be_true
@weather.night?.should be_false
end
it "returns false if a measurement returns false (night is opposite)" do
- wunderground = Barometer::Measurement.new(:wunderground)
+ wunderground = Data::Measurement.new(:wunderground)
wunderground.success = true
@weather.measurements << wunderground
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def day?(a=nil); false; end
end; end
@weather.day?.should be_false
@weather.night?.should be_true
end
end
describe "sunny?" do
- it "requires time as a Time object" do
- lambda { @weather.sunny?("a") }.should raise_error(ArgumentError)
- lambda { @weather.sunny?(Time.now.utc) }.should_not raise_error(ArgumentError)
+ it "requires time as a Data::LocalTime object" do
+ #lambda { @weather.sunny?("a") }.should raise_error(ArgumentError)
+ lambda { @weather.sunny?(@now) }.should_not raise_error(ArgumentError)
end
it "returns nil when no measurements" do
@weather.measurements.should be_empty
@weather.sunny?.should be_nil
end
it "returns true if a measurement returns true" do
- wunderground = Barometer::Measurement.new(:wunderground)
+ wunderground = Data::Measurement.new(:wunderground)
wunderground.success = true
@weather.measurements << wunderground
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def day?(a=nil); true; end
end; end
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def sunny?(a=nil,b=nil); true; end
end; end
@weather.sunny?.should be_true
end
it "returns false if a measurement returns false" do
- wunderground = Barometer::Measurement.new(:wunderground)
+ wunderground = Data::Measurement.new(:wunderground)
wunderground.success = true
@weather.measurements << wunderground
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def day?(a=nil); true; end
end; end
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def sunny?(a=nil,b=nil); false; end
end; end
@weather.sunny?.should be_false
end
it "returns false if night time" do
- wunderground = Barometer::Measurement.new(:wunderground)
+ wunderground = Data::Measurement.new(:wunderground)
wunderground.success = true
@weather.measurements << wunderground
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def sunny?(a=nil,b=nil); true; end
end; end
@weather.sunny?.should be_true
- module Barometer; class Measurement
+ module Barometer; class Data::Measurement
def day?(a=nil); false; end
end; end
@weather.sunny?.should be_false
end
\ No newline at end of file