/
teaching_time_spec.rb
64 lines (53 loc) · 1.82 KB
/
teaching_time_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'rspec-parameterized'
require 'spec_helper'
require 'sirius/teaching_time'
describe Sirius::TeachingTime do
using RSpec::Parameterized::TableSyntax
subject(:teaching_time) do
described_class.new(teaching_period: Period.parse('14:30', '16:00'),
parity: parity, day: input_day)
end
let(:parity) { 'odd' }
let(:input_day) { :tuesday }
describe '#week_frequency' do
where :parity, :week_frequency do
'odd' | 2
'even' | 2
'both' | 1
end
with_them ->{ "with #{parity} parity" } do
it 'returns correct frequency' do
expect(teaching_time.week_frequency).to eq week_frequency
end
end
end
describe '#duration' do
it 'returns difference between start and end' do
expect(subject.duration).to eq 90.minutes
end
end
describe '#to_recurrence_rule' do
let(:ends_at) { DateTime.parse('2015-11-11') }
it 'returns weekly recurrence rule' do
expect(subject.to_recurrence_rule(0, ends_at)).to be_an_instance_of IceCube::WeeklyRule
end
it 'returns terminating rule' do
expect(subject.to_recurrence_rule(0, ends_at)).to be_terminating
end
where :input_day, :offset, :output_day do
:sunday | 0 | :sunday
:monday | -1 | :sunday
:sunday | +1 | :monday
:wednesday| +7 | :wednesday
:friday | +4 | :tuesday
end
with_them ->{ "with input_day #{input_day} and offset #{offset}" } do
# IceCube indexes days of week from 0 to 6, beginning with Sunday.
let(:result_day) { (Date::DAYS_INTO_WEEK[output_day] + 1) % 7 }
it 'sets correct recurrence day' do
rule = subject.to_recurrence_rule(offset, ends_at)
expect(rule.validations[:day].first.day).to eq result_day
end
end
end
end