spec/lwws_spec.rb in weatherhacks-0.1.1 vs spec/lwws_spec.rb in weatherhacks-0.2.0

- old
+ new

@@ -1,243 +1,236 @@ -require File.dirname(__FILE__) + '/spec_helper.rb' +$LOAD_PATH.unshift File.join(File.join(File.dirname(__FILE__), ".."), "lib") +require "weatherhacks" +require "rubygems" +require "bacon" -describe WeatherHacks::LWWS::Forecast do - before do - @forecast = WeatherHacks::LWWS::Forecast.new($today) - end +include WeatherHacks::LWWS - it "can read author as a String" do - @forecast.author.should be_a_kind_of(String) - end +$today, $tomorrow, $dayaftertomorrow = WeatherHacks.lwws("松江") - it "can read location as a WeatherHacks::LWWS::Location" do - @forecast.location.should be_a_kind_of(WeatherHacks::LWWS::Location) - end +describe "WeatherHacks::LWWS::Forecast" do - it "can read title as a String" do - @forecast.title.should be_a_kind_of(String) + def forecast(&block) + [$today, $tomorrow, $dayaftertomorrow].each {|f| yield f } end - it "can read link as a URI" do - @forecast.link.should be_a_kind_of(URI) + it "#author" do + forecast {|f| f.author.should.be.kind_of(String) } end - it "can read forecastday as a String" do - @forecast.forecastday.should be_a_kind_of(String) + it "#location" do + forecast {|f| f.location.should.be.kind_of(::Location) } end - it "can read day as a String" do - @forecast.day.should match(/Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday/) + it "#title" do + forecast {|f| f.title.should.be.kind_of(String) } end - it "can read forecastdate as a Time" do - @forecast.forecastdate.should be_a_kind_of(Time) + it "#link" do + forecast {|f| f.link.should.be.kind_of(URI) } end - it "can read publictime as a Time" do - @forecast.publictime.should be_a_kind_of(Time) + it "#forecastday" do + $today.forecastday.should == "today" + $tomorrow.forecastday.should == "tomorrow" + $dayaftertomorrow.forecastday.should == "dayaftertomorrow" end - it "can read telop as a String" do - @forecast.telop.should be_a_kind_of(String) + it "#day" do + forecast {|f| f.day.should =~ /(Sun|Mon|Tues|Wednes|Thurs|Fri|Satur)day/ } end - it "can read description as String" do - @forecast.description.should be_a_kind_of(String) + it "#forecastdate" do + forecast {|f| f.forecastdate.should.be.kind_of(Time) } end - it "can read image as a WeatherHacks::LWWS::Image" do - @forecast.image.should be_a_kind_of(WeatherHacks::LWWS::Image) + it "#publictime" do + forecast {|f| f.publictime.should.be.kind_of(Time) } end - it "can read celsius as a WeatherHacks::LWWS::Celsius" do - @forecast.celsius.should be_a_kind_of(WeatherHacks::LWWS::Celsius) + it "#telop" do + forecast {|f| f.telop.should.be.kind_of(String) } end - it "can read fahrenheit as a WeatherHacks::LWWS::Fahrenheit" do - @forecast.fahrenheit.should be_a_kind_of(WeatherHacks::LWWS::Fahrenheit) + it "#description" do + forecast {|f| f.description.should.be.kind_of(String) } end - it "can read pinpoints as a list of WeatherHacks::LWWS::PinpointLocation" do - @forecast.pinpoints.each do |location| - location.should be_a_kind_of(WeatherHacks::LWWS::PinpointLocation) - end + it "#image" do + forecast {|f| f.image.should.be.kind_of(Image) } end - it "can read copyright as a WeatherHacks::LWWS::Copyright" do - @forecast.copyright.should be_a_kind_of(WeatherHacks::LWWS::Copyright) + it "#celsius" do + forecast {|f| f.celsius.should.be.kind_of(Celsius) } end - after do - @forecast = nil + it "#fahrenheit" do + forecast {|f| f.fahrenheit.should.be.kind_of(Fahrenheit) } end -end -describe WeatherHacks::LWWS::Forecast, "#forecastday" do - it "allows 'today'" do - WeatherHacks::LWWS::Forecast.new($today).forecastday.should eql("today") + it "#pinpoints" do + forecast do |f| + f.pinpoints.each do |location| + location.should.be.kind_of(PinpointLocation) + end + end end - it "allows 'tomorrow'" do - WeatherHacks::LWWS::Forecast.new($tomorrow).forecastday.should eql("tomorrow") + it "#copyright" do + forecast{|f| f.copyright.should.be.kind_of(Copyright) } end - - it "allows 'dayaftertomorrow'" do - WeatherHacks::LWWS::Forecast.new($dayaftertomorrow).forecastday.should eql("dayaftertomorrow") - end end -describe WeatherHacks::LWWS::Location do +describe "WeatherHacks::LWWS::Location" do before do - @location = WeatherHacks::LWWS::Forecast.new($today).location + @location = $today.location end - it "can read area as a String" do - @location.area.should be_a_kind_of(String) + it "area" do + @location.area.should.be.kind_of(String) end - it "can read pref as a String" do - @location.pref.should be_a_kind_of(String) + it "pref" do + @location.pref.should.be.kind_of(String) end - it "can read city as a String" do - @location.city.should be_a_kind_of(String) + it "city" do + @location.city.should.be.kind_of(String) end after do @location = nil end end -describe WeatherHacks::LWWS::Image do +describe "WeatherHacks::LWWS::Image" do before do - @image = WeatherHacks::LWWS::Forecast.new($today).image + @image = $today.image end - it "can read title as a String" do - @image.title.should be_a_kind_of(String) + after do + @image = nil end - it "can read link as a URI" do - @image.link.should be_a_kind_of(URI) + it "title" do + @image.title.should.be.kind_of(String) end - it "can read url as a URI" do - @image.url.should be_a_kind_of(URI) + it "link" do + @image.link.should.be.kind_of(URI) end - it "can read width as a Integer" do - @image.width.should be_a_kind_of(Integer) + it "url" do + @image.url.should.be.kind_of(URI) end - it "can read height as a Integer" do - @image.height.should be_a_kind_of(Integer) + it "width" do + @image.width.should.be.kind_of(Integer) end - after do - @image = nil + it "height" do + @image.height.should.be.kind_of(Integer) end end -describe WeatherHacks::LWWS::Temperature do +describe "WeatherHacks::LWWS::Temperature" do before do - forecast = WeatherHacks::LWWS::Forecast.new($today) - @celsius = forecast.celsius - @fahrenheit = forecast.fahrenheit + @celsius = $today.celsius + @fahrenheit = $today.fahrenheit end - it "can read min of celsius as a Integer" do - @celsius.min.should be_a_kind_of(Integer) if @celsius.min - + after do + @celsius = nil + @fahrenheit = nil end - it "can read max of celsius as a Integer" do - @celsius.max.should be_a_kind_of(Integer) if @celsius.max + it "min celsius" do + @celsius.min.should.be.kind_of(Integer) if @celsius.min end - it "can read min of fahrenheit as a Float" do - @fahrenheit.min.should be_a_kind_of(Float) if @fahrenheit.min + it "max celsius" do + @celsius.max.should.be.kind_of(Integer) if @celsius.max end - it "can read max of fahrenheit as a Float" do - @fahrenheit.max.should be_a_kind_of(Float) if @fahrenheit.max + it "min fahrenheit" do + @fahrenheit.min.should.be.kind_of(Float) if @fahrenheit.min end - after do - @celsius = nil - @fahrenheit = nil + it "max fahrenheit" do + @fahrenheit.max.should.be.kind_of(Float) if @fahrenheit.max end end -describe WeatherHacks::LWWS::PinpointLocation do +describe "WeatherHacks::LWWS::PinpointLocation" do before do - @pinpoints = WeatherHacks::LWWS::Forecast.new($today).pinpoints + @pinpoints = $today.pinpoints end - it "can read title as a String" do + after do + @pinpoints = nil + end + + it "title" do @pinpoints.each do |location| - location.title.should be_a_kind_of(String) + location.title.should.be.kind_of(String) end end - it "can read link as a URI" do + it "link" do @pinpoints.each do |location| - location.link.should be_a_kind_of(URI) + location.link.should.be.kind_of(URI) end end - it "can read publictime as a Time" do + it "publictime" do @pinpoints.each do |location| - location.publictime.should be_a_kind_of(Time) + location.publictime.should.be.kind_of(Time) end end - - after do - @pinpoints = nil - end end -describe WeatherHacks::LWWS::Copyright do +describe "WeatherHacks::LWWS::Copyright" do before do - @copyright = WeatherHacks::LWWS::Forecast.new($today).copyright + @copyright = $today.copyright end - it "can read title as a String" do - @copyright.title.should be_a_kind_of(String) + after do + @copyright = nil end - it "can read link as a URI" do - @copyright.link.should be_a_kind_of(URI) + it "title" do + @copyright.title.should.be.kind_of(String) end - it "can read image as a WeatherHacks::LWWS::Image" do - @copyright.image.should be_a_kind_of(WeatherHacks::LWWS::Image) + it "link" do + @copyright.link.should.be.kind_of(URI) end - it "can read providers as a list of WeatherHacks::LWWS::Provider" do + it "image" do + @copyright.image.should.be.kind_of(WeatherHacks::LWWS::Image) + end + + it "providers" do @copyright.providers.each do |provider| - provider.should be_a_kind_of(WeatherHacks::LWWS::Provider) + provider.should.be.kind_of(WeatherHacks::LWWS::Provider) end end - after do - @copyright = nil - end end -describe WeatherHacks::LWWS::Provider do +describe "WeatherHacks::LWWS::Provider" do before do - @provider = WeatherHacks::LWWS::Forecast.new($today).copyright.providers[0] + @provider = $today.copyright.providers[0] end - it "can read name as a String" do - @provider.name.should be_a_kind_of(String) + after do + @provider = nil end - it "can read link as a URI" do - @provider.link.should be_a_kind_of(URI) + it "name" do + @provider.name.should.be.kind_of(String) end - after do - @provider = nil + it "link" do + @provider.link.should.be.kind_of(URI) end end