holidays 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +22 -8
  4. data/Rakefile +26 -8
  5. data/bin/console +7 -0
  6. data/bin/setup +5 -0
  7. data/{data → definitions}/SYNTAX.rdoc +0 -0
  8. data/{data → definitions}/ar.yaml +0 -0
  9. data/{data → definitions}/at.yaml +1 -1
  10. data/{data → definitions}/au.yaml +80 -51
  11. data/{data → definitions}/be.yaml +0 -0
  12. data/{data → definitions}/br.yaml +0 -0
  13. data/{data → definitions}/ca.yaml +0 -0
  14. data/{data → definitions}/ch.yaml +0 -0
  15. data/{data → definitions}/cl.yaml +0 -0
  16. data/{data → definitions}/cr.yaml +0 -0
  17. data/{data → definitions}/cz.yaml +0 -0
  18. data/{data → definitions}/de.yaml +25 -34
  19. data/{data → definitions}/dk.yaml +0 -0
  20. data/{data → definitions}/ecb_target.yaml +2 -2
  21. data/{data → definitions}/el.yaml +0 -0
  22. data/{data → definitions}/es.yaml +37 -26
  23. data/{data → definitions}/federal_reserve.yaml +0 -0
  24. data/{data → definitions}/fedex.yaml +9 -3
  25. data/{data → definitions}/fi.yaml +0 -0
  26. data/{data → definitions}/fr.yaml +0 -0
  27. data/{data → definitions}/gb.yaml +19 -19
  28. data/{data → definitions}/hr.yaml +0 -0
  29. data/{data → definitions}/hu.yaml +1 -1
  30. data/{data → definitions}/ie.yaml +0 -0
  31. data/{data → definitions}/index.yaml +0 -0
  32. data/{data → definitions}/is.yaml +0 -0
  33. data/{data → definitions}/it.yaml +0 -0
  34. data/{data → definitions}/jp.yaml +3 -3
  35. data/{data → definitions}/li.yaml +3 -3
  36. data/{data → definitions}/lt.yaml +0 -0
  37. data/{data → definitions}/ma.yaml +0 -0
  38. data/{data → definitions}/mx.yaml +0 -0
  39. data/{data → definitions}/nerc.yaml +0 -0
  40. data/{data → definitions}/nl.yaml +0 -0
  41. data/{data → definitions}/no.yaml +0 -0
  42. data/{data → definitions}/north_america_informal.yaml +0 -0
  43. data/{data → definitions}/nyse.yaml +0 -0
  44. data/{data → definitions}/nz.yaml +21 -10
  45. data/{data → definitions}/ph.yaml +0 -0
  46. data/{data → definitions}/pl.yaml +0 -0
  47. data/{data → definitions}/pt.yaml +0 -0
  48. data/{data → definitions}/ro.yaml +1 -2
  49. data/{data → definitions}/se.yaml +0 -0
  50. data/{data → definitions}/sg.yaml +0 -0
  51. data/{data → definitions}/si.yaml +6 -6
  52. data/{data → definitions}/sk.yaml +0 -0
  53. data/{data → definitions}/united_nations.yaml +0 -0
  54. data/{data → definitions}/ups.yaml +17 -11
  55. data/{data → definitions}/us.yaml +20 -15
  56. data/{data → definitions}/ve.yaml +0 -0
  57. data/{data → definitions}/vi.yaml +0 -0
  58. data/{data → definitions}/za.yaml +0 -0
  59. data/holidays.gemspec +2 -1
  60. data/lib/generated_definitions/MANIFEST +56 -0
  61. data/lib/generated_definitions/REGIONS.rb +4 -0
  62. data/lib/{holidays → generated_definitions}/ar.rb +2 -2
  63. data/lib/{holidays → generated_definitions}/at.rb +2 -2
  64. data/lib/{holidays → generated_definitions}/au.rb +19 -10
  65. data/lib/{holidays → generated_definitions}/be.rb +2 -2
  66. data/lib/{holidays → generated_definitions}/br.rb +2 -2
  67. data/lib/{holidays → generated_definitions}/ca.rb +2 -2
  68. data/lib/{holidays → generated_definitions}/ch.rb +2 -2
  69. data/lib/{holidays → generated_definitions}/cl.rb +2 -2
  70. data/lib/{holidays → generated_definitions}/cr.rb +2 -2
  71. data/lib/{holidays → generated_definitions}/cz.rb +2 -2
  72. data/lib/{holidays → generated_definitions}/de.rb +5 -4
  73. data/lib/{holidays → generated_definitions}/dk.rb +2 -2
  74. data/lib/{holidays → generated_definitions}/ecb_target.rb +2 -2
  75. data/lib/{holidays → generated_definitions}/el.rb +2 -2
  76. data/lib/{holidays → generated_definitions}/es.rb +6 -6
  77. data/lib/{holidays → generated_definitions}/europe.rb +7 -6
  78. data/lib/{holidays → generated_definitions}/fed_ex.rb +8 -3
  79. data/lib/{holidays → generated_definitions}/federal_reserve.rb +2 -2
  80. data/lib/{holidays → generated_definitions}/fi.rb +2 -2
  81. data/lib/{holidays → generated_definitions}/fr.rb +2 -2
  82. data/lib/{holidays → generated_definitions}/gb.rb +2 -2
  83. data/lib/{holidays → generated_definitions}/hr.rb +2 -2
  84. data/lib/{holidays → generated_definitions}/hu.rb +2 -2
  85. data/lib/{holidays → generated_definitions}/ie.rb +2 -2
  86. data/lib/{holidays → generated_definitions}/is.rb +2 -2
  87. data/lib/{holidays → generated_definitions}/it.rb +2 -2
  88. data/lib/{holidays → generated_definitions}/jp.rb +5 -5
  89. data/lib/{holidays → generated_definitions}/li.rb +2 -2
  90. data/lib/{holidays → generated_definitions}/lt.rb +2 -2
  91. data/lib/{holidays → generated_definitions}/ma.rb +2 -2
  92. data/lib/{holidays → generated_definitions}/mx.rb +2 -2
  93. data/lib/{holidays → generated_definitions}/nerc.rb +2 -2
  94. data/lib/{holidays → generated_definitions}/nl.rb +2 -2
  95. data/lib/{holidays → generated_definitions}/no.rb +2 -2
  96. data/lib/{holidays → generated_definitions}/north_america.rb +8 -3
  97. data/lib/{holidays → generated_definitions}/nyse.rb +2 -2
  98. data/lib/{holidays → generated_definitions}/nz.rb +5 -5
  99. data/lib/{holidays → generated_definitions}/ph.rb +2 -2
  100. data/lib/{holidays → generated_definitions}/pl.rb +2 -2
  101. data/lib/{holidays → generated_definitions}/pt.rb +2 -2
  102. data/lib/{holidays → generated_definitions}/ro.rb +2 -2
  103. data/lib/{holidays → generated_definitions}/scandinavia.rb +2 -2
  104. data/lib/{holidays → generated_definitions}/se.rb +2 -2
  105. data/lib/{holidays → generated_definitions}/sg.rb +2 -2
  106. data/lib/{holidays → generated_definitions}/si.rb +2 -2
  107. data/lib/{holidays → generated_definitions}/sk.rb +2 -2
  108. data/lib/{holidays → generated_definitions}/united_nations.rb +2 -2
  109. data/lib/{holidays → generated_definitions}/ups.rb +8 -3
  110. data/lib/{holidays → generated_definitions}/us.rb +8 -3
  111. data/lib/{holidays → generated_definitions}/ve.rb +2 -2
  112. data/lib/{holidays → generated_definitions}/vi.rb +2 -2
  113. data/lib/{holidays → generated_definitions}/za.rb +2 -2
  114. data/lib/holidays.rb +120 -665
  115. data/lib/holidays/core_extensions/date.rb +39 -0
  116. data/lib/holidays/date_calculator/day_of_month.rb +68 -0
  117. data/lib/holidays/date_calculator/easter.rb +58 -0
  118. data/lib/holidays/date_calculator/weekend_modifier.rb +49 -0
  119. data/lib/holidays/date_calculator_factory.rb +21 -0
  120. data/lib/holidays/definition/context/generator.rb +216 -0
  121. data/lib/holidays/definition/context/merger.rb +26 -0
  122. data/lib/holidays/definition/repository/cache.rb +33 -0
  123. data/lib/holidays/definition/repository/holidays_by_month.rb +49 -0
  124. data/lib/holidays/definition/repository/proc_cache.rb +36 -0
  125. data/lib/holidays/definition/repository/regions.rb +36 -0
  126. data/lib/holidays/definition/validator/region.rb +45 -0
  127. data/lib/holidays/definition_factory.rb +50 -0
  128. data/lib/holidays/option/context/parse_options.rb +96 -0
  129. data/lib/holidays/option_factory.rb +14 -0
  130. data/lib/holidays/use_case/context/between.rb +105 -0
  131. data/lib/holidays/use_case/context/dates_driver_builder.rb +64 -0
  132. data/lib/holidays/use_case_factory.rb +20 -0
  133. data/lib/holidays/version.rb +1 -1
  134. data/test/defs/test_defs_ar.rb +1 -1
  135. data/test/defs/test_defs_at.rb +2 -2
  136. data/test/defs/test_defs_au.rb +61 -43
  137. data/test/defs/test_defs_be.rb +1 -1
  138. data/test/defs/test_defs_br.rb +1 -1
  139. data/test/defs/test_defs_ca.rb +1 -1
  140. data/test/defs/test_defs_ch.rb +1 -1
  141. data/test/defs/test_defs_cl.rb +1 -1
  142. data/test/defs/test_defs_cr.rb +1 -1
  143. data/test/defs/test_defs_cz.rb +1 -1
  144. data/test/defs/test_defs_de.rb +18 -30
  145. data/test/defs/test_defs_dk.rb +1 -1
  146. data/test/defs/test_defs_ecb_target.rb +3 -3
  147. data/test/defs/test_defs_el.rb +1 -1
  148. data/test/defs/test_defs_es.rb +36 -25
  149. data/test/defs/test_defs_europe.rb +82 -84
  150. data/test/defs/test_defs_fed_ex.rb +4 -1
  151. data/test/defs/test_defs_federal_reserve.rb +1 -1
  152. data/test/defs/test_defs_fi.rb +1 -1
  153. data/test/defs/test_defs_fr.rb +1 -1
  154. data/test/defs/test_defs_gb.rb +20 -20
  155. data/test/defs/test_defs_hr.rb +1 -1
  156. data/test/defs/test_defs_hu.rb +2 -2
  157. data/test/defs/test_defs_ie.rb +1 -1
  158. data/test/defs/test_defs_is.rb +1 -1
  159. data/test/defs/test_defs_it.rb +1 -1
  160. data/test/defs/test_defs_jp.rb +1 -1
  161. data/test/defs/test_defs_li.rb +4 -4
  162. data/test/defs/test_defs_lt.rb +1 -1
  163. data/test/defs/test_defs_ma.rb +1 -1
  164. data/test/defs/test_defs_mx.rb +1 -1
  165. data/test/defs/test_defs_nerc.rb +1 -1
  166. data/test/defs/test_defs_nl.rb +1 -1
  167. data/test/defs/test_defs_no.rb +1 -1
  168. data/test/defs/test_defs_north_america.rb +5 -3
  169. data/test/defs/test_defs_nyse.rb +1 -1
  170. data/test/defs/test_defs_nz.rb +19 -9
  171. data/test/defs/test_defs_ph.rb +1 -1
  172. data/test/defs/test_defs_pl.rb +1 -1
  173. data/test/defs/test_defs_pt.rb +1 -1
  174. data/test/defs/test_defs_ro.rb +2 -3
  175. data/test/defs/test_defs_scandinavia.rb +1 -1
  176. data/test/defs/test_defs_se.rb +1 -1
  177. data/test/defs/test_defs_sg.rb +1 -1
  178. data/test/defs/test_defs_si.rb +7 -7
  179. data/test/defs/test_defs_sk.rb +1 -1
  180. data/test/defs/test_defs_united_nations.rb +1 -1
  181. data/test/defs/test_defs_ups.rb +5 -2
  182. data/test/defs/test_defs_us.rb +5 -3
  183. data/test/defs/test_defs_ve.rb +1 -1
  184. data/test/defs/test_defs_vi.rb +1 -1
  185. data/test/defs/test_defs_za.rb +1 -1
  186. data/test/{test_date.rb → holidays/core_extensions/test_date.rb} +8 -2
  187. data/test/holidays/date_calculator/test_day_of_month.rb +27 -0
  188. data/test/holidays/date_calculator/test_easter.rb +29 -0
  189. data/test/holidays/date_calculator/test_weekend_modifier.rb +33 -0
  190. data/test/holidays/definition/context/test_generator.rb +84 -0
  191. data/test/holidays/definition/context/test_merger.rb +22 -0
  192. data/test/holidays/definition/repository/test_cache.rb +82 -0
  193. data/test/holidays/definition/repository/test_holidays_by_month.rb +187 -0
  194. data/test/holidays/definition/repository/test_proc_cache.rb +29 -0
  195. data/test/holidays/definition/repository/test_regions.rb +86 -0
  196. data/test/holidays/definition/validator/test_region.rb +50 -0
  197. data/test/holidays/option/context/test_parse_options.rb +69 -0
  198. data/test/holidays/test_date_calculator_factory.rb +21 -0
  199. data/test/holidays/test_definition_factory.rb +34 -0
  200. data/test/holidays/test_option_factory.rb +9 -0
  201. data/test/holidays/test_use_case_factory.rb +13 -0
  202. data/test/holidays/use_case/context/test_between.rb +75 -0
  203. data/test/holidays/use_case/context/test_dates_driver_builder.rb +91 -0
  204. data/test/test_all_regions.rb +14 -3
  205. data/test/test_helper.rb +2 -1
  206. data/test/test_holidays.rb +19 -24
  207. data/test/test_holidays_between.rb +85 -0
  208. data/test/test_multiple_regions.rb +2 -2
  209. data/test/test_parse_definitions.rb +10 -4
  210. metadata +181 -111
  211. data/.coveralls.yml +0 -1
  212. data/lib/holidays/MANIFEST +0 -55
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
3
3
  class MultipleRegionsTests < Test::Unit::TestCase
