regentanz 0.3.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +268 -0
- data/bin/regentanz +16 -0
- data/lib/regentanz.rb +10 -11
- data/lib/regentanz/cli/common.rb +35 -0
- data/lib/regentanz/cli/compare.rb +85 -0
- data/lib/regentanz/cli/compile.rb +27 -0
- data/lib/regentanz/template_compiler.rb +263 -0
- data/lib/regentanz/version.rb +1 -2
- data/lib/regentanz/yaml-ext.rb +18 -0
- data/spec/regentanz/resources/test/unloaded.rb +11 -0
- data/spec/regentanz/template_compiler_spec.rb +692 -0
- data/spec/spec_helper.rb +2 -0
- metadata +45 -152
- data/.gitignore +0 -5
- data/.rvmrc +0 -4
- data/CHANGELOG.rdoc +0 -26
- data/Gemfile +0 -4
- data/LICENSE +0 -24
- data/README.rdoc +0 -54
- data/Rakefile +0 -23
- data/lib/regentanz/astronomy.rb +0 -69
- data/lib/regentanz/cache.rb +0 -2
- data/lib/regentanz/cache/base.rb +0 -51
- data/lib/regentanz/cache/file.rb +0 -86
- data/lib/regentanz/callbacks.rb +0 -18
- data/lib/regentanz/conditions.rb +0 -3
- data/lib/regentanz/conditions/base.rb +0 -16
- data/lib/regentanz/conditions/current.rb +0 -14
- data/lib/regentanz/conditions/forecast.rb +0 -14
- data/lib/regentanz/configuration.rb +0 -55
- data/lib/regentanz/configurator.rb +0 -22
- data/lib/regentanz/google_weather.rb +0 -151
- data/lib/regentanz/parser.rb +0 -1
- data/lib/regentanz/parser/google_weather.rb +0 -100
- data/lib/regentanz/test_helper.rb +0 -52
- data/regentanz.gemspec +0 -30
- data/test/factories.rb +0 -6
- data/test/support/tmp/.gitignore +0 -1
- data/test/support/valid_response.xml.erb +0 -26
- data/test/test_helper.rb +0 -14
- data/test/unit/astronomy_test.rb +0 -26
- data/test/unit/cache/base_test.rb +0 -53
- data/test/unit/cache/file_test.rb +0 -141
- data/test/unit/callbacks_test.rb +0 -27
- data/test/unit/configuration_test.rb +0 -57
- data/test/unit/current_condition_test.rb +0 -33
- data/test/unit/forecast_condition_test.rb +0 -35
- data/test/unit/google_weather_test.rb +0 -125
- data/test/unit/parser/google_weather_parser_test.rb +0 -71
data/test/unit/callbacks_test.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class CallbacksTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@object = Object.new
|
7
|
-
@object.extend Regentanz::Callbacks
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_should_define_constant
|
11
|
-
assert Regentanz::Callbacks::CALLBACKS
|
12
|
-
expected_callbacks = [:api_failure_detected, :api_failure_resumed]
|
13
|
-
assert_equal expected_callbacks, Regentanz::Callbacks::CALLBACKS
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_google_weather_should_include_callbacks
|
17
|
-
assert Regentanz::GoogleWeather.included_modules.include?(Regentanz::Callbacks)
|
18
|
-
assert Regentanz::GoogleWeather.included_modules.include?(ActiveSupport::Callbacks)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_define_each_callback_method
|
22
|
-
Regentanz::Callbacks::CALLBACKS.each do |callback_method|
|
23
|
-
assert @object.private_methods.include?(callback_method.to_s), "#{callback_method} not defined"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
require "tmpdir"
|
3
|
-
|
4
|
-
class ConfigurationTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
test "should configure Regentanz" do
|
7
|
-
assert_respond_to Regentanz, :configure
|
8
|
-
assert_respond_to Regentanz, :configuration
|
9
|
-
assert_not_nil Regentanz.configuration
|
10
|
-
|
11
|
-
Regentanz.configure do |config|
|
12
|
-
config.do_not_get_weather = true
|
13
|
-
end
|
14
|
-
assert_not_nil Regentanz.configuration
|
15
|
-
assert Regentanz.configuration.do_not_get_weather
|
16
|
-
end
|
17
|
-
|
18
|
-
test "should have configuration" do
|
19
|
-
configuration_options = [
|
20
|
-
:base_url,
|
21
|
-
:cache_backend,
|
22
|
-
:cache_dir,
|
23
|
-
:cache_prefix,
|
24
|
-
:cache_ttl,
|
25
|
-
:retry_marker,
|
26
|
-
:retry_ttl,
|
27
|
-
:do_not_get_weather,
|
28
|
-
:suppress_stderr_output
|
29
|
-
]
|
30
|
-
assert_equal configuration_options, Regentanz::Configuration::OPTIONS, "Diff: #{configuration_options - Regentanz::Configuration::OPTIONS}"
|
31
|
-
obj = Regentanz::Configuration.new
|
32
|
-
configuration_options.each do |config_option|
|
33
|
-
assert_respond_to obj, config_option
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
test "every DEFAULT_OPTION should have a cattr_accessor" do
|
38
|
-
assert_not_nil Regentanz::Configuration::DEFAULT_OPTIONS
|
39
|
-
Regentanz::Configuration::DEFAULT_OPTIONS.each do |config_option|
|
40
|
-
assert_respond_to Regentanz::Configuration, :"default_#{config_option}"
|
41
|
-
assert_not_nil Regentanz::Configuration.send(:"default_#{config_option}")
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
test "instance should have sane defaults" do
|
47
|
-
obj = Regentanz::Configuration.new
|
48
|
-
tmpdir = Dir.tmpdir
|
49
|
-
assert_equal "http://www.google.com/ig/api", obj.base_url
|
50
|
-
assert_equal "#{tmpdir}", obj.cache_dir
|
51
|
-
assert_equal "regentanz", obj.cache_prefix
|
52
|
-
assert_equal 14400, obj.cache_ttl
|
53
|
-
assert_equal 3600, obj.retry_ttl
|
54
|
-
assert_equal "#{tmpdir}/regentanz_api_retry.txt", obj.retry_marker
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class CurrentConditionTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
test "should define setters and getters" do
|
6
|
-
obj = Regentanz::Conditions::Current.new
|
7
|
-
[:condition, :style, :icon, :humidity, :wind_condition, :temp_c, :temp_f].each do |attr|
|
8
|
-
assert_respond_to obj, attr
|
9
|
-
assert_respond_to obj, :"#{attr}="
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
test "should initialize with attributes hash" do
|
14
|
-
attributes = {
|
15
|
-
"condition" => "Klar",
|
16
|
-
"temp_f" => "77",
|
17
|
-
"temp_c" => "25",
|
18
|
-
"humidity" => "Feuchtigkeit: 57 %",
|
19
|
-
"icon" => "http://www.google.com/ig/images/weather/sunny.gif",
|
20
|
-
"style" => "sunny",
|
21
|
-
"wind_condition" => "Wind: W mit 24 km/h"
|
22
|
-
}
|
23
|
-
obj = Regentanz::Conditions::Current.new(attributes)
|
24
|
-
assert_equal "Klar", obj.condition
|
25
|
-
assert_equal 77, obj.temp_f
|
26
|
-
assert_equal 25, obj.temp_c
|
27
|
-
assert_equal "Feuchtigkeit: 57 %", obj.humidity
|
28
|
-
assert_equal "http://www.google.com/ig/images/weather/sunny.gif", obj.icon
|
29
|
-
assert_equal "sunny", obj.style
|
30
|
-
assert_equal "Wind: W mit 24 km/h", obj.wind_condition
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class ForecastConditionTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@object = Regentanz::Conditions::Forecast.new
|
7
|
-
end
|
8
|
-
|
9
|
-
test "should define setters and getters" do
|
10
|
-
[:condition, :style, :icon, :day_of_week, :high, :low].each do |attr|
|
11
|
-
assert_respond_to @object, attr
|
12
|
-
assert_respond_to @object, :"#{attr}="
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
test "should initialize with attributes hash" do
|
17
|
-
attributes = {
|
18
|
-
"high" => "31",
|
19
|
-
"condition" => "Vereinzelt Regen",
|
20
|
-
"icon" => "http://www.google.com/ig/images/weather/chance_of_rain.gif",
|
21
|
-
"day_of_week" =>"Do.",
|
22
|
-
"low" => "16",
|
23
|
-
"style" => "chance-of-rain"
|
24
|
-
}
|
25
|
-
|
26
|
-
obj = Regentanz::Conditions::Forecast.new(attributes)
|
27
|
-
assert_equal 31, obj.high
|
28
|
-
assert_equal "Vereinzelt Regen", obj.condition
|
29
|
-
assert_equal "http://www.google.com/ig/images/weather/chance_of_rain.gif", obj.icon
|
30
|
-
assert_equal "Do.", obj.day_of_week
|
31
|
-
assert_equal 16, obj.low
|
32
|
-
assert_equal "chance-of-rain", obj.style
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,125 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class GoogleWeatherTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
TEST_CACHE_FILE_NAME = File.join(Regentanz.configuration.cache_dir, "regentanz_test.xml")
|
6
|
-
|
7
|
-
def setup
|
8
|
-
setup_regentanz_test_configuration!
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
Dir.glob(File.join(Regentanz.configuration.cache_dir, "**", "*")).each { |file| File.delete(file) }
|
13
|
-
end
|
14
|
-
|
15
|
-
test "should initialize with options hash" do
|
16
|
-
Regentanz::GoogleWeather.any_instance.expects(:get_weather).never()
|
17
|
-
options = { :location => "Test Valley", :lang => "es" }
|
18
|
-
obj = Regentanz::GoogleWeather.new(options)
|
19
|
-
assert_equal "Test Valley", obj.location
|
20
|
-
assert_equal "es", obj.lang
|
21
|
-
end
|
22
|
-
|
23
|
-
test "should be compatible with old constructor" do
|
24
|
-
Regentanz::GoogleWeather.any_instance.expects(:get_weather).never()
|
25
|
-
obj = Factory(:google_weather, :location => "Test Valley")
|
26
|
-
assert_equal "Test Valley", obj.location
|
27
|
-
assert_equal "de", obj.lang
|
28
|
-
end
|
29
|
-
|
30
|
-
test "should have cache instance" do
|
31
|
-
obj = Factory(:google_weather)
|
32
|
-
assert_respond_to obj, :cache
|
33
|
-
assert_kind_of Regentanz.configuration.cache_backend, obj.cache
|
34
|
-
end
|
35
|
-
|
36
|
-
test "should enter retry state if invalid xml file has been found" do
|
37
|
-
stub_valid_xml_api_response!
|
38
|
-
Regentanz::GoogleWeather.any_instance.expects(:api_failure_detected) # callback
|
39
|
-
|
40
|
-
weather = Factory(:google_weather)
|
41
|
-
assert !weather.waiting_for_retry?
|
42
|
-
create_invalid_xml_response(TEST_CACHE_FILE_NAME)
|
43
|
-
|
44
|
-
weather.get_weather!
|
45
|
-
assert weather.waiting_for_retry?
|
46
|
-
end
|
47
|
-
|
48
|
-
test "should leave retry state remove invalid cache file when retry_ttl waittime is over" do
|
49
|
-
File.new(Regentanz.configuration.retry_marker, "w+").close
|
50
|
-
assert File.exists?(Regentanz.configuration.retry_marker) # ensure test setup
|
51
|
-
Regentanz.configuration.retry_ttl = 0; sleep 0.1
|
52
|
-
Regentanz::GoogleWeather.any_instance.expects(:api_failure_resumed) # callback
|
53
|
-
|
54
|
-
create_invalid_xml_response(TEST_CACHE_FILE_NAME)
|
55
|
-
weather = Factory(:google_weather)
|
56
|
-
|
57
|
-
weather.get_weather!
|
58
|
-
assert !weather.waiting_for_retry?
|
59
|
-
end
|
60
|
-
|
61
|
-
test "should have lang option" do
|
62
|
-
weather = Factory(:google_weather, :lang => :es)
|
63
|
-
assert_equal "es", weather.lang
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_should_calculate_sunrise_and_sunset_based_on_geodata
|
67
|
-
weather = Regentanz::GoogleWeather.new("Berlin", weather_options(:geo_location => nil) )
|
68
|
-
assert weather.respond_to? :sunrise
|
69
|
-
assert weather.respond_to? :sunset
|
70
|
-
assert_nil weather.sunrise
|
71
|
-
assert_nil weather.sunset
|
72
|
-
|
73
|
-
lat = 52.5163253260716
|
74
|
-
lng = 13.3780860900879
|
75
|
-
|
76
|
-
weather = Regentanz::GoogleWeather.new("Berlin", weather_options(:geodata => {:lat => lat, :lng => lng}) )
|
77
|
-
assert weather.sunrise.is_a? Time
|
78
|
-
assert weather.sunset.is_a? Time
|
79
|
-
end
|
80
|
-
|
81
|
-
test "should set default cache_id by location" do
|
82
|
-
obj = Regentanz::GoogleWeather.new(:location => "Test Valley", :cache_id => nil)
|
83
|
-
assert_not_nil obj.cache_id
|
84
|
-
end
|
85
|
-
|
86
|
-
test "should work with caching disabled" do
|
87
|
-
Regentanz.configuration.cache_backend = nil
|
88
|
-
stub_valid_xml_api_response!
|
89
|
-
obj = Factory(:google_weather, :cache_id => nil)
|
90
|
-
assert_nil obj.cache
|
91
|
-
obj.get_weather!
|
92
|
-
end
|
93
|
-
|
94
|
-
test "should delegate retry state to cache instance" do
|
95
|
-
obj = Factory(:google_weather)
|
96
|
-
assert_respond_to obj, :waiting_for_retry?
|
97
|
-
assert_not_nil obj.cache
|
98
|
-
assert !obj.waiting_for_retry?
|
99
|
-
obj.cache.expects(:waiting_for_retry?).returns(true)
|
100
|
-
assert obj.waiting_for_retry?
|
101
|
-
end
|
102
|
-
|
103
|
-
test "should respond_to present?" do
|
104
|
-
obj = Factory(:google_weather)
|
105
|
-
assert_respond_to obj, :present?
|
106
|
-
|
107
|
-
Regentanz::GoogleWeather.any_instance.expects(:current).returns(nil)
|
108
|
-
Regentanz::GoogleWeather.any_instance.expects(:forecast).returns(nil)
|
109
|
-
assert_equal false, obj.present?
|
110
|
-
|
111
|
-
Regentanz::GoogleWeather.any_instance.expects(:current).returns(nil)
|
112
|
-
Regentanz::GoogleWeather.any_instance.expects(:forecast).returns(true)
|
113
|
-
assert_equal true, obj.present?
|
114
|
-
Regentanz::GoogleWeather.any_instance.expects(:current).returns(true)
|
115
|
-
assert_equal true, obj.present?
|
116
|
-
end
|
117
|
-
|
118
|
-
private
|
119
|
-
|
120
|
-
# Return a few default options for the test environment
|
121
|
-
def weather_options(options = {})
|
122
|
-
{:cache_id => "test"}.merge(options.symbolize_keys!)
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
-
|
3
|
-
class GoogleWeatherParserTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
setup_regentanz_test_configuration!
|
7
|
-
end
|
8
|
-
|
9
|
-
test "should have parser instance" do
|
10
|
-
obj = Regentanz::GoogleWeather.new
|
11
|
-
assert_respond_to obj, :parser
|
12
|
-
assert_not_nil obj.parser
|
13
|
-
assert_kind_of Regentanz::Parser::GoogleWeather, obj.parser
|
14
|
-
end
|
15
|
-
|
16
|
-
test "should convert encoding" do
|
17
|
-
obj = Regentanz::Parser::GoogleWeather.new
|
18
|
-
assert_respond_to obj, :convert_encoding
|
19
|
-
assert_nil obj.convert_encoding(nil)
|
20
|
-
assert_nil obj.convert_encoding("")
|
21
|
-
# FIXME test actual conversion
|
22
|
-
end
|
23
|
-
|
24
|
-
test "should parse xml for current condition" do
|
25
|
-
obj = Regentanz::Parser::GoogleWeather.new
|
26
|
-
assert_respond_to obj, :parse_current!
|
27
|
-
assert_nil obj.parse_current!(nil)
|
28
|
-
assert_nil obj.parse_current!("")
|
29
|
-
|
30
|
-
xml = valid_xml_response
|
31
|
-
parsed = obj.parse_current!(xml)
|
32
|
-
assert_kind_of Regentanz::Conditions::Current, parsed
|
33
|
-
assert_equal "Feuchtigkeit: 57 %", parsed.humidity
|
34
|
-
assert_equal "Wind: W mit 24 km/h", parsed.wind_condition
|
35
|
-
assert_equal 25, parsed.temp_c
|
36
|
-
assert_equal 77, parsed.temp_f
|
37
|
-
assert_equal "http://www.google.com/ig/images/weather/sunny.gif", parsed.icon
|
38
|
-
assert_equal "Klar", parsed.condition
|
39
|
-
end
|
40
|
-
|
41
|
-
test "should rescue current condition parsing from parse erros" do
|
42
|
-
obj = Regentanz::Parser::GoogleWeather.new
|
43
|
-
xml = invalid_xml_response
|
44
|
-
assert_nothing_raised { assert_nil obj.parse_current!(xml) }
|
45
|
-
end
|
46
|
-
|
47
|
-
test "should parse xml for forecast" do
|
48
|
-
obj = Regentanz::Parser::GoogleWeather.new
|
49
|
-
assert_respond_to obj, :parse_forecast!
|
50
|
-
assert_nil obj.parse_forecast!(nil)
|
51
|
-
assert_nil obj.parse_forecast!("")
|
52
|
-
|
53
|
-
xml = valid_xml_response
|
54
|
-
parsed = obj.parse_forecast!(xml)
|
55
|
-
assert_kind_of Array, parsed
|
56
|
-
assert_equal 1, parsed.size
|
57
|
-
assert_kind_of Regentanz::Conditions::Forecast, parsed.first
|
58
|
-
assert_equal "Do.", parsed.first.day_of_week
|
59
|
-
assert_equal 31, parsed.first.high
|
60
|
-
assert_equal 16, parsed.first.low
|
61
|
-
assert_equal "http://www.google.com/ig/images/weather/chance_of_rain.gif", parsed.first.icon
|
62
|
-
assert_equal "Vereinzelt Regen", parsed.first.condition
|
63
|
-
end
|
64
|
-
|
65
|
-
test "should rescue forecast parsing from parse erros" do
|
66
|
-
obj = Regentanz::Parser::GoogleWeather.new
|
67
|
-
xml = invalid_xml_response
|
68
|
-
assert_nothing_raised { assert_nil obj.parse_forecast!(xml) }
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|