calendarium-romanum 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+
3
+ describe SanctoraleLoader do
4
+
5
+ before :each do
6
+ @s = Sanctorale.new
7
+ @l = SanctoraleLoader.new
8
+ end
9
+
10
+ describe 'data sources' do
11
+ describe '.load_from_string' do
12
+ before :each do
13
+ str = '1/3 : Ss.mi Nominis Iesu'
14
+ @l.load_from_string @s, str
15
+ end
16
+
17
+ it 'loads one entry' do
18
+ expect(@s.size).to eq 1
19
+ end
20
+
21
+ it 'loads date correctly' do
22
+ expect(@s.get(1, 3).size).to eq 1
23
+ end
24
+
25
+ it 'loads title correctly' do
26
+ expect(@s.get(1, 3)[0].title).to eq 'Ss.mi Nominis Iesu'
27
+ end
28
+
29
+ it 'sets default rank' do
30
+ expect(@s.get(1, 3)[0].rank).to eq Ranks::MEMORIAL_OPTIONAL
31
+ end
32
+
33
+ it 'sets default colour - white' do
34
+ expect(@s.get(1, 3)[0].colour).to eq Colours::WHITE
35
+ end
36
+
37
+ it 'loads explicit rank if given' do
38
+ str = '1/25 f : In conversione S. Pauli, apostoli'
39
+ @l.load_from_string @s, str
40
+ expect(@s.get(1, 25)[0].rank).to eq Ranks::FEAST_GENERAL
41
+ end
42
+ end
43
+
44
+ describe '.load_from_file' do
45
+ it 'loads something from file' do
46
+ @l.load_from_file(@s, File.join(%w{data universal-la.txt}))
47
+ expect(@s.size).to be > 190
48
+ end
49
+ end
50
+ end
51
+
52
+ describe 'record/file format' do
53
+ describe 'month as heading' do
54
+ it 'loads a month heading and uses the month for subsequent records' do
55
+ str = ['= 1', '25 f : In conversione S. Pauli, apostoli'].join "\n"
56
+ @l.load_from_string @s, str
57
+ expect(@s).not_to be_empty
58
+ expect(@s.get(1, 25)).not_to be_empty
59
+ end
60
+ end
61
+
62
+ describe 'colour' do
63
+ it 'sets colour if specified' do
64
+ str = '4/25 f R : S. Marci, evangelistae'
65
+ @l.load_from_string @s, str
66
+ expect(@s.get(4, 25).first.colour).to eq Colours::RED
67
+ end
68
+ end
69
+
70
+ describe 'rank' do
71
+ it 'sets exact rank if specified' do
72
+ # say we specify a proper calendar of a church dedicated to St. George
73
+ str = '4/23 s1.4 R : S. Georgii, martyris'
74
+ @l.load_from_string @s, str
75
+ celeb = @s.get(4, 23).first
76
+ expect(celeb.rank).to eq Ranks::SOLEMNITY_PROPER
77
+ end
78
+ end
79
+ end
80
+
81
+ describe 'invalid input' do
82
+ describe 'syntax errors' do
83
+ it 'invalid syntax' do
84
+ str = 'line without standard beginning'
85
+ expect do
86
+ @l.load_from_string @s, str
87
+ end.to raise_exception /Syntax error/
88
+ end
89
+ end
90
+
91
+ describe 'syntactically correct data making no sense' do
92
+ it 'invalid month' do
93
+ str = '100/25 f : In conversione S. Pauli, apostoli'
94
+ expect do
95
+ @l.load_from_string @s, str
96
+ end.to raise_exception /Invalid month/
97
+ end
98
+
99
+ it 'line with day only, without preceding month heading' do
100
+ str = '25 f : In conversione S. Pauli, apostoli'
101
+ expect do
102
+ @l.load_from_string @s, str
103
+ end.to raise_exception /Invalid month/
104
+ end
105
+
106
+ it 'invalid day' do
107
+ str = '1/250 f : In conversione S. Pauli, apostoli'
108
+ expect do
109
+ @l.load_from_string @s, str
110
+ end.to raise_exception /Invalid day/
111
+ end
112
+
113
+ it 'invalid month heading' do
114
+ str = '= 0'
115
+ expect do
116
+ @l.load_from_string @s, str
117
+ end.to raise_exception /Invalid month/
118
+ end
119
+
120
+ it 'invalid rank' do
121
+ str = '1/25 X : In conversione S. Pauli, apostoli'
122
+ expect do
123
+ @l.load_from_string @s, str
124
+ end.to raise_exception /Syntax error/
125
+ end
126
+
127
+ it 'invalid numeric rank' do
128
+ str = '4/23 s8.4 R : S. Georgii, martyris'
129
+ expect do
130
+ @l.load_from_string @s, str
131
+ end.to raise_exception /rank/
132
+ end
133
+
134
+ it 'invalid combination of rank latter and number' do
135
+ str = '4/23 m2.5 R : S. Georgii, martyris'
136
+ expect do
137
+ @l.load_from_string @s, str
138
+ end.to raise_exception /rank/
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,22 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
18
+
19
+ require 'calendarium-romanum'
20
+ include CalendariumRomanum
21
+ include Ranks
22
+ include Colours
@@ -0,0 +1,342 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Temporale do
4
+
5
+ before :all do
6
+ @t = @t12 = Temporale.new 2012
7
+ @t13 = Temporale.new 2013
8
+ end
9
+
10
+ describe '.liturgical_year' do
11
+ it 'returns liturgical year for the given date' do
12
+ [
13
+ [Date.new(2014, 11, 1), 2013],
14
+ [Date.new(2014, 12, 1), 2014]
15
+ ].each do |date, year|
16
+ Temporale.liturgical_year(date).should eq year
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#weekday_before' do
22
+ it 'works well for all 7 weekdays' do
23
+ today = Date.new 2014, 3, 16
24
+ @t.weekday_before(0, today).should eq Date.new(2014, 3, 9)
25
+ @t.weekday_before(1, today).should eq Date.new(2014, 3, 10)
26
+ @t.weekday_before(2, today).should eq Date.new(2014, 3, 11)
27
+ @t.weekday_before(3, today).should eq Date.new(2014, 3, 12)
28
+ @t.weekday_before(4, today).should eq Date.new(2014, 3, 13)
29
+ @t.weekday_before(5, today).should eq Date.new(2014, 3, 14)
30
+ @t.weekday_before(6, today).should eq Date.new(2014, 3, 15)
31
+ end
32
+ end
33
+
34
+ describe '#weekday_after' do
35
+ it 'works well for all 7 weekdays' do
36
+ today = Date.new 2014, 3, 16
37
+ @t.monday_after(today).should eq Date.new(2014, 3, 17)
38
+ @t.tuesday_after(today).should eq Date.new(2014, 3, 18)
39
+ @t.wednesday_after(today).should eq Date.new(2014, 3, 19)
40
+ @t.thursday_after(today).should eq Date.new(2014, 3, 20)
41
+ @t.friday_after(today).should eq Date.new(2014, 3, 21)
42
+ @t.saturday_after(today).should eq Date.new(2014, 3, 22)
43
+ @t.sunday_after(today).should eq Date.new(2014, 3, 23)
44
+ end
45
+ end
46
+
47
+ describe '#advent_sunday' do
48
+ it 'determines first Sunday of Advent' do
49
+ [
50
+ [2004, [11, 28]],
51
+ [2010, [11, 28]],
52
+ [2011, [11, 27]],
53
+ [2012, [12, 2]],
54
+ [2013, [12, 1]]
55
+ ].each do |d|
56
+ year, date = d
57
+ @t.advent_sunday(1, year).should eq Date.new(year, *date)
58
+ end
59
+ end
60
+
61
+ it 'determines second Sunday of Advent' do
62
+ @t.advent_sunday(2, 2013).should eq Date.new(2013,12,8)
63
+ end
64
+ end
65
+
66
+ describe '#second_advent_sunday' do
67
+ # alias of advent_sunday through method_missing
68
+
69
+ it 'determines second Sunday of Advent' do
70
+ @t.second_advent_sunday(2013).should eq Date.new(2013,12,8)
71
+ end
72
+ end
73
+
74
+ describe '#easter_sunday' do
75
+ it 'determines Easter Sunday' do
76
+ [
77
+ [2003, [2004, 4, 11]],
78
+ [2004, [2005, 3, 27]],
79
+ [2005, [2006, 4, 16]],
80
+ [2006, [2007, 4, 8]],
81
+ [2014, [2015, 4, 5]]
82
+ ].each do |d|
83
+ year, date = d
84
+ @t.easter_sunday(year).should eq Date.new(*date)
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '#date_range' do
90
+ it 'includes days of the year' do
91
+ @t.date_range.should include Date.new(2012, 12, 3)
92
+ @t.date_range.should include Date.new(2013, 11, 5)
93
+ end
94
+ end
95
+
96
+ describe '#season' do
97
+ it 'determines Advent' do
98
+ @t13.season(Date.new(2013, 12, 15)).should eq :advent
99
+ @t13.season(Date.new(2013, 12, 1)).should eq :advent
100
+ @t13.season(Date.new(2013, 12, 24)).should eq :advent
101
+ end
102
+
103
+ it 'determines Christmas' do
104
+ @t13.season(Date.new(2013, 12, 25)).should eq :christmas
105
+ @t13.season(Date.new(2014, 1, 12)).should eq :christmas
106
+ @t13.season(Date.new(2014, 1, 13)).should eq :ordinary
107
+ end
108
+
109
+ it 'determines Lent' do
110
+ @t13.season(Date.new(2014, 3, 4)).should eq :ordinary
111
+ @t13.season(Date.new(2014, 3, 5)).should eq :lent
112
+ @t13.season(Date.new(2014, 4, 19)).should eq :lent
113
+ @t13.season(Date.new(2014, 4, 20)).should eq :easter
114
+ end
115
+
116
+ it 'determines Easter time' do
117
+ @t13.season(Date.new(2014, 4, 20)).should eq :easter
118
+ @t13.season(Date.new(2014, 6, 8)).should eq :easter
119
+ @t13.season(Date.new(2014, 6, 9)).should eq :ordinary
120
+ end
121
+ end
122
+
123
+ describe '#get' do
124
+ it 'returns a Celebration' do
125
+ expect(@t13.get(8, 12)).to be_a Celebration
126
+ end
127
+
128
+ describe 'for' do
129
+ describe 'ferial' do
130
+ it 'in Ordinary Time' do
131
+ c = @t13.get(8, 12)
132
+ expect(c.rank).to eq FERIAL
133
+ expect(c.color).to eq GREEN
134
+ end
135
+
136
+ it 'in Advent' do
137
+ c = @t13.get(12, 12)
138
+ expect(c.rank).to eq FERIAL
139
+ expect(c.color).to eq VIOLET
140
+ end
141
+
142
+ it 'in the last week of Advent' do
143
+ c = @t13.get(12, 23)
144
+ expect(c.rank).to eq FERIAL_PRIVILEGED
145
+ expect(c.color).to eq VIOLET
146
+ end
147
+
148
+ it 'in Christmas time' do
149
+ c = @t13.get(1, 3)
150
+ expect(c.rank).to eq FERIAL
151
+ expect(c.color).to eq WHITE
152
+ end
153
+
154
+ it 'in Lent' do
155
+ c = @t13.get(3, 18)
156
+ expect(c.rank).to eq FERIAL_PRIVILEGED
157
+ expect(c.color).to eq VIOLET
158
+ end
159
+
160
+ it 'in Easter Time' do
161
+ c = @t13.get(5, 5)
162
+ expect(c.rank).to eq FERIAL
163
+ expect(c.color).to eq WHITE
164
+ end
165
+ end
166
+
167
+ describe 'Sunday' do
168
+ it 'in Ordinary Time' do
169
+ c = @t13.get(8, 10)
170
+ expect(c.rank).to eq SUNDAY_UNPRIVILEGED
171
+ expect(c.color).to eq GREEN
172
+ end
173
+
174
+ it 'in Advent' do
175
+ c = @t13.get(12, 15)
176
+ expect(c.rank).to eq PRIMARY
177
+ expect(c.color).to eq VIOLET
178
+ end
179
+
180
+ it 'in Christmas time' do
181
+ c = @t13.get(1, 5)
182
+ expect(c.rank).to eq SUNDAY_UNPRIVILEGED
183
+ expect(c.color).to eq WHITE
184
+ end
185
+
186
+ it 'in Lent' do
187
+ c = @t13.get(3, 23)
188
+ expect(c.rank).to eq PRIMARY
189
+ expect(c.color).to eq VIOLET
190
+ end
191
+
192
+ it 'in Easter Time' do
193
+ c = @t13.get(5, 11)
194
+ expect(c.rank).to eq PRIMARY
195
+ expect(c.color).to eq WHITE
196
+ end
197
+ end
198
+
199
+ describe 'solemnities and their cycles - ' do
200
+ it 'end of Advent time' do
201
+ c = @t13.get(12, 17)
202
+ expect(c.rank).to eq FERIAL_PRIVILEGED
203
+ expect(c.colour).to eq VIOLET
204
+ end
205
+
206
+ it 'Nativity' do
207
+ c = @t13.get(12, 25)
208
+ expect(c.rank).to eq PRIMARY
209
+ expect(c.title).to eq 'The Nativity of the Lord'
210
+ expect(c.colour).to eq WHITE
211
+ end
212
+
213
+ it 'day in the octave of Nativity' do
214
+ c = @t13.get(12, 27)
215
+ expect(c.rank).to eq FERIAL_PRIVILEGED
216
+ expect(c.colour).to eq WHITE
217
+ end
218
+
219
+ it 'Holy Family' do
220
+ c = @t13.get(12, 29)
221
+ expect(c.rank).to eq PRIMARY
222
+ expect(c.title).to eq 'The Holy Family of Jesus, Mary and Joseph'
223
+ expect(c.colour).to eq WHITE
224
+ end
225
+
226
+ it 'Epiphany' do
227
+ c = @t13.get(1, 6)
228
+ expect(c.rank).to eq PRIMARY
229
+ expect(c.title).to eq 'The Epiphany of the Lord'
230
+ expect(c.colour).to eq WHITE
231
+ end
232
+
233
+ it 'Baptism of the Lord' do
234
+ c = @t13.get(1, 12)
235
+ expect(c.rank).to eq FEAST_LORD_GENERAL
236
+ expect(c.title).to eq 'The Baptism of the Lord'
237
+ expect(c.colour).to eq WHITE
238
+ end
239
+
240
+ it 'Good Friday' do
241
+ c = @t13.get(4, 18)
242
+ expect(c.rank).to eq TRIDUUM
243
+ expect(c.title).to eq 'Friday of the Passion of the Lord'
244
+ end
245
+
246
+ it 'Holy Saturday' do
247
+ c = @t13.get(4, 19)
248
+ expect(c.rank).to eq TRIDUUM
249
+ expect(c.title).to eq 'Holy Saturday'
250
+ expect(c.colour).to eq VIOLET
251
+ end
252
+
253
+ it 'Resurrection' do
254
+ c = @t13.get(4, 20)
255
+ expect(c.rank).to eq TRIDUUM
256
+ expect(c.title).to eq 'Easter Sunday of the Resurrection of the Lord'
257
+ end
258
+
259
+ it 'day in the Easter Octave' do
260
+ c = @t13.get(4, 22)
261
+ expect(c.rank).to eq PRIMARY
262
+ end
263
+
264
+ it 'Pentecost' do
265
+ c = @t13.get(6, 8)
266
+ expect(c.rank).to eq PRIMARY
267
+ expect(c.title).to eq 'Pentecost Sunday'
268
+ expect(c.colour).to eq RED
269
+ end
270
+
271
+ it 'Trinity' do
272
+ c = @t13.get(6, 15)
273
+ expect(c.rank).to eq SOLEMNITY_GENERAL
274
+ expect(c.title).to eq 'The Most Holy Trinity'
275
+ expect(c.colour).to eq WHITE
276
+ end
277
+
278
+ it 'Body of Christ' do
279
+ c = @t13.get(6, 19)
280
+ expect(c.rank).to eq SOLEMNITY_GENERAL
281
+ expect(c.title).to eq 'The Most Holy Body and Blood of Christ'
282
+ expect(c.colour).to eq WHITE
283
+ end
284
+
285
+ it 'Sacred Heart' do
286
+ c = @t13.get(6, 27)
287
+ expect(c.rank).to eq SOLEMNITY_GENERAL
288
+ expect(c.title).to eq 'The Most Sacred Heart of Jesus'
289
+ expect(c.colour).to eq WHITE
290
+ end
291
+
292
+ it 'Christ the King' do
293
+ c = @t13.get(11, 23)
294
+ expect(c.rank).to eq SOLEMNITY_GENERAL
295
+ expect(c.title).to eq 'Our Lord Jesus Christ, King of the Universe'
296
+ expect(c.colour).to eq WHITE
297
+ end
298
+ end
299
+ end
300
+ end
301
+
302
+ describe 'initialized without a year' do
303
+ before :each do
304
+ @tny = Temporale.new
305
+ end
306
+
307
+ it 'is possible to initialize a Temporale without a year' do
308
+ expect { Temporale.new }.not_to raise_exception
309
+ end
310
+
311
+ it 'crashes when a date is requested without year' do
312
+ expect { @tny.first_advent_sunday }.to raise_exception
313
+ end
314
+
315
+ it 'computes dates as expected if year is given' do
316
+ days = %i(first_advent_sunday nativity holy_family mother_of_god
317
+ epiphany baptism_of_lord ash_wednesday easter_sunday good_friday
318
+ holy_saturday pentecost
319
+ holy_trinity body_blood sacred_heart christ_king
320
+
321
+ date_range)
322
+ days.each do |msg|
323
+ @tny.send(msg, 2012).should eq @t12.send(msg)
324
+ end
325
+ end
326
+
327
+ describe '#get' do
328
+ it 'always raises an exception' do
329
+ # for get to work well is imoportant to have precomputed
330
+ # solemnity dates. That is only possible when a year
331
+ # is specified on initialization.
332
+ [
333
+ Date.new(2015, 1, 1),
334
+ Date.new(2015, 9, 23),
335
+ Date.new(2015, 3, 4)
336
+ ].each do |date|
337
+ expect { @tny.get(date) }.to raise_exception
338
+ end
339
+ end
340
+ end
341
+ end
342
+ end