4
4
 
5
5
  def test_definition_dir
6
- assert File.directory?(Holidays::DEFINITION_PATH)
6
+ assert File.directory?(Holidays::FULL_DEFINITIONS_PATH)
7
7
  end
8
8
 
9
9
  def test_getting_available_paths
@@ -27,7 +27,6 @@ class MultipleRegionsTests < Test::Unit::TestCase
27
27
  assert defs.include?(:united_nations)
28
28
  end
29
29
 
30
-
31
30
  def test_loading_all
32
31
  Holidays.load_all
33
32
  holidays = Holidays.on(Date.civil(2011, 5, 1), :any)
@@ -59,8 +58,20 @@ class MultipleRegionsTests < Test::Unit::TestCase
59
58
  assert holidays.any? { |h| h[:name] == 'Neujahrstag' }
60
59
  end
61
60
 
61
+ def test_unknown_region_raises_exception
62
+ assert_raise Holidays::UnknownRegionError do
63
+ Holidays.on(Date.civil(2014, 1, 1), :something_we_do_not_recognize)
64
+ end
65
+ end
66
+
67
+ def test_malicious_load_attempt_raises_exception
68
+ assert_raise Holidays::UnknownRegionError do
69
+ Holidays.between(Date.civil(2014, 1, 1), Date.civil(2016, 1, 1), '../../../../../../../../../../../../tmp/profile_pic.jpg')
70
+ end
71
+ end
72
+
62
73
  private
