weatherzone 0.6.3 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/weatherzone.rb CHANGED
@@ -35,5 +35,5 @@ require 'weatherzone/helpers/date_parser'
35
35
  require 'weatherzone/helpers/units'
36
36
 
37
37
  module Weatherzone
38
- VERSION = '0.6.3'
38
+ VERSION = '0.6.5'
39
39
  end
@@ -3,9 +3,10 @@ require 'singleton'
3
3
  module Weatherzone
4
4
 
5
5
  class RequestFailed < Exception
6
- attr_reader :message
7
- def initialize(url)
8
- @message = "Failed to retreive #{url} and no cached version available"
6
+ attr_reader :message, :original_exception
7
+ def initialize(url, original_exception)
8
+ @message = "Failed to retreive #{url} and no cached version available"
9
+ @original_exception = original_exception
9
10
  end
10
11
  end
11
12
 
@@ -64,22 +65,22 @@ module Weatherzone
64
65
  response = OpenURI::open(url)
65
66
  response.read
66
67
  end
67
- rescue Timeout::Error, SocketError
68
- error("webservice connection failed")
69
- raise RequestFailed.new(url)
68
+ rescue Timeout::Error, SocketError => e
69
+ error("webservice connection failed #{e}")
70
+ raise RequestFailed.new(url, e)
70
71
  end
71
72
 
72
- def debug(message)
73
- @logger.debug("[weatherzone] #{message}") if @logger
73
+ def debug(message)
74
+ @logger.debug("[weatherzone] [DEBUG] #{message}") if @logger
74
75
  end
75
76
 
76
77
  def info(message)
77
- @logger.info("[weatherzone] #{message}") if @logger
78
+ @logger.info("[weatherzone] [INFO] #{message}") if @logger
78
79
  end
79
80
 
80
81
  def error(message)
81
- @logger.error("[weatherzone] #{message}") if @logger
82
+ @logger.error("[weatherzone] [ERROR] #{message}") if @logger
82
83
  end
83
-
84
+
84
85
  end
85
86
  end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/support/dependencies.rb'
2
+
3
+ class TestExceptions < Test::Unit::TestCase
4
+
5
+ def setup
6
+ Weatherzone::Connection.connect(ENV['WZ_USER'], ENV['WZ_PASS'], :url => ENV['WZ_URL'], :timeout_after => 10) do
7
+ eval(File.open(File.dirname(__FILE__) + '/../.wzkey.rb', 'r').read)
8
+ end
9
+ @connection = Weatherzone::Connection.instance
10
+ end
11
+
12
+ def test_should_have_credentials
13
+ assert ENV['WZ_USER'], "You need to set the WZ_USER environment variable to run these tests"
14
+ assert ENV['WZ_PASS'], "You need to set the WZ_PASS environment variable to run these tests"
15
+ assert ENV['WZ_URL'], "You need to set the WZ_URL environment variable to run these tests"
16
+ end
17
+
18
+ def test_should_have_keygen
19
+ File.open(File.dirname(__FILE__) + '/../.wzkey.rb', 'r')
20
+ rescue Exception
21
+ assert false, "You need to create #{File.dirname(__FILE__) + '/../.wzkey.rb'} to run these tests"
22
+ end
23
+
24
+ def test_request_failed_should_capture_original_exception
25
+ timeout(0.1) do
26
+ sleep(1)
27
+ end
28
+ rescue Exception => e
29
+ begin
30
+ raise Weatherzone::RequestFailed.new("url", e)
31
+ rescue Weatherzone::RequestFailed => weatherzone_exception
32
+ assert_instance_of Timeout::Error, weatherzone_exception.original_exception
33
+ end
34
+ end
35
+
36
+ def test_connection_should_raise_request_failed_on_timeout
37
+ @connection.timeout_after = 0.1
38
+ assert_raises Weatherzone::RequestFailed do
39
+ Weather.find_by_location_name("Sydney")
40
+ end
41
+ end
42
+
43
+ end
data/test/test_helper.rb CHANGED
@@ -1,35 +1,4 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
- require 'mocha'
4
- require 'logger'
5
- require 'ruby-debug'
6
-
7
- require File.dirname(__FILE__) + '/../lib/weatherzone'
8
-
9
- require 'weatherzone/resources/point_forecast'
10
- require 'weatherzone/resources/forecast'
11
- require 'weatherzone/resources/conditions'
12
- require 'weatherzone/resources/district_forecast'
13
- require 'weatherzone/resources/state_forecast'
14
- require 'weatherzone/resources/marine_summary'
15
- require 'weatherzone/resources/marine_forecast'
16
- require 'weatherzone/resources/surf_report'
17
- require 'weatherzone/resources/lift'
18
- require 'weatherzone/resources/snow_report'
19
- require 'weatherzone/resources/historical_observation'
20
- require 'weatherzone/resources/daily_observation'
21
- require 'weatherzone/resources/climate_period'
22
- require 'weatherzone/resources/warning'
23
- require 'weatherzone/resources/image'
24
- require 'weatherzone/resources/almanac_period'
25
- require 'weatherzone/resources/almanac'
26
- require 'weatherzone/resources/tide'
27
- require 'weatherzone/resources/buoy_observation'
28
- require 'weatherzone/resources/location'
29
- require 'weatherzone/resources/country'
30
- require 'weatherzone/resources/moon_phase'
31
- require 'weatherzone/resources/news_item'
32
- require 'weatherzone/resources/weather'
1
+ require File.dirname(__FILE__) + '/support/dependencies.rb'
33
2
 
34
3
  class Test::Unit::TestCase
35
4
  def setup
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 3
9
- version: 0.6.3
8
+ - 5
9
+ version: 0.6.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ben Askins
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-24 00:00:00 +11:00
17
+ date: 2010-04-20 00:00:00 +10:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -137,6 +137,7 @@ test_files:
137
137
  - test/test_country.rb
138
138
  - test/test_daily_observation.rb
139
139
  - test/test_district_forecast.rb
140
+ - test/test_exceptions.rb
140
141
  - test/test_farenheit_conversion_factor.rb
141
142
  - test/test_file_parser.rb
142
143
  - test/test_finder.rb