|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe RRule::Secondly do |
| 6 | + let(:interval) { 1 } |
| 7 | + let(:context) do |
| 8 | + RRule::Context.new( |
| 9 | + { interval: interval }, |
| 10 | + date, |
| 11 | + 'America/Los_Angeles' |
| 12 | + ) |
| 13 | + end |
| 14 | + let(:filters) { [] } |
| 15 | + let(:generator) { RRule::AllOccurrences.new(context) } |
| 16 | + let(:timeset) { [{ hour: date.hour, minute: date.min, second: date.sec }] } |
| 17 | + |
| 18 | + before { context.rebuild(date.year, date.month) } |
| 19 | + |
| 20 | + describe '#next_occurrences' do |
| 21 | + subject(:frequency) { described_class.new(context, filters, generator, timeset) } |
| 22 | + |
| 23 | + context 'with an interval of one' do |
| 24 | + let(:date) { Time.zone.local(1997, 1, 1, 0, 0, 0) } |
| 25 | + |
| 26 | + it 'returns sequential seconds' do |
| 27 | + expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1, 0, 0, 0)] |
| 28 | + expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1, 0, 0, 1)] |
| 29 | + expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1, 0, 0, 2)] |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + context 'with an interval of two' do |
| 34 | + let(:interval) { 2 } |
| 35 | + let(:date) { Time.zone.local(1997, 1, 1, 0, 0, 0) } |
| 36 | + |
| 37 | + it 'returns every other second' do |
| 38 | + expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1, 0, 0, 0)] |
| 39 | + expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1, 0, 0, 2)] |
| 40 | + expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1, 0, 0, 4)] |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + context 'at the end of the minute' do |
| 45 | + let(:date) { Time.zone.local(1997, 1, 1, 0, 0, 59) } |
| 46 | + |
| 47 | + it 'goes into the next minute' do |
| 48 | + expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1, 0, 0, 59)] |
| 49 | + expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1, 0, 1, 0)] |
| 50 | + expect(frequency.next_occurrences).to eql [Time.zone.local(1997, 1, 1, 0, 1, 1)] |
| 51 | + end |
| 52 | + end |
| 53 | + end |
| 54 | +end |
0 commit comments