63
74
  def def_count
64
- Dir.glob(Holidays::DEFINITION_PATH + '/*.rb').size
75
+ Dir.glob(Holidays::FULL_DEFINITIONS_PATH + '/*.rb').size
65
76
  end
66
77
  end
data/test/test_helper.rb CHANGED
@@ -7,9 +7,10 @@ $KCODE = 'u' if RUBY_VERSION =~ /^1\.8/
7
7
 
8
8
  require 'rubygems'
9
9
  require 'test/unit'
10
+ require 'mocha/test_unit'
10
11
  require 'date'
11
12
  require 'holidays'
12
- require 'holidays/ca'
13
+ require "#{Holidays::DEFINITIONS_PATH}/ca"
13
14
 
14
15
  module Holidays
15
16
  # Test region used for generating a holiday on Date.today
@@ -1,10 +1,10 @@
1
1
  require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
2
 
3
- require 'holidays/ca'
3
+ require "#{Holidays::DEFINITIONS_PATH}/ca"
4
4
 
5
5
  # Re-include CA defs via holidays/north_america to ensure that individual
6
6
  # defs aren't duplicated.
7
- require 'holidays/north_america'
7
+ require "#{Holidays::DEFINITIONS_PATH}/north_america"
8
8
 
9
9
  class HolidaysTests < Test::Unit::TestCase
10
10
  def setup
@@ -19,17 +19,6 @@ class HolidaysTests < Test::Unit::TestCase
19
19
  assert_equal 0, holidays.length
20
20
  end
21
21
 
22
- def test_between
23
- holidays = Holidays.between(Date.civil(2008,7,1), Date.civil(2008,7,1), :ca)
24
- assert_equal 1, holidays.length
25
-
26
- holidays = Holidays.between(Date.civil(2008,7,1), Date.civil(2008,7,31), :ca)
27
- assert_equal 1, holidays.length
28
-
29
- holidays = Holidays.between(Date.civil(2008,7,2), Date.civil(2008,7,31), :ca)
30
- assert_equal 0, holidays.length
31
- end
32
-
33
22
  def test_full_week
34
23
  ## Full weeks:
35
24
  # Try with a Monday
@@ -40,7 +29,7 @@ class HolidaysTests < Test::Unit::TestCase
40
29
  assert Holidays.full_week?(Date.civil(2012,1,29), :us)
41
30
  # Try Wednesday on a week going into a new month
42
31
  assert Holidays.full_week?(Date.civil(2012,2,1), :us)
43
-
32
+
44
33
  ## Weeks with holidays:
45
34
  # New Year's 2012 (on Sunday, observed Monday). Test from a Wednesday.
46
35
  assert_equal(false, Holidays.full_week?(Date.civil(2012,1,4), :us))
@@ -53,7 +42,7 @@ class HolidaysTests < Test::Unit::TestCase
53
42
  holidays_in_2012 = weeks_in_2012.times.count { |week| Holidays.full_week?(Date.commercial(2012,week+1), :us) == false }
54
43
  assert_equal 10, holidays_in_2012
55
44
  end
56
-
45
+
57
46
  def test_requires_valid_regions
58
47
  assert_raises Holidays::UnknownRegionError do
59
48
  Holidays.on(Date.civil(2008,1,1), :xx)
@@ -75,7 +64,7 @@ class HolidaysTests < Test::Unit::TestCase
75
64
  holidays = Holidays.on(@date, [:ca_bc,:ca])
76
65
  assert_equal 1, holidays.length
77
66
  end
78
-
67
+
79
68
  def test_observed_dates
80
69
  # Should fall on Tuesday the 1st
81
70
  assert_equal 1, Holidays.on(Date.civil(2008,7,1), :ca, :observed).length
@@ -100,7 +89,7 @@ class HolidaysTests < Test::Unit::TestCase
100
89
  holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31))
101
90
  assert holidays.length >= 3
102
91
  end
103
-
92
+
104
93
  def test_sub_regions
105
94
  # Should return Victoria Day.
106
95
  holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca)
@@ -126,7 +115,7 @@ class HolidaysTests < Test::Unit::TestCase
126
115
  assert_equal '2067-04-03', Holidays.easter(2067).to_s
127
116
  assert_equal '2099-04-12', Holidays.easter(2099).to_s
128
117
  end
129
-
118
+
130
119
  def test_orthodox_easter
131
120
  assert_equal '2000-04-30', Holidays.orthodox_easter(2000).to_s
132
121
  assert_equal '2008-04-27', Holidays.orthodox_easter(2008).to_s
@@ -158,15 +147,21 @@ class HolidaysTests < Test::Unit::TestCase
158
147
  }
159
148
  end
160
149
 
150
+ #FIXME - I am not a huge fan of this test as it is written. It depends on the definitions not changing.
151
+ # I think that this is fine for an integration test but I think it should be labeled as such.
161
152
  def test_caching
153
+ start_date = Date.civil(2008, 3, 21)
154
+ end_date = Date.civil(2008, 3, 25)
155
+ cache_data = Holidays.between(start_date, end_date, :ca, :informal)
156
+ options = [:ca, :informal]
157
+
158
+ Holidays::DefinitionFactory.cache_repository.expects(:cache_between).with(start_date, end_date, cache_data, options)
159
+
162
160
  Holidays.cache_between(Date.civil(2008,3,21), Date.civil(2008,3,25), :ca, :informal)
163
161
 
164
- # Test that cache has been set
165
- cache_key = [:ca, :informal]
166
- assert_equal Date.civil(2008,3,21), Holidays.cache_range[cache_key].begin
167
- assert_equal Date.civil(2008,3,25), Holidays.cache_range[cache_key].end
168
- assert_equal Date.civil(2008,3,21), Holidays.cache[cache_key].first[:date]
169
- assert_equal Date.civil(2008,3,24), Holidays.cache[cache_key].last[:date]
162
+ # Test that cache has been set and it returns the same as before
163
+ assert_equal 1, Holidays.on(Date.civil(2008, 3, 21), :ca, :informal).length
164
+ assert_equal 1, Holidays.on(Date.civil(2008, 3, 24), :ca, :informal).length
170
165
 
171
166
  # Test that correct results are returned outside the cache range, and with no caching
172
167
  assert_equal 1, Holidays.on(Date.civil(2035,1,1), :ca, :informal).length
@@ -0,0 +1,85 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
+
3
+ require "#{Holidays::DEFINITIONS_PATH}/ca"
4
+
5
+ # Re-include CA defs via holidays/north_america to ensure that individual
6
+ # defs aren't duplicated.
7
+ #
8
+ # NOTE: this test is a mixture of integration and unit tests. It's messy and bad.
9
+ # I am not fixing it here because I am trying to clean up the 'between' use case
10
+ # and don't want to bite off more than I can chew.
11
+ require "#{Holidays::DEFINITIONS_PATH}/north_america"
12
+
13
+ class HolidaysTests < Test::Unit::TestCase
14
+ def setup
15
+ @date = Date.civil(2008,1,1)
16
+ @subject = Holidays.method(:between)
17
+ end
18
+
19
+ def teardown
20
+ Holidays::DefinitionFactory.cache_repository.reset!
21
+ end
22
+
23
+ def test_between
24
+ holidays = @subject.call(Date.civil(2008,7,1), Date.civil(2008,7,1), :ca)
25
+ assert_equal 1, holidays.length
26
+
27
+ holidays = @subject.call(Date.civil(2008,7,1), Date.civil(2008,7,31), :ca)
28
+ assert_equal 1, holidays.length
29
+
30
+ holidays = @subject.call(Date.civil(2008,7,2), Date.civil(2008,7,31), :ca)
31
+ assert_equal 0, holidays.length
32
+ end
33
+
34
+ def test_between_raises_error_if_missing_start_or_end_date
35
+ assert_raise ArgumentError do
36
+ @subject.call(nil, Date.civil(2015, 1, 1), :us)
37
+ end
38
+
39
+ assert_raise ArgumentError do
40
+ @subject.call(Date.civil(2015, 1, 1), nil, :us)
41
+ end
42
+ end
43
+
44
+ def test_cached_holidays_are_returned_if_present
45
+ start_date = Date.civil(2015, 1, 1)
46
+ end_date = Date.civil(2015, 1, 31)
47
+ options = [:us, :informal]
48
+
49
+ Holidays::DefinitionFactory.cache_repository.expects(:find).with(start_date, end_date, options).returns({cached: 'data'})
50
+
51
+ assert_equal({cached: 'data'}, @subject.call(start_date, end_date, *options))
52
+ end
53
+
54
+ def test_options_are_parsed
55
+ start_date = Date.civil(2015, 1, 1)
56
+ end_date = Date.civil(2015, 1, 31)
57
+ options = [:us]
58
+
59
+ options_parser_mock = mock()
60
+ Holidays::OptionFactory.stubs(:parse_options).returns(options_parser_mock)
61
+ options_parser_mock.expects(:call).with(options).returns([[:us], false, false])
62
+
63
+ between_mock = mock()
64
+ Holidays::UseCaseFactory.stubs(:between).returns(between_mock)
65
+ between_mock.expects(:call).with(start_date, end_date, {2015 => [0, 1, 2], 2014 => [0, 12]}, [:us], false, false)
66
+
67
+ @subject.call(start_date, end_date, *options)
68
+ end
69
+
70
+ def test_dates_driver_builder_is_called
71
+ start_date = Date.civil(2015, 1, 1)
72
+ end_date = Date.civil(2015, 1, 31)
73
+ options = [:us]
74
+
75
+ dates_driver_builder_mock = mock()
76
+ Holidays::UseCaseFactory.stubs(:dates_driver_builder).returns(dates_driver_builder_mock)
77
+ dates_driver_builder_mock.expects(:call).with(start_date, end_date).returns({2015 => [0, 1, 2]})
78
+
79
+ between_mock = mock()
80
+ Holidays::UseCaseFactory.stubs(:between).returns(between_mock)
81
+ between_mock.expects(:call).with(start_date, end_date, {2015 => [0, 1, 2]}, [:us], false, false)
82
+
83
+ @subject.call(start_date, end_date, *options)
84
+ end
85
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
- require 'holidays/gb'
3
- require 'holidays/ie'
2
+ require "#{Holidays::DEFINITIONS_PATH}/gb"
3
+ require "#{Holidays::DEFINITIONS_PATH}/ie"
4
4
 
5
5
  class MultipleRegionsTests < Test::Unit::TestCase
6
6
  def setup
@@ -1,12 +1,15 @@
1
1
  require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
2
 
3
- class ParseDefinitionsTests < Test::Unit::TestCase
3
+ class ParseDefinitionsIntegrationTests < Test::Unit::TestCase
4
4
 
5
5
  def test_single_parse_definition_file
6
- module_src, test_src = Holidays.parse_definition_files_and_return_source(:test_region, 'test/data/test_single_custom_holiday_defs.yaml')
6
+ module_src, test_src, regions = Holidays.parse_definition_files_and_return_source(:test_region, 'test/data/test_single_custom_holiday_defs.yaml')
7
7
 
8
8
  assert_equal false, module_src.empty?
9
9
  assert_equal false, test_src.empty?
10
+
11
+ assert regions.is_a?(Array)
12
+ assert_equal false, regions.empty?
10
13
  end
11
14
 
12
15
  def test_parsing_without_def_file_results_in_error
@@ -16,9 +19,12 @@ class ParseDefinitionsTests < Test::Unit::TestCase
16
19
  end
17
20
 
18
21
  def test_parsing_of_multiple_definition_files
19
- module_src, test_src = Holidays.parse_definition_files_and_return_source(:test_region_multiple, 'test/data/test_single_custom_holiday_defs.yaml', 'test/data/test_custom_govt_holiday_defs.yaml')
22
+ module_src, test_src, regions = Holidays.parse_definition_files_and_return_source(:test_region_multiple, 'test/data/test_single_custom_holiday_defs.yaml', 'test/data/test_custom_govt_holiday_defs.yaml')
20
23
 
21
24
  assert_equal false, module_src.empty?
22
25
  assert_equal false, test_src.empty?
26
+
27
+ assert regions.is_a?(Array)
28
+ assert_equal false, regions.empty?
23
29
  end
24
- end
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: holidays
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dunae
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-25 00:00:00.000000000 Z
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
69
83
  description: A collection of Ruby methods to deal with statutory and other holidays.
70
84
  You deserve a holiday!
71
85
  email:
@@ -74,121 +88,141 @@ executables: []
74
88
  extensions: []
75
89
  extra_rdoc_files: []
76
90
  files:
77
- - ".coveralls.yml"
78
91
  - CHANGELOG.md
79
92
  - Gemfile
80
93
  - LICENSE
81
94
  - README.md
82
95
  - REFERENCES
83
96
  - Rakefile
84
- - data/SYNTAX.rdoc
85
- - data/ar.yaml
86
- - data/at.yaml
87
- - data/au.yaml
88
- - data/be.yaml
89
- - data/br.yaml
90
- - data/ca.yaml
91
- - data/ch.yaml
92
- - data/cl.yaml
93
- - data/cr.yaml
94
- - data/cz.yaml
95
- - data/de.yaml
96
- - data/dk.yaml
97
- - data/ecb_target.yaml
98
- - data/el.yaml
99
- - data/es.yaml
100
- - data/federal_reserve.yaml
101
- - data/fedex.yaml
102
- - data/fi.yaml
103
- - data/fr.yaml
104
- - data/gb.yaml
105
- - data/hr.yaml
106
- - data/hu.yaml
107
- - data/ie.yaml
108
- - data/index.yaml
109
- - data/is.yaml
110
- - data/it.yaml
111
- - data/jp.yaml
112
- - data/li.yaml
113
- - data/lt.yaml
114
- - data/ma.yaml
115
- - data/mx.yaml
116
- - data/nerc.yaml
117
- - data/nl.yaml
118
- - data/no.yaml
119
- - data/north_america_informal.yaml
120
- - data/nyse.yaml
121
- - data/nz.yaml
122
- - data/ph.yaml
123
- - data/pl.yaml
124
- - data/pt.yaml
125
- - data/ro.yaml
126
- - data/se.yaml
127
- - data/sg.yaml
128
- - data/si.yaml
129
- - data/sk.yaml
130
- - data/united_nations.yaml
131
- - data/ups.yaml
132
- - data/us.yaml
133
- - data/ve.yaml
134
- - data/vi.yaml
135
- - data/za.yaml
97
+ - bin/console
98
+ - bin/setup
99
+ - definitions/SYNTAX.rdoc
100
+ - definitions/ar.yaml
101
+ - definitions/at.yaml
102
+ - definitions/au.yaml
103
+ - definitions/be.yaml
104
+ - definitions/br.yaml
105
+ - definitions/ca.yaml
106
+ - definitions/ch.yaml
107
+ - definitions/cl.yaml
108
+ - definitions/cr.yaml
109
+ - definitions/cz.yaml
110
+ - definitions/de.yaml
111
+ - definitions/dk.yaml
112
+ - definitions/ecb_target.yaml
113
+ - definitions/el.yaml
114
+ - definitions/es.yaml
115
+ - definitions/federal_reserve.yaml
116
+ - definitions/fedex.yaml
117
+ - definitions/fi.yaml
118
+ - definitions/fr.yaml
119
+ - definitions/gb.yaml
120
+ - definitions/hr.yaml
121
+ - definitions/hu.yaml
122
+ - definitions/ie.yaml
123
+ - definitions/index.yaml
124
+ - definitions/is.yaml
125
+ - definitions/it.yaml
126
+ - definitions/jp.yaml
127
+ - definitions/li.yaml
128
+ - definitions/lt.yaml
129
+ - definitions/ma.yaml
130
+ - definitions/mx.yaml
131
+ - definitions/nerc.yaml
132
+ - definitions/nl.yaml
133
+ - definitions/no.yaml
134
+ - definitions/north_america_informal.yaml
135
+ - definitions/nyse.yaml
136
+ - definitions/nz.yaml
137
+ - definitions/ph.yaml
138
+ - definitions/pl.yaml
139
+ - definitions/pt.yaml
140
+ - definitions/ro.yaml
141
+ - definitions/se.yaml
142
+ - definitions/sg.yaml
143
+ - definitions/si.yaml
144
+ - definitions/sk.yaml
145
+ - definitions/united_nations.yaml
146
+ - definitions/ups.yaml
147
+ - definitions/us.yaml
148
+ - definitions/ve.yaml
149
+ - definitions/vi.yaml
150
+ - definitions/za.yaml
136
151
  - holidays.gemspec
152
+ - lib/generated_definitions/MANIFEST
153
+ - lib/generated_definitions/REGIONS.rb
154
+ - lib/generated_definitions/ar.rb
155
+ - lib/generated_definitions/at.rb
156
+ - lib/generated_definitions/au.rb
157
+ - lib/generated_definitions/be.rb
158
+ - lib/generated_definitions/br.rb
159
+ - lib/generated_definitions/ca.rb
160
+ - lib/generated_definitions/ch.rb
161
+ - lib/generated_definitions/cl.rb
162
+ - lib/generated_definitions/cr.rb
163
+ - lib/generated_definitions/cz.rb
164
+ - lib/generated_definitions/de.rb
165
+ - lib/generated_definitions/dk.rb
166
+ - lib/generated_definitions/ecb_target.rb
167
+ - lib/generated_definitions/el.rb
168
+ - lib/generated_definitions/es.rb
169
+ - lib/generated_definitions/europe.rb
170
+ - lib/generated_definitions/fed_ex.rb
171
+ - lib/generated_definitions/federal_reserve.rb
172
+ - lib/generated_definitions/fi.rb
173
+ - lib/generated_definitions/fr.rb
174
+ - lib/generated_definitions/gb.rb
175
+ - lib/generated_definitions/hr.rb
176
+ - lib/generated_definitions/hu.rb
177
+ - lib/generated_definitions/ie.rb
178
+ - lib/generated_definitions/is.rb
179
+ - lib/generated_definitions/it.rb
180
+ - lib/generated_definitions/jp.rb
181
+ - lib/generated_definitions/li.rb
182
+ - lib/generated_definitions/lt.rb
183
+ - lib/generated_definitions/ma.rb
184
+ - lib/generated_definitions/mx.rb
185
+ - lib/generated_definitions/nerc.rb
186
+ - lib/generated_definitions/nl.rb
187
+ - lib/generated_definitions/no.rb
188
+ - lib/generated_definitions/north_america.rb
189
+ - lib/generated_definitions/nyse.rb
190
+ - lib/generated_definitions/nz.rb
191
+ - lib/generated_definitions/ph.rb
192
+ - lib/generated_definitions/pl.rb
193
+ - lib/generated_definitions/pt.rb
194
+ - lib/generated_definitions/ro.rb
195
+ - lib/generated_definitions/scandinavia.rb
196
+ - lib/generated_definitions/se.rb
197
+ - lib/generated_definitions/sg.rb
198
+ - lib/generated_definitions/si.rb
199
+ - lib/generated_definitions/sk.rb
200
+ - lib/generated_definitions/united_nations.rb
201
+ - lib/generated_definitions/ups.rb
202
+ - lib/generated_definitions/us.rb
203
+ - lib/generated_definitions/ve.rb
204
+ - lib/generated_definitions/vi.rb
205
+ - lib/generated_definitions/za.rb
137
206
  - lib/holidays.rb
138
- - lib/holidays/MANIFEST
139
- - lib/holidays/ar.rb
140
- - lib/holidays/at.rb
141
- - lib/holidays/au.rb
142
- - lib/holidays/be.rb
143
- - lib/holidays/br.rb
144
- - lib/holidays/ca.rb
145
- - lib/holidays/ch.rb
146
- - lib/holidays/cl.rb
147
- - lib/holidays/cr.rb
148
- - lib/holidays/cz.rb
149
- - lib/holidays/de.rb
150
- - lib/holidays/dk.rb
151
- - lib/holidays/ecb_target.rb
152
- - lib/holidays/el.rb
153
- - lib/holidays/es.rb
154
- - lib/holidays/europe.rb
155
- - lib/holidays/fed_ex.rb
156
- - lib/holidays/federal_reserve.rb
157
- - lib/holidays/fi.rb
158
- - lib/holidays/fr.rb
159
- - lib/holidays/gb.rb
160
- - lib/holidays/hr.rb
161
- - lib/holidays/hu.rb
162
- - lib/holidays/ie.rb
163
- - lib/holidays/is.rb
164
- - lib/holidays/it.rb
165
- - lib/holidays/jp.rb
166
- - lib/holidays/li.rb
167
- - lib/holidays/lt.rb
168
- - lib/holidays/ma.rb
169
- - lib/holidays/mx.rb
170
- - lib/holidays/nerc.rb
171
- - lib/holidays/nl.rb
172
- - lib/holidays/no.rb
173
- - lib/holidays/north_america.rb
174
- - lib/holidays/nyse.rb
175
- - lib/holidays/nz.rb
176
- - lib/holidays/ph.rb
177
- - lib/holidays/pl.rb
178
- - lib/holidays/pt.rb
179
- - lib/holidays/ro.rb
180
- - lib/holidays/scandinavia.rb
181
- - lib/holidays/se.rb
182
- - lib/holidays/sg.rb
183
- - lib/holidays/si.rb
184
- - lib/holidays/sk.rb
185
- - lib/holidays/united_nations.rb
186
- - lib/holidays/ups.rb
187
- - lib/holidays/us.rb
188
- - lib/holidays/ve.rb
207
+ - lib/holidays/core_extensions/date.rb
208
+ - lib/holidays/date_calculator/day_of_month.rb
209
+ - lib/holidays/date_calculator/easter.rb
210
+ - lib/holidays/date_calculator/weekend_modifier.rb
211
+ - lib/holidays/date_calculator_factory.rb
212
+ - lib/holidays/definition/context/generator.rb
213
+ - lib/holidays/definition/context/merger.rb
214
+ - lib/holidays/definition/repository/cache.rb
215
+ - lib/holidays/definition/repository/holidays_by_month.rb
216
+ - lib/holidays/definition/repository/proc_cache.rb
217
+ - lib/holidays/definition/repository/regions.rb
218
+ - lib/holidays/definition/validator/region.rb
219
+ - lib/holidays/definition_factory.rb
220
+ - lib/holidays/option/context/parse_options.rb
221
+ - lib/holidays/option_factory.rb
222
+ - lib/holidays/use_case/context/between.rb
223
+ - lib/holidays/use_case/context/dates_driver_builder.rb
224
+ - lib/holidays/use_case_factory.rb
189
225
  - lib/holidays/version.rb
190
- - lib/holidays/vi.rb
191
- - lib/holidays/za.rb
192
226
  - test/data/test_custom_govt_holiday_defs.yaml
193
227
  - test/data/test_multiple_custom_holiday_defs.yaml
194
228
  - test/data/test_single_custom_holiday_defs.yaml
@@ -244,11 +278,29 @@ files:
244
278
  - test/defs/test_defs_ve.rb
245
279
  - test/defs/test_defs_vi.rb
246
280
  - test/defs/test_defs_za.rb
281
+ - test/holidays/core_extensions/test_date.rb
282
+ - test/holidays/date_calculator/test_day_of_month.rb
283
+ - test/holidays/date_calculator/test_easter.rb
284
+ - test/holidays/date_calculator/test_weekend_modifier.rb
285
+ - test/holidays/definition/context/test_generator.rb
286
+ - test/holidays/definition/context/test_merger.rb
287
+ - test/holidays/definition/repository/test_cache.rb
288
+ - test/holidays/definition/repository/test_holidays_by_month.rb
289
+ - test/holidays/definition/repository/test_proc_cache.rb
290
+ - test/holidays/definition/repository/test_regions.rb
291
+ - test/holidays/definition/validator/test_region.rb
292
+ - test/holidays/option/context/test_parse_options.rb
293
+ - test/holidays/test_date_calculator_factory.rb
294
+ - test/holidays/test_definition_factory.rb
295
+ - test/holidays/test_option_factory.rb
296
+ - test/holidays/test_use_case_factory.rb
297
+ - test/holidays/use_case/context/test_between.rb
298
+ - test/holidays/use_case/context/test_dates_driver_builder.rb
247
299
  - test/test_all_regions.rb
248
300
  - test/test_custom_holidays.rb
249
- - test/test_date.rb
250
301
  - test/test_helper.rb
251
302
  - test/test_holidays.rb
303
+ - test/test_holidays_between.rb
252
304
  - test/test_multiple_regions.rb
253
305
  - test/test_parse_definitions.rb
254
306
  homepage: https://github.com/alexdunae/holidays
@@ -271,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
323
  version: '0'
272
324
  requirements: []
273
325
  rubyforge_project:
274
- rubygems_version: 2.2.2
326
+ rubygems_version: 2.4.5
275
327
  signing_key:
276
328
  specification_version: 4
277
329
  summary: A collection of Ruby methods to deal with statutory and other holidays.
@@ -331,10 +383,28 @@ test_files:
331
383
  - test/defs/test_defs_ve.rb
332
384
  - test/defs/test_defs_vi.rb
333
385
  - test/defs/test_defs_za.rb
386
+ - test/holidays/core_extensions/test_date.rb
387
+ - test/holidays/date_calculator/test_day_of_month.rb
388
+ - test/holidays/date_calculator/test_easter.rb
389
+ - test/holidays/date_calculator/test_weekend_modifier.rb
390
+ - test/holidays/definition/context/test_generator.rb
391
+ - test/holidays/definition/context/test_merger.rb
392
+ - test/holidays/definition/repository/test_cache.rb
393
+ - test/holidays/definition/repository/test_holidays_by_month.rb
394
+ - test/holidays/definition/repository/test_proc_cache.rb
395
+ - test/holidays/definition/repository/test_regions.rb
396
+ - test/holidays/definition/validator/test_region.rb
397
+ - test/holidays/option/context/test_parse_options.rb
398
+ - test/holidays/test_date_calculator_factory.rb
399
+ - test/holidays/test_definition_factory.rb
400
+ - test/holidays/test_option_factory.rb
401
+ - test/holidays/test_use_case_factory.rb
402
+ - test/holidays/use_case/context/test_between.rb
403
+ - test/holidays/use_case/context/test_dates_driver_builder.rb
334
404
  - test/test_all_regions.rb
335
405
  - test/test_custom_holidays.rb
336
- - test/test_date.rb
337
406
  - test/test_helper.rb
338
407
  - test/test_holidays.rb
408
+ - test/test_holidays_between.rb
339
409
  - test/test_multiple_regions.rb
340
410
  - test/test_parse_definitions.rb