recurrence 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b5dcd970513024fef80a9774f83b32e51aad12a3
4
+ data.tar.gz: 6c4258d978897be59e86f14c40def4e838f71f3f
5
+ SHA512:
6
+ metadata.gz: 9ad289eaf1aa4e7e96c9699347229e2b93cff83ac561a64b1638537dfb5fdfa2a24b6e0a2e9747c65a5df1cc02f093996068c20f795a1350b3409d9c7505098c
7
+ data.tar.gz: c339f2f8e64b880483e162181101c8eedd5bf2dc36beec288138c618c90d8743b82a169e4f68a085f53a61667d5a25a6f73e49df58494b1929142df0ab535b34
data/.rspec CHANGED
@@ -1 +1 @@
1
- --color --format documentation
1
+ --color
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
5
+ script: bundle exec rspec
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
@@ -1,30 +1,44 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- recurrence (1.2.0)
5
- activesupport (>= 2.3.0)
4
+ recurrence (1.3.0)
5
+ activesupport
6
6
  i18n
7
7
 
8
8
  GEM
9
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (3.0.9)
12
- diff-lcs (1.1.2)
13
- i18n (0.6.0)
14
- rake (0.9.2)
15
- rspec (2.6.0)
16
- rspec-core (~> 2.6.0)
17
- rspec-expectations (~> 2.6.0)
18
- rspec-mocks (~> 2.6.0)
19
- rspec-core (2.6.4)
20
- rspec-expectations (2.6.0)
21
- diff-lcs (~> 1.1.2)
22
- rspec-mocks (2.6.0)
11
+ activesupport (4.1.0)
12
+ i18n (~> 0.6, >= 0.6.9)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
+ thread_safe (~> 0.1)
16
+ tzinfo (~> 1.1)
17
+ diff-lcs (1.2.5)
18
+ i18n (0.6.9)
19
+ json (1.8.1)
20
+ minitest (5.3.3)
21
+ rake (10.3.1)
22
+ rspec (3.0.0.beta2)
23
+ rspec-core (= 3.0.0.beta2)
24
+ rspec-expectations (= 3.0.0.beta2)
25
+ rspec-mocks (= 3.0.0.beta2)
26
+ rspec-core (3.0.0.beta2)
27
+ rspec-support (= 3.0.0.beta2)
28
+ rspec-expectations (3.0.0.beta2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (= 3.0.0.beta2)
31
+ rspec-mocks (3.0.0.beta2)
32
+ rspec-support (= 3.0.0.beta2)
33
+ rspec-support (3.0.0.beta2)
34
+ thread_safe (0.3.3)
35
+ tzinfo (1.1.0)
36
+ thread_safe (~> 0.1)
23
37
 
24
38
  PLATFORMS
25
39
  ruby
26
40
 
27
41
  DEPENDENCIES
28
- rake (~> 0.9)
42
+ rake
29
43
  recurrence!
30
- rspec (~> 2.6)
44
+ rspec (= 3.0.0.beta2)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 Nando Vieira
1
+ Copyright (c) 2008-2014 Nando Vieira
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,151 @@
1
+ # Recurrence
2
+
3
+ A simple library to handle recurring events.
4
+
5
+ ## Installation
6
+
7
+ gem install recurrence
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ require "rubygems"
13
+ require "recurrence"
14
+
15
+ # Daily
16
+ r = Recurrence.new(:every => :day)
17
+ r = Recurrence.new(:every => :day, :interval => 9)
18
+ r = Recurrence.new(:every => :day, :repeat => 7)
19
+ r = Recurrence.daily(options = {})
20
+
21
+ # Weekly
22
+ r = Recurrence.new(:every => :week, :on => 5)
23
+ r = Recurrence.new(:every => :week, :on => :monday)
24
+ r = Recurrence.new(:every => :week, :on => [:monday, :friday])
25
+ r = Recurrence.new(:every => :week, :on => [:monday, :wednesday, :friday])
26
+ r = Recurrence.new(:every => :week, :on => :friday, :interval => 2)
27
+ r = Recurrence.new(:every => :week, :on => :friday, :repeat => 4)
28
+ r = Recurrence.weekly(:on => :thursday)
29
+
30
+ # Monthly by month day
31
+ r = Recurrence.new(:every => :month, :on => 15)
32
+ r = Recurrence.new(:every => :month, :on => 31)
33
+ r = Recurrence.new(:every => :month, :on => 7, :interval => 2)
34
+ r = Recurrence.new(:every => :month, :on => 7, :interval => :monthly)
35
+ r = Recurrence.new(:every => :month, :on => 7, :interval => :bimonthly)
36
+ r = Recurrence.new(:every => :month, :on => 7, :repeat => 6)
37
+ r = Recurrence.monthly(:on => 31)
38
+
39
+ # Monthly by week day
40
+ r = Recurrence.new(:every => :month, :on => :first, :weekday => :sunday)
41
+ r = Recurrence.new(:every => :month, :on => :third, :weekday => :monday)
42
+ r = Recurrence.new(:every => :month, :on => :last, :weekday => :friday)
43
+ r = Recurrence.new(:every => :month, :on => :last, :weekday => :friday, :interval => 2)
44
+ r = Recurrence.new(:every => :month, :on => :last, :weekday => :friday, :interval => :quarterly)
45
+ r = Recurrence.new(:every => :month, :on => :last, :weekday => :friday, :interval => :semesterly)
46
+ r = Recurrence.new(:every => :month, :on => :last, :weekday => :friday, :repeat => 3)
47
+
48
+ # Yearly
49
+ r = Recurrence.new(:every => :year, :on => [7, 4]) # => [month, day]
50
+ r = Recurrence.new(:every => :year, :on => [10, 31], :interval => 3)
51
+ r = Recurrence.new(:every => :year, :on => [:jan, 31])
52
+ r = Recurrence.new(:every => :year, :on => [:january, 31])
53
+ r = Recurrence.new(:every => :year, :on => [10, 31], :repeat => 3)
54
+ r = Recurrence.yearly(:on => [:january, 31])
55
+
56
+ # Limit recurrence
57
+ # :starts defaults to Date.today
58
+ # :until defaults to 2037-12-31
59
+ r = Recurrence.new(:every => :day, :starts => Date.today)
60
+ r = Recurrence.new(:every => :day, :until => '2010-01-31')
61
+ r = Recurrence.new(:every => :day, :starts => Date.today, :until => '2010-01-31')
62
+
63
+ # Generate a collection of events which always includes a final event with the given through date
64
+ # :through defaults to being unset
65
+ r = Recurrence.new(:every => :day, :through => '2010-01-31')
66
+ r = Recurrence.new(:every => :day, :starts => Date.today, :through => '2010-01-31')
67
+
68
+ # Remove a date in the series on the given except date(s)
69
+ # :except defaults to being unset
70
+ r = Recurrence.new(:every => :day, :except => '2010-01-31')
71
+ r = Recurrence.new(:every => :day, :except => [Date.today, '2010-01-31'])
72
+
73
+ # Override the next date handler
74
+ r = Recurrence.new(:every => :month, :on => 1, :handler => Proc.new { |day, month, year| raise("Date not allowed!") if year == 2011 && month == 12 && day == 31 })
75
+
76
+ # Shift the recurrences to maintain dates around boundaries (Jan 31 -> Feb 28 -> Mar 28)
77
+ r = Recurrence.new(:every => :month, :on => 31, :shift => true)
78
+
79
+ # Getting an array with all events
80
+ r.events.each {|date| puts date.to_s } # => Memoized array
81
+ r.events!.each {|date| puts date.to_s } # => reset items cache and re-execute it
82
+ r.events(:starts => '2009-01-01').each {|date| puts date.to_s }
83
+ r.events(:until => '2009-01-10').each {|date| puts date.to_s }
84
+ r.events(:through => '2009-01-10').each {|date| puts date.to_s }
85
+ r.events(:starts => '2009-01-05', :until => '2009-01-10').each {|date| puts date.to_s }
86
+
87
+ # Iterating events
88
+ r.each { |date| puts date.to_s } # => Use items method
89
+ r.each! { |date| puts date.to_s } # => Use items! method
90
+
91
+ # Check if a date is included
92
+ r.include?(Date.today) # => true or false
93
+ r.include?('2008-09-21')
94
+
95
+ # Get next available date
96
+ r.next # => Keep the original date object
97
+ r.next! # => Change the internal date object to the next available date
98
+ ```
99
+
100
+ ## Troubleshooting
101
+
102
+ If you're having problems because already have a class/module called Recurrence that is conflicting with this gem, you can require the namespace and create a class that inherits from `SimplesIdeias::Recurrence`.
103
+
104
+ ```ruby
105
+ require "recurrence/namespace"
106
+
107
+ class RecurrentEvent < SimplesIdeias::Recurrence
108
+ end
109
+
110
+ r = RecurrentEvent.new(:every => :day)
111
+ ```
112
+
113
+ If you're using Rails/Bundler or something like that, remember to override the `:require` option.
114
+
115
+ ```ruby
116
+ # Gemfile
117
+ source "https://rubygems.org"
118
+
119
+ gem "recurrence", :require => "recurrence/namespace"
120
+ ```
121
+
122
+ ## Maintainer
123
+
124
+ * Nando Vieira (http://nandovieira.com.br)
125
+
126
+ ## Contributors
127
+
128
+ * https://github.com/fnando/recurrence/graphs/contributors
129
+
130
+ ## License
131
+
132
+ (The MIT License)
133
+
134
+ Permission is hereby granted, free of charge, to any person obtaining
135
+ a copy of this software and associated documentation files (the
136
+ 'Software'), to deal in the Software without restriction, including
137
+ without limitation the rights to use, copy, modify, merge, publish,
138
+ distribute, sublicense, and/or sell copies of the Software, and to
139
+ permit persons to whom the Software is furnished to do so, subject to
140
+ the following conditions:
141
+
142
+ The above copyright notice and this permission notice shall be
143
+ included in all copies or substantial portions of the Software.
144
+
145
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
146
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
147
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
148
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
149
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
150
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
151
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -3,9 +3,3 @@ Bundler::GemHelper.install_tasks
3
3
 
4
4
  require "rspec/core/rake_task"
5
5
  RSpec::Core::RakeTask.new
6
-
7
- require "rdoc/task"
8
- Rake::RDocTask.new do |rd|
9
- rd.main = "README.rdoc"
10
- rd.rdoc_files.include("README.rdoc", "lib/**/*.rb", "History.txt", "License.txt")
11
- end
@@ -35,6 +35,7 @@ module SimplesIdeias
35
35
 
36
36
  @date = next_in_recurrence
37
37
 
38
+ @finished = true if @options[:through] && @date >= @options[:through]
38
39
  @finished, @date = true, nil if @date > @options[:until]
39
40
  shift_to @date if @date && @options[:shift]
40
41
  @date
@@ -57,7 +57,7 @@ module SimplesIdeias
57
57
  # Have a raw month from 0 to 11 interval
58
58
  raw_month = date.month + interval - 1
59
59
 
60
- next_year = date.year + raw_month / 12
60
+ next_year = date.year + raw_month.div(12)
61
61
  next_month = (raw_month % 12) + 1 # change back to ruby interval
62
62
 
63
63
  @options[:handler].call(@options[:on], next_month, next_year)
@@ -65,7 +65,7 @@ module SimplesIdeias
65
65
 
66
66
  def advance_to_month_by_weekday(date, interval=@options[:interval])
67
67
  raw_month = date.month + interval - 1
68
- next_year = date.year + raw_month / 12
68
+ next_year = date.year + raw_month.div(12)
69
69
  next_month = (raw_month % 12) + 1 # change back to ruby interval
70
70
  date = Date.new(next_year, next_month, 1)
71
71
 
@@ -79,7 +79,7 @@ module SimplesIdeias
79
79
 
80
80
  # Go to the previous month if we lost it
81
81
  if date.month != month
82
- weeks = (date.day - 1) / 7 + 1
82
+ weeks = (date.day - 1).div(7) + 1
83
83
  date -= weeks * 7
84
84
  end
85
85
 
@@ -71,6 +71,7 @@ module SimplesIdeias
71
71
  # Recurrence.daily(:starts => 3.days.from_now)
72
72
  # Recurrence.daily(:until => 10.days.from_now)
73
73
  # Recurrence.daily(:repeat => 5)
74
+ # Recurrence.daily(:except => Date.tomorrow)
74
75
  #
75
76
  def self.daily(options = {})
76
77
  options[:every] = :day
@@ -139,24 +140,16 @@ module SimplesIdeias
139
140
  # Recurrence.new(:every => :year, :on => [:jan, 14])
140
141
  #
141
142
  def initialize(options)
142
- raise ArgumentError, ":every option is required" unless options.key?(:every)
143
- raise ArgumentError, "invalid :every option" unless FREQUENCY.include?(options[:every].to_s)
143
+ validate_initialize_options(options)
144
+
145
+ options[:except] = [options[:except]].flatten.map {|d| as_date(d)} if options[:except]
144
146
 
145
147
  @options = options
146
148
  @_options = initialize_dates(options.dup)
147
149
  @_options[:interval] ||= 1
148
150
  @_options[:handler] ||= Handler::FallBack
149
151
 
150
- @event = case @_options[:every].to_sym
151
- when :day
152
- Event::Daily.new(@_options)
153
- when :week
154
- Event::Weekly.new(@_options)
155
- when :month
156
- Event::Monthly.new(@_options)
157
- when :year
158
- Event::Yearly.new(@_options)
159
- end
152
+ @event = initialize_event(@_options[:every])
160
153
  end
161
154
 
162
155
  # Reset the recurrence cache, returning to the first available date.
@@ -221,12 +214,14 @@ module SimplesIdeias
221
214
  # [5] Sat, 20 Nov 2010
222
215
  # ]
223
216
  #
224
- def events(options={})
217
+ def events(options = {})
225
218
  options[:starts] = as_date(options[:starts])
226
219
  options[:until] = as_date(options[:until])
220
+ options[:through] = as_date(options[:through])
227
221
  options[:repeat] ||= @options[:repeat]
222
+ options[:except] ||= @options[:except]
228
223
 
229
- reset! if options[:starts] || options[:until]
224
+ reset! if options[:starts] || options[:until] || options[:through]
230
225
 
231
226
  @events ||= Array.new.tap do |list|
232
227
  loop do
@@ -236,12 +231,14 @@ module SimplesIdeias
236
231
 
237
232
  valid_start = options[:starts].nil? || date >= options[:starts]
238
233
  valid_until = options[:until].nil? || date <= options[:until]
239
- list << date if valid_start && valid_until
234
+ valid_except = options[:except].nil? || !options[:except].include?(date)
235
+ list << date if valid_start && valid_until && valid_except
240
236
 
241
237
  stop_repeat = options[:repeat] && list.size == options[:repeat]
242
238
  stop_until = options[:until] && options[:until] <= date
239
+ stop_through = options[:through] && options[:through] <= date
243
240
 
244
- break if stop_until || stop_repeat
241
+ break if stop_until || stop_repeat || stop_through
245
242
  end
246
243
  end
247
244
  end
@@ -281,8 +278,26 @@ module SimplesIdeias
281
278
  end
282
279
 
283
280
  private
281
+ def validate_initialize_options(options)
282
+ raise ArgumentError, ":every option is required" unless options.key?(:every)
283
+ raise ArgumentError, ":every option is invalid" unless FREQUENCY.include?(options[:every].to_s)
284
+ end
285
+
286
+ def initialize_event(type)
287
+ case type.to_sym
288
+ when :day
289
+ Event::Daily.new(@_options)
290
+ when :week
291
+ Event::Weekly.new(@_options)
292
+ when :month
293
+ Event::Monthly.new(@_options)
294
+ when :year
295
+ Event::Yearly.new(@_options)
296
+ end
297
+ end
298
+
284
299
  def initialize_dates(options) # :nodoc:
285
- [:starts, :until].each do |name|
300
+ [:starts, :until, :through].each do |name|
286
301
  options[name] = as_date(options[name])
287
302
  end
288
303
 
@@ -2,7 +2,7 @@ module SimplesIdeias
2
2
  class Recurrence
3
3
  module Version
4
4
  MAJOR = 1
5
- MINOR = 2
5
+ MINOR = 3
6
6
  PATCH = 0
7
7
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
8
8
  end
@@ -1,6 +1,4 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require 'recurrence/version'
1
+ require "./lib/recurrence/version"
4
2
 
5
3
  Gem::Specification.new do |s|
6
4
  s.name = "recurrence"
@@ -17,8 +15,8 @@ Gem::Specification.new do |s|
17
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
16
  s.require_paths = ["lib"]
19
17
 
20
- s.add_dependency "activesupport", ">= 2.3.0"
18
+ s.add_dependency "activesupport"
21
19
  s.add_dependency "i18n"
22
- s.add_development_dependency "rspec", "~> 2.6"
23
- s.add_development_dependency "rake", "~> 0.9"
20
+ s.add_development_dependency "rspec", "3.0.0.beta2"
21
+ s.add_development_dependency "rake"
24
22
  end
@@ -3,64 +3,64 @@ require "spec_helper"
3
3
  describe Recurrence do
4
4
  let(:enumerator_constant){ RUBY_VERSION > "1.9.0" ? Enumerator : Enumerable::Enumerator }
5
5
 
6
- it "should require :every option" do
6
+ it "requires :every option" do
7
7
  expect { recurrence({}) }.to raise_error(ArgumentError)
8
8
  end
9
9
 
10
- it "should require valid :every option" do
10
+ it "requires valid :every option" do
11
11
  expect { recurrence(:every => "invalid") }.to raise_error(ArgumentError)
12
12
  end
13
13
 
14
- it "should require :interval to be greater than zero when provided" do
14
+ it "requires :interval to be greater than zero when provided" do
15
15
  expect { recurrence(:every => :day, :interval => 0) }.to raise_error(ArgumentError)
16
16
  end
17
17
 
18
- it "should require :repeat to be greater than zero when provided" do
18
+ it "requires :repeat to be greater than zero when provided" do
19
19
  expect { recurrence(:every => :day, :repeat => 0) }.to raise_error(ArgumentError)
20
20
  end
21
21
 
22
- it "should return an enumerator when Recurrence#each is called without a block" do
23
- recurrence(:every => :day).each.should be_instance_of(enumerator_constant)
22
+ it "returns an enumerator when Recurrence#each is called without a block" do
23
+ expect(recurrence(:every => :day).each).to be_instance_of(enumerator_constant)
24
24
  end
25
25
 
26
- it "should return an enumerator when Recurrence#each! is called without a block" do
27
- recurrence(:every => :day).each!.should be_instance_of(enumerator_constant)
26
+ it "returns an enumerator when Recurrence#each! is called without a block" do
27
+ expect(recurrence(:every => :day).each!).to be_instance_of(enumerator_constant)
28
28
  end
29
29
 
30
30
  Recurrence::Event::Monthly::INTERVALS.each do |interval|
31
- it "should accept valid :interval symbol for monthly recurrence (#{interval[0]})" do
31
+ it "accepts valid :interval symbol for monthly recurrence (#{interval[0]})" do
32
32
  expect {
33
33
  recurrence(:every => :month, :on => 10, :interval => interval[0])
34
- }.to_not raise_error(ArgumentError)
34
+ }.to_not raise_error
35
35
  end
36
36
  end
37
37
 
38
38
  Recurrence::Event::Yearly::MONTHS.each do |month_name, month_number|
39
- it "should accept month as symbol for yearly recurrence (#{month_name})" do
39
+ it "accepts month as symbol for yearly recurrence (#{month_name})" do
40
40
  expect {
41
41
  recurrence(:every => :year, :on => [month_name, 10])
42
- }.to_not raise_error(ArgumentError)
42
+ }.to_not raise_error
43
43
  end
44
44
  end
45
45
 
46
- it "should require month to be a valid symbol for yearly recurrence" do
46
+ it "requires month to be a valid symbol for yearly recurrence" do
47
47
  expect {
48
48
  recurrence(:every => :year, :on => [:invalid, 10])
49
49
  }.to raise_error(ArgumentError)
50
50
  end
51
51
 
52
- it "should require :interval to be a valid symbol for monthly recurrence" do
52
+ it "requires :interval to be a valid symbol for monthly recurrence" do
53
53
  expect {
54
54
  recurrence(:every => :month, :on => 10, :interval => :invalid)
55
55
  }.to raise_error(ArgumentError)
56
56
  end
57
57
 
58
58
  describe ".default_starts_date" do
59
- it "should return Date.today by default" do
60
- Recurrence.default_starts_date.should == Date.today
59
+ it "returns Date.today by default" do
60
+ expect(Recurrence.default_starts_date).to eq(Date.today)
61
61
  end
62
62
 
63
- it "should require only strings and procs" do
63
+ it "requires only strings and procs" do
64
64
  expect {
65
65
  Recurrence.default_starts_date = Date.tomorrow
66
66
  }.to raise_error(ArgumentError)
@@ -70,13 +70,13 @@ describe Recurrence do
70
70
  before { Recurrence.default_starts_date = "Date.tomorrow" }
71
71
  after { Recurrence.default_starts_date = nil }
72
72
 
73
- it "should return Date.tomorrow" do
74
- Recurrence.default_starts_date.should == Date.tomorrow
73
+ it "returns Date.tomorrow" do
74
+ expect(Recurrence.default_starts_date).to eq(Date.tomorrow)
75
75
  end
76
76
 
77
- it "should have effect on generated events" do
77
+ it "has effect on generated events" do
78
78
  r = Recurrence.new(:every => :day, :until => 3.days.from_now.to_date)
79
- r.events.first.should == Date.tomorrow
79
+ expect(r.events.first).to eq(Date.tomorrow)
80
80
  end
81
81
  end
82
82
 
@@ -84,93 +84,128 @@ describe Recurrence do
84
84
  before { Recurrence.default_starts_date = lambda { Date.tomorrow } }
85
85
  after { Recurrence.default_starts_date = nil }
86
86
 
87
- it "should return Date.tomorrow" do
88
- Recurrence.default_starts_date.should == Date.tomorrow
87
+ it "returns Date.tomorrow" do
88
+ expect(Recurrence.default_starts_date).to eq(Date.tomorrow)
89
89
  end
90
90
 
91
- it "should have effect on generated events" do
91
+ it "has effect on generated events" do
92
92
  r = Recurrence.new(:every => :day, :until => 3.days.from_now.to_date)
93
- r.events.first.should == Date.tomorrow
93
+ expect(r.events.first).to eq(Date.tomorrow)
94
94
  end
95
95
  end
96
96
  end
97
97
 
98
98
  context "with daily recurring" do
99
- it "should recur until limit date" do
99
+ it "recurs until limit date" do
100
100
  @recurrence = Recurrence.daily
101
- @recurrence.events[-1].should == Date.parse("2037-12-31")
101
+ expect(@recurrence.events[-1]).to eq(Date.parse("2037-12-31"))
102
102
  end
103
103
 
104
- it "should repeat until 1 month from now" do
104
+ it "repeats until 1 month from now" do
105
105
  date = 1.month.from_now
106
106
  @recurrence = recurrence(:every => :day, :until => date.to_date)
107
- @recurrence.events[-1].should == date.to_date
107
+ expect(@recurrence.events[-1]).to eq(date.to_date)
108
108
  end
109
109
 
110
- it "should start 2 months ago (#{2.months.ago.to_s(:date)})" do
110
+ it "recurs through 1 month from now" do
111
+ date = 1.month.from_now
112
+ @recurrence = recurrence(:every => :day, :through => date.to_date)
113
+ expect(@recurrence.events[-1]).to eq(date.to_date)
114
+ end
115
+
116
+ it "starts 2 months ago (#{2.months.ago.to_s(:date)})" do
111
117
  date = 2.months.ago
112
118
  @recurrence = recurrence(:every => :day, :starts => date.to_date)
113
- @recurrence.events[0].should == date.to_date
114
- @recurrence.events[1].should == (date + 1.day).to_date
115
- @recurrence.events[2].should == (date + 2.day).to_date
119
+ expect(@recurrence.events[0]).to eq(date.to_date)
120
+ expect(@recurrence.events[1]).to eq((date + 1.day).to_date)
121
+ expect(@recurrence.events[2]).to eq((date + 2.day).to_date)
116
122
  end
117
123
 
118
- it "should start at 2008-03-19 and repeat until 2008-04-24" do
124
+ it "starts at 2008-03-19 and repeat until 2008-04-24" do
119
125
  @recurrence = recurrence(:every => :day, :starts => "2008-03-19", :until => "2008-04-24")
120
- @recurrence.events[0].to_s.should == "2008-03-19"
121
- @recurrence.events[1].to_s.should == "2008-03-20"
122
- @recurrence.events[-1].to_s.should == "2008-04-24"
126
+ expect(@recurrence.events[0].to_s).to eq("2008-03-19")
127
+ expect(@recurrence.events[1].to_s).to eq("2008-03-20")
128
+ expect(@recurrence.events[-1].to_s).to eq("2008-04-24")
123
129
  end
124
130
 
125
- it "should use interval" do
131
+ it "starts at 2008-03-19 and repeat through 2008-04-24" do
132
+ @recurrence = recurrence(:every => :day, :starts => "2008-03-19", :through => "2008-04-24")
133
+ expect(@recurrence.events[0].to_s).to eq("2008-03-19")
134
+ expect(@recurrence.events[1].to_s).to eq("2008-03-20")
135
+ expect(@recurrence.events[-1].to_s).to eq("2008-04-24")
136
+ end
137
+
138
+ it "uses interval" do
126
139
  @recurrence = recurrence(:every => :day, :interval => 2, :starts => "2008-09-21")
127
- @recurrence.events[0].to_s.should == "2008-09-21"
128
- @recurrence.events[1].to_s.should == "2008-09-23"
129
- @recurrence.events[2].to_s.should == "2008-09-25"
140
+ expect(@recurrence.events[0].to_s).to eq("2008-09-21")
141
+ expect(@recurrence.events[1].to_s).to eq("2008-09-23")
142
+ expect(@recurrence.events[2].to_s).to eq("2008-09-25")
130
143
  end
131
144
 
132
- it "should use repeat" do
145
+ it "uses repeat" do
133
146
  @recurrence = recurrence(:every => :day, :starts => "2008-09-21", :repeat => 10)
134
- @recurrence.events.size.should == 10
147
+ expect(@recurrence.events.size).to eq(10)
135
148
  end
136
149
 
137
- it "should have a lacking day if the interval does not match the last day" do
150
+ it "has a lacking day if the interval does not match the last day" do
138
151
  @recurrence = recurrence(
139
152
  :every => :day,
140
153
  :starts => "2008-03-19",
141
154
  :until => "2008-04-25",
142
155
  :interval => 2
143
156
  )
144
- @recurrence.events[-1].to_s.should == "2008-04-24"
157
+ expect(@recurrence.events[-1].to_s).to eq("2008-04-24")
158
+ end
159
+
160
+ it "doesn't have a lacking day if the interval does not match the last day" do
161
+ @recurrence = recurrence(
162
+ :every => :day,
163
+ :starts => "2008-03-19",
164
+ :through => "2008-04-25",
165
+ :interval => 2
166
+ )
167
+ expect(@recurrence.events[-1].to_s).to eq("2008-04-26")
168
+ end
169
+
170
+ it "uses except" do
171
+ @recurrence = Recurrence.daily(:except => Date.tomorrow)
172
+ expect(@recurrence.events.include?(Date.tomorrow)).to be_falsey
173
+ expect(@recurrence.events.include?(Date.tomorrow+1.day)).to be_truthy
145
174
  end
146
175
  end
147
176
 
148
177
  context "with weekly recurring" do
149
- it "should recur until limit date" do
178
+ it "recurs until limit date" do
150
179
  @recurrence = Recurrence.weekly(:on => :thursday)
151
- @recurrence.events[-1].should == Date.parse("2037-12-31")
180
+ expect(@recurrence.events[-1]).to eq(Date.parse("2037-12-31"))
152
181
  end
153
182
 
154
- it "should repeat 6 weeks from now" do
183
+ it "repeats 6 weeks from now" do
155
184
  date = 6.weeks.from_now
156
185
  @recurrence = recurrence(:every => :week, :on => date.wday, :until => date.to_date)
157
- @recurrence.events[-1].should == date.to_date
186
+ expect(@recurrence.events[-1]).to eq(date.to_date)
187
+ end
188
+
189
+ it "repeats through 6 weeks from now" do
190
+ date = 6.weeks.from_now
191
+ @recurrence = recurrence(:every => :week, :on => date.wday, :through => date.to_date)
192
+ expect(@recurrence.events[-1]).to eq(date.to_date)
158
193
  end
159
194
 
160
- it "should start 3 months ago (#{3.months.ago.to_s(:date)})" do
195
+ it "starts 3 months ago (#{3.months.ago.to_s(:date)})" do
161
196
  date = 3.months.ago
162
197
 
163
198
  @recurrence = recurrence(:every => :week, :on => date.wday, :starts => date.to_date)
164
- @recurrence.events[0].should == date.to_date
165
- @recurrence.events[1].should == (date + 1.week).to_date
166
- @recurrence.events[2].should == (date + 2.weeks).to_date
167
- @recurrence.events[3].should == (date + 3.weeks).to_date
168
- @recurrence.events[4].should == (date + 4.weeks).to_date
169
- @recurrence.events[5].should == (date + 5.weeks).to_date
170
- @recurrence.events[6].should == (date + 6.weeks).to_date
199
+ expect(@recurrence.events[0]).to eq(date.to_date)
200
+ expect(@recurrence.events[1]).to eq((date + 1.week).to_date)
201
+ expect(@recurrence.events[2]).to eq((date + 2.weeks).to_date)
202
+ expect(@recurrence.events[3]).to eq((date + 3.weeks).to_date)
203
+ expect(@recurrence.events[4]).to eq((date + 4.weeks).to_date)
204
+ expect(@recurrence.events[5]).to eq((date + 5.weeks).to_date)
205
+ expect(@recurrence.events[6]).to eq((date + 6.weeks).to_date)
171
206
  end
172
207
 
173
- it "should start at 2008-02-29 and repeat until 2008-03-14" do
208
+ it "starts at 2008-02-29 and repeat until 2008-03-14" do
174
209
  starts = Date.parse("2008-02-29")
175
210
  ends = Date.parse("2008-03-14")
176
211
 
@@ -180,12 +215,27 @@ describe Recurrence do
180
215
  :starts => starts,
181
216
  :until => ends.to_date
182
217
  )
183
- @recurrence.events[0].to_s.should == "2008-02-29"
184
- @recurrence.events[1].to_s.should == "2008-03-07"
185
- @recurrence.events[-1].to_s.should == ends.to_s
218
+ expect(@recurrence.events[0].to_s).to eq("2008-02-29")
219
+ expect(@recurrence.events[1].to_s).to eq("2008-03-07")
220
+ expect(@recurrence.events[-1].to_s).to eq(ends.to_s)
186
221
  end
187
222
 
188
- it "should use interval" do
223
+ it "starts at 2008-02-29 and repeat through 2008-03-14" do
224
+ starts = Date.parse("2008-02-29")
225
+ ends = Date.parse("2008-03-14")
226
+
227
+ @recurrence = recurrence(
228
+ :every => :week,
229
+ :on => :friday,
230
+ :starts => starts,
231
+ :through=> ends.to_date
232
+ )
233
+ expect(@recurrence.events[0].to_s).to eq("2008-02-29")
234
+ expect(@recurrence.events[1].to_s).to eq("2008-03-07")
235
+ expect(@recurrence.events[-1].to_s).to eq(ends.to_s)
236
+ end
237
+
238
+ it "uses interval" do
189
239
  starts = Date.parse("2008-09-21")
190
240
  @recurrence = recurrence(
191
241
  :every => :week,
@@ -194,16 +244,16 @@ describe Recurrence do
194
244
  :starts => starts,
195
245
  :until => "2009-01-01"
196
246
  )
197
- @recurrence.events[0].to_s.should == "2008-09-21"
198
- @recurrence.events[1].to_s.should == "2008-10-05"
199
- @recurrence.events[2].to_s.should == "2008-10-19"
200
- @recurrence.events[3].to_s.should == "2008-11-02"
201
- @recurrence.events[4].to_s.should == "2008-11-16"
202
- @recurrence.events[5].to_s.should == "2008-11-30"
203
- @recurrence.events[6].to_s.should == "2008-12-14"
247
+ expect(@recurrence.events[0].to_s).to eq("2008-09-21")
248
+ expect(@recurrence.events[1].to_s).to eq("2008-10-05")
249
+ expect(@recurrence.events[2].to_s).to eq("2008-10-19")
250
+ expect(@recurrence.events[3].to_s).to eq("2008-11-02")
251
+ expect(@recurrence.events[4].to_s).to eq("2008-11-16")
252
+ expect(@recurrence.events[5].to_s).to eq("2008-11-30")
253
+ expect(@recurrence.events[6].to_s).to eq("2008-12-14")
204
254
  end
205
255
 
206
- it "should use repeat" do
256
+ it "uses repeat" do
207
257
  starts = Date.parse("2008-09-21")
208
258
  @recurrence = recurrence(
209
259
  :every => :week,
@@ -212,10 +262,10 @@ describe Recurrence do
212
262
  :until => "2011-01-01",
213
263
  :repeat => 5
214
264
  )
215
- @recurrence.events.size.should == 5
265
+ expect(@recurrence.events.size).to eq(5)
216
266
  end
217
267
 
218
- it "should occur several times per week" do
268
+ it "occurs several times per week" do
219
269
  starts = Date.parse("2008-09-21") #=> sunday
220
270
  @recurrence = recurrence(
221
271
  :every => :week,
@@ -224,14 +274,14 @@ describe Recurrence do
224
274
  :starts => starts,
225
275
  :until => "2009-01-01"
226
276
  )
227
- @recurrence.events[0].to_s.should == "2008-09-21"
228
- @recurrence.events[1].to_s.should == "2008-09-27"
229
- @recurrence.events[2].to_s.should == "2008-10-05"
230
- @recurrence.events[3].to_s.should == "2008-10-11"
231
- @recurrence.events[4].to_s.should == "2008-10-19"
232
- @recurrence.events[5].to_s.should == "2008-10-25"
233
- @recurrence.events[6].to_s.should == "2008-11-02"
234
- @recurrence.events[7].to_s.should == "2008-11-08"
277
+ expect(@recurrence.events[0].to_s).to eq("2008-09-21")
278
+ expect(@recurrence.events[1].to_s).to eq("2008-09-27")
279
+ expect(@recurrence.events[2].to_s).to eq("2008-10-05")
280
+ expect(@recurrence.events[3].to_s).to eq("2008-10-11")
281
+ expect(@recurrence.events[4].to_s).to eq("2008-10-19")
282
+ expect(@recurrence.events[5].to_s).to eq("2008-10-25")
283
+ expect(@recurrence.events[6].to_s).to eq("2008-11-02")
284
+ expect(@recurrence.events[7].to_s).to eq("2008-11-08")
235
285
 
236
286
  starts = Date.parse("2008-09-21") #=> sunday
237
287
  @recurrence = recurrence(
@@ -240,15 +290,15 @@ describe Recurrence do
240
290
  :starts => starts,
241
291
  :until => "2009-01-01"
242
292
  )
243
- @recurrence.events[0].to_s.should == "2008-09-22"
244
- @recurrence.events[1].to_s.should == "2008-09-24"
245
- @recurrence.events[2].to_s.should == "2008-09-26"
246
- @recurrence.events[3].to_s.should == "2008-09-29"
247
- @recurrence.events[4].to_s.should == "2008-10-01"
248
- @recurrence.events[5].to_s.should == "2008-10-03"
293
+ expect(@recurrence.events[0].to_s).to eq("2008-09-22")
294
+ expect(@recurrence.events[1].to_s).to eq("2008-09-24")
295
+ expect(@recurrence.events[2].to_s).to eq("2008-09-26")
296
+ expect(@recurrence.events[3].to_s).to eq("2008-09-29")
297
+ expect(@recurrence.events[4].to_s).to eq("2008-10-01")
298
+ expect(@recurrence.events[5].to_s).to eq("2008-10-03")
249
299
  end
250
300
 
251
- it "should run until next available saturday" do
301
+ it "runs until next available saturday" do
252
302
  starts = Date.parse("2008-09-21") # => sunday
253
303
  @recurrence = recurrence(
254
304
  :every => :week,
@@ -256,31 +306,44 @@ describe Recurrence do
256
306
  :starts => starts,
257
307
  :until => "2009-01-01"
258
308
  )
259
- @recurrence.events[0].to_s.should == "2008-09-27"
309
+ expect(@recurrence.events[0].to_s).to eq("2008-09-27")
310
+ end
311
+
312
+ it "uses except" do
313
+ date = 6.weeks.from_now
314
+ @recurrence = recurrence(:every => :week, :on => date.wday, :except => 2.weeks.from_now.to_date)
315
+ expect(@recurrence.events.include?(1.week.from_now.to_date)).to be_truthy
316
+ expect(@recurrence.events.include?(2.weeks.from_now.to_date)).to be_falsey
260
317
  end
261
318
  end
262
319
 
263
320
  context "with monthly recurring" do
264
321
  context "using day" do
265
- it "should recur until limit date" do
322
+ it "recurs until limit date" do
266
323
  @recurrence = Recurrence.monthly(:on => 31)
267
- @recurrence.events[-1].should == Date.parse("2037-12-31")
324
+ expect(@recurrence.events[-1]).to eq(Date.parse("2037-12-31"))
268
325
  end
269
326
 
270
- it "should repeat until 8 months from now" do
327
+ it "repeats until 8 months from now" do
271
328
  date = 8.months.from_now
272
329
  @recurrence = recurrence(:every => :month, :on => date.day, :until => date.to_date)
273
- @recurrence.events[-1].should == date.to_date
330
+ expect(@recurrence.events[-1]).to eq(date.to_date)
331
+ end
332
+
333
+ it "repeats through 8 months from now" do
334
+ date = 8.months.from_now
335
+ @recurrence = recurrence(:every => :month, :on => date.day, :through => date.to_date)
336
+ expect(@recurrence.events[-1]).to eq(date.to_date)
274
337
  end
275
338
 
276
- it "should start 9 months ago" do
339
+ it "starts 9 months ago" do
277
340
  date = 9.months.ago
278
341
 
279
342
  @recurrence = recurrence(:every => :month, :on => date.day, :starts => date.to_date)
280
- @recurrence.events[0].should == date.to_date
343
+ expect(@recurrence.events[0]).to eq(date.to_date)
281
344
  end
282
345
 
283
- it "should start at 2008-06-07 and repeat until 2008-11-07" do
346
+ it "starts at 2008-06-07 and repeat until 2008-11-07" do
284
347
  starts = Date.parse("2008-06-07")
285
348
  ends = Date.parse("2008-11-07")
286
349
 
@@ -290,11 +353,25 @@ describe Recurrence do
290
353
  :starts => starts,
291
354
  :until => ends
292
355
  )
293
- @recurrence.events[0].to_s.should == "2008-06-07"
294
- @recurrence.events[-1].to_s.should == "2008-11-07"
356
+ expect(@recurrence.events[0].to_s).to eq("2008-06-07")
357
+ expect(@recurrence.events[-1].to_s).to eq("2008-11-07")
358
+ end
359
+
360
+ it "starts at 2008-06-07 and repeat through 2008-11-07" do
361
+ starts = Date.parse("2008-06-07")
362
+ ends = Date.parse("2008-11-07")
363
+
364
+ @recurrence = recurrence(
365
+ :every => :month,
366
+ :on => starts.day,
367
+ :starts => starts,
368
+ :through=> ends
369
+ )
370
+ expect(@recurrence.events[0].to_s).to eq("2008-06-07")
371
+ expect(@recurrence.events[-1].to_s).to eq("2008-11-07")
295
372
  end
296
373
 
297
- it "should run until next available 27th" do
374
+ it "runs until next available 27th" do
298
375
  starts = Date.parse("2008-09-28")
299
376
 
300
377
  @recurrence = recurrence(
@@ -303,10 +380,22 @@ describe Recurrence do
303
380
  :starts => starts,
304
381
  :until => "2009-01-01"
305
382
  )
306
- @recurrence.events[0].to_s.should == "2008-10-27"
383
+ expect(@recurrence.events[0].to_s).to eq("2008-10-27")
384
+ end
385
+
386
+ it "runs through final available 27th" do
387
+ starts = Date.parse("2008-09-28")
388
+
389
+ @recurrence = recurrence(
390
+ :every => :month,
391
+ :on => 27,
392
+ :starts => starts,
393
+ :through=> "2009-01-01"
394
+ )
395
+ expect(@recurrence.events[-1].to_s).to eq("2009-01-27")
307
396
  end
308
397
 
309
- it "should use interval" do
398
+ it "uses interval" do
310
399
  starts = Date.parse("2008-01-31")
311
400
  @recurrence = recurrence(
312
401
  :every => :month,
@@ -315,13 +404,13 @@ describe Recurrence do
315
404
  :starts => starts,
316
405
  :until => "2010-01-01"
317
406
  )
318
- @recurrence.events[0].to_s.should == "2008-01-31"
319
- @recurrence.events[1].to_s.should == "2008-03-31"
320
- @recurrence.events[2].to_s.should == "2008-05-31"
321
- @recurrence.events[3].to_s.should == "2008-07-31"
322
- @recurrence.events[4].to_s.should == "2008-09-30"
323
- @recurrence.events[5].to_s.should == "2008-11-30"
324
- @recurrence.events[6].to_s.should == "2009-01-31"
407
+ expect(@recurrence.events[0].to_s).to eq("2008-01-31")
408
+ expect(@recurrence.events[1].to_s).to eq("2008-03-31")
409
+ expect(@recurrence.events[2].to_s).to eq("2008-05-31")
410
+ expect(@recurrence.events[3].to_s).to eq("2008-07-31")
411
+ expect(@recurrence.events[4].to_s).to eq("2008-09-30")
412
+ expect(@recurrence.events[5].to_s).to eq("2008-11-30")
413
+ expect(@recurrence.events[6].to_s).to eq("2009-01-31")
325
414
 
326
415
  starts = Date.parse("2008-01-31")
327
416
  @recurrence = recurrence(
@@ -331,12 +420,12 @@ describe Recurrence do
331
420
  :starts => starts,
332
421
  :until => "2010-01-01"
333
422
  )
334
- @recurrence.events[0].to_s.should == "2008-04-29"
335
- @recurrence.events[1].to_s.should == "2008-07-29"
336
- @recurrence.events[2].to_s.should == "2008-10-29"
337
- @recurrence.events[3].to_s.should == "2009-01-29"
338
- @recurrence.events[4].to_s.should == "2009-04-29"
339
- @recurrence.events[5].to_s.should == "2009-07-29"
423
+ expect(@recurrence.events[0].to_s).to eq("2008-04-29")
424
+ expect(@recurrence.events[1].to_s).to eq("2008-07-29")
425
+ expect(@recurrence.events[2].to_s).to eq("2008-10-29")
426
+ expect(@recurrence.events[3].to_s).to eq("2009-01-29")
427
+ expect(@recurrence.events[4].to_s).to eq("2009-04-29")
428
+ expect(@recurrence.events[5].to_s).to eq("2009-07-29")
340
429
 
341
430
  starts = Date.parse("2008-02-29")
342
431
  @recurrence = recurrence(
@@ -346,13 +435,13 @@ describe Recurrence do
346
435
  :starts => starts,
347
436
  :until => "2010-01-01"
348
437
  )
349
- @recurrence.events[0].to_s.should == "2008-02-29"
350
- @recurrence.events[1].to_s.should == "2008-06-30"
351
- @recurrence.events[2].to_s.should == "2008-10-31"
352
- @recurrence.events[3].to_s.should == "2009-02-28"
438
+ expect(@recurrence.events[0].to_s).to eq("2008-02-29")
439
+ expect(@recurrence.events[1].to_s).to eq("2008-06-30")
440
+ expect(@recurrence.events[2].to_s).to eq("2008-10-31")
441
+ expect(@recurrence.events[3].to_s).to eq("2009-02-28")
353
442
  end
354
443
 
355
- it "should use repeat" do
444
+ it "uses repeat" do
356
445
  starts = Date.parse("2008-01-31")
357
446
  @recurrence = recurrence(
358
447
  :every => :month,
@@ -361,22 +450,28 @@ describe Recurrence do
361
450
  :until => "2010-01-01",
362
451
  :repeat => 5
363
452
  )
364
- @recurrence.events.size.should == 5
453
+ expect(@recurrence.events.size).to eq(5)
454
+ end
455
+
456
+ it "uses except" do
457
+ @recurrence = recurrence(:every => :month, :on => Date.today.day, :except => 8.months.from_now.to_date)
458
+ expect(@recurrence.events.include?(7.months.from_now.to_date)).to be_truthy
459
+ expect(@recurrence.events.include?(8.months.from_now.to_date)).to be_falsey
365
460
  end
366
461
  end
367
462
 
368
463
  context "using weekday" do
369
- it "should recur until limit date" do
464
+ it "recurs until limit date" do
370
465
  @recurrence = Recurrence.daily(:on => 5, :weekday => :thursday)
371
- @recurrence.events[-1].should == Date.parse("2037-12-31")
466
+ expect(@recurrence.events[-1]).to eq(Date.parse("2037-12-31"))
372
467
  end
373
468
 
374
- it "should use weekday shortcut" do
469
+ it "uses weekday shortcut" do
375
470
  @recurrence = Recurrence.daily(:on => 5, :weekday => :thu)
376
- @recurrence.events[-1].should == Date.parse("2037-12-31")
471
+ expect(@recurrence.events[-1]).to eq(Date.parse("2037-12-31"))
377
472
  end
378
473
 
379
- it "should repeat until 8 months from now" do
474
+ it "repeats until 8 months from now" do
380
475
  date = 8.months.from_now
381
476
  week = (date.day - 1) / 7 + 1
382
477
  @recurrence = recurrence(
@@ -385,10 +480,22 @@ describe Recurrence do
385
480
  :weekday => date.wday,
386
481
  :until => date.to_date
387
482
  )
388
- @recurrence.events[-1].should == date.to_date
483
+ expect(@recurrence.events[-1]).to eq(date.to_date)
389
484
  end
390
485
 
391
- it "should start 9 months ago" do
486
+ it "repeats through 8 months from now" do
487
+ date = 8.months.from_now
488
+ week = (date.day - 1) / 7 + 1
489
+ @recurrence = recurrence(
490
+ :every => :month,
491
+ :on => week,
492
+ :weekday => date.wday,
493
+ :through => date.to_date
494
+ )
495
+ expect(@recurrence.events[-1]).to eq(date.to_date)
496
+ end
497
+
498
+ it "starts 9 months ago" do
392
499
  date = 9.months.ago
393
500
  week = (date.day - 1) / 7 + 1
394
501
  @recurrence = recurrence(
@@ -397,10 +504,10 @@ describe Recurrence do
397
504
  :weekday => date.wday,
398
505
  :starts => date.to_date
399
506
  )
400
- @recurrence.events[0].should == date.to_date
507
+ expect(@recurrence.events[0]).to eq(date.to_date)
401
508
  end
402
509
 
403
- it "should start at 2008-06-07 and repeat until 2008-11-01 (first saturday)" do
510
+ it "starts at 2008-06-07 and repeat until 2008-11-01 (first saturday)" do
404
511
  starts = Date.parse("2008-06-07")
405
512
  ends = Date.parse("2008-11-01")
406
513
 
@@ -411,11 +518,11 @@ describe Recurrence do
411
518
  :starts => starts,
412
519
  :until => ends
413
520
  )
414
- @recurrence.events[0].to_s.should == "2008-06-07"
415
- @recurrence.events[-1].to_s.should == "2008-11-01"
521
+ expect(@recurrence.events[0].to_s).to eq("2008-06-07")
522
+ expect(@recurrence.events[-1].to_s).to eq("2008-11-01")
416
523
  end
417
524
 
418
- it "should start at 2008-06-29 and repeat until 2008-11-30 (last sunday)" do
525
+ it "starts at 2008-06-29 and repeat until 2008-11-30 (last sunday)" do
419
526
  starts = Date.parse("2008-06-29")
420
527
  ends = Date.parse("2008-11-30")
421
528
 
@@ -426,11 +533,11 @@ describe Recurrence do
426
533
  :starts => starts,
427
534
  :until => ends
428
535
  )
429
- @recurrence.events[0].to_s.should == "2008-06-29"
430
- @recurrence.events[-1].to_s.should == "2008-11-30"
536
+ expect(@recurrence.events[0].to_s).to eq("2008-06-29")
537
+ expect(@recurrence.events[-1].to_s).to eq("2008-11-30")
431
538
  end
432
539
 
433
- it "should use interval" do
540
+ it "uses interval" do
434
541
  starts = Date.parse("2009-01-01")
435
542
  @recurrence = recurrence(
436
543
  :every => :month,
@@ -440,16 +547,16 @@ describe Recurrence do
440
547
  :starts => starts,
441
548
  :until => "2010-02-01"
442
549
  )
443
- @recurrence.events[0].to_s.should == "2009-01-18"
444
- @recurrence.events[1].to_s.should == "2009-03-15"
445
- @recurrence.events[2].to_s.should == "2009-05-17"
446
- @recurrence.events[3].to_s.should == "2009-07-19"
447
- @recurrence.events[4].to_s.should == "2009-09-20"
448
- @recurrence.events[5].to_s.should == "2009-11-15"
449
- @recurrence.events[6].to_s.should == "2010-01-17"
550
+ expect(@recurrence.events[0].to_s).to eq("2009-01-18")
551
+ expect(@recurrence.events[1].to_s).to eq("2009-03-15")
552
+ expect(@recurrence.events[2].to_s).to eq("2009-05-17")
553
+ expect(@recurrence.events[3].to_s).to eq("2009-07-19")
554
+ expect(@recurrence.events[4].to_s).to eq("2009-09-20")
555
+ expect(@recurrence.events[5].to_s).to eq("2009-11-15")
556
+ expect(@recurrence.events[6].to_s).to eq("2010-01-17")
450
557
  end
451
558
 
452
- it "should use repeat" do
559
+ it "uses repeat" do
453
560
  starts = Date.parse("2009-01-01")
454
561
  @recurrence = recurrence(
455
562
  :every => :month,
@@ -459,7 +566,7 @@ describe Recurrence do
459
566
  :until => "2011-02-01",
460
567
  :repeat => 5
461
568
  )
462
- @recurrence.events.size.should == 5
569
+ expect(@recurrence.events.size).to eq(5)
463
570
  end
464
571
  end
465
572
 
@@ -468,82 +575,92 @@ describe Recurrence do
468
575
  @starts = Date.parse("2008-09-03")
469
576
  end
470
577
 
471
- it "should use numeric interval" do
578
+ it "uses numeric interval" do
472
579
  @recurrence = recurrence(:every => :month, :on => 21, :interval => 2, :starts => @starts)
473
- @recurrence.events[0].to_s.should == "2008-09-21"
474
- @recurrence.events[1].to_s.should == "2008-11-21"
475
- @recurrence.events[2].to_s.should == "2009-01-21"
476
- @recurrence.events[3].to_s.should == "2009-03-21"
580
+ expect(@recurrence.events[0].to_s).to eq("2008-09-21")
581
+ expect(@recurrence.events[1].to_s).to eq("2008-11-21")
582
+ expect(@recurrence.events[2].to_s).to eq("2009-01-21")
583
+ expect(@recurrence.events[3].to_s).to eq("2009-03-21")
477
584
  end
478
585
 
479
- it "should accept monthly symbol" do
586
+ it "accepts monthly symbol" do
480
587
  @recurrence = recurrence(
481
588
  :every => :month,
482
589
  :on => 10,
483
590
  :starts => @starts,
484
591
  :interval => :monthly
485
592
  )
486
- @recurrence.events[0].to_s.should == "2008-09-10"
487
- @recurrence.events[1].to_s.should == "2008-10-10"
593
+ expect(@recurrence.events[0].to_s).to eq("2008-09-10")
594
+ expect(@recurrence.events[1].to_s).to eq("2008-10-10")
488
595
  end
489
596
 
490
- it "should accept bimonthly symbol" do
597
+ it "accepts bimonthly symbol" do
491
598
  @recurrence = recurrence(
492
599
  :every => :month,
493
600
  :on => 10,
494
601
  :starts => @starts,
495
602
  :interval => :bimonthly
496
603
  )
497
- @recurrence.events[0].to_s.should == "2008-09-10"
498
- @recurrence.events[1].to_s.should == "2008-11-10"
604
+ expect(@recurrence.events[0].to_s).to eq("2008-09-10")
605
+ expect(@recurrence.events[1].to_s).to eq("2008-11-10")
499
606
  end
500
607
 
501
- it "should accept quarterly symbol" do
608
+ it "accepts quarterly symbol" do
502
609
  @recurrence = recurrence(
503
610
  :every => :month,
504
611
  :on => 10,
505
612
  :starts => @starts,
506
613
  :interval => :quarterly
507
614
  )
508
- @recurrence.events[0].to_s.should == "2008-09-10"
509
- @recurrence.events[1].to_s.should == "2008-12-10"
615
+ expect(@recurrence.events[0].to_s).to eq("2008-09-10")
616
+ expect(@recurrence.events[1].to_s).to eq("2008-12-10")
510
617
  end
511
618
 
512
- it "should accept semesterly symbol" do
619
+ it "accepts semesterly symbol" do
513
620
  @recurrence = recurrence(:every => :month, :on => 10, :starts => @starts, :interval => :semesterly)
514
- @recurrence.events[0].to_s.should == "2008-09-10"
515
- @recurrence.events[1].to_s.should == "2009-03-10"
621
+ expect(@recurrence.events[0].to_s).to eq("2008-09-10")
622
+ expect(@recurrence.events[1].to_s).to eq("2009-03-10")
516
623
  end
517
624
  end
518
625
  end
519
626
 
520
627
  describe "with yearly recurring" do
521
- it "should recur until limit date" do
628
+ it "recurs until limit date" do
522
629
  @recurrence = Recurrence.yearly(:on => [12,31])
523
- @recurrence.events[-1].should == Date.parse("2037-12-31")
630
+ expect(@recurrence.events[-1]).to eq(Date.parse("2037-12-31"))
524
631
  end
525
632
 
526
- it "should repeat until 7 years from now" do
633
+ it "repeats until 7 years from now" do
527
634
  date = 7.years.from_now
528
635
  @recurrence = recurrence(
529
636
  :every => :year,
530
637
  :on => [date.month, date.day],
531
638
  :until => date.to_date
532
639
  )
533
- @recurrence.events[-1].should == date.to_date
640
+ expect(@recurrence.events[-1]).to eq(date.to_date)
641
+ end
642
+
643
+ it "repeats through 7 years from now" do
644
+ date = 7.years.from_now
645
+ @recurrence = recurrence(
646
+ :every => :year,
647
+ :on => [date.month, date.day],
648
+ :through => date.to_date
649
+ )
650
+ expect(@recurrence.events[-1]).to eq(date.to_date)
534
651
  end
535
652
 
536
- it "should start 2 years ago" do
653
+ it "starts 2 years ago" do
537
654
  date = 2.years.ago
538
655
  @recurrence = recurrence(
539
656
  :every => :year,
540
657
  :on => [date.month, date.day],
541
658
  :starts => date.to_date
542
659
  )
543
- @recurrence.events[0].should == date.to_date
660
+ expect(@recurrence.events[0]).to eq(date.to_date)
544
661
  end
545
662
 
546
- it "should start at 2003-06-07 and repeat until 2018-06-07" do
663
+ it "starts at 2003-06-07 and repeat until 2018-06-07" do
547
664
  starts = Date.parse("2003-06-07")
548
665
  ends = Date.parse("2018-06-07")
549
666
 
@@ -553,11 +670,25 @@ describe Recurrence do
553
670
  :starts => starts,
554
671
  :until => ends
555
672
  )
556
- @recurrence.events[0].to_s.should == "2003-06-07"
557
- @recurrence.events[-1].to_s.should == "2018-06-07"
673
+ expect(@recurrence.events[0].to_s).to eq("2003-06-07")
674
+ expect(@recurrence.events[-1].to_s).to eq("2018-06-07")
558
675
  end
559
676
 
560
- it "should use interval" do
677
+ it "starts at 2003-06-07 and repeat through 2018-06-07" do
678
+ starts = Date.parse("2003-06-07")
679
+ ends = Date.parse("2018-06-07")
680
+
681
+ @recurrence = recurrence(
682
+ :every => :year,
683
+ :on => [starts.month, starts.day],
684
+ :starts => starts,
685
+ :through=> ends
686
+ )
687
+ expect(@recurrence.events[0].to_s).to eq("2003-06-07")
688
+ expect(@recurrence.events[-1].to_s).to eq("2018-06-07")
689
+ end
690
+
691
+ it "uses interval" do
561
692
  starts = Date.parse("2008-09-21")
562
693
 
563
694
  @recurrence = recurrence(
@@ -566,13 +697,13 @@ describe Recurrence do
566
697
  :interval => 2,
567
698
  :starts => starts
568
699
  )
569
- @recurrence.events[0].to_s.should == "2008-09-21"
570
- @recurrence.events[1].to_s.should == "2010-09-21"
571
- @recurrence.events[2].to_s.should == "2012-09-21"
572
- @recurrence.events[3].to_s.should == "2014-09-21"
700
+ expect(@recurrence.events[0].to_s).to eq("2008-09-21")
701
+ expect(@recurrence.events[1].to_s).to eq("2010-09-21")
702
+ expect(@recurrence.events[2].to_s).to eq("2012-09-21")
703
+ expect(@recurrence.events[3].to_s).to eq("2014-09-21")
573
704
  end
574
705
 
575
- it "should use repeat" do
706
+ it "uses repeat" do
576
707
  starts = Date.parse("2008-09-21")
577
708
 
578
709
  @recurrence = recurrence(
@@ -581,143 +712,184 @@ describe Recurrence do
581
712
  :starts => starts,
582
713
  :repeat => 5
583
714
  )
584
- @recurrence.events.size.should == 5
715
+ expect(@recurrence.events.size).to eq(5)
716
+ end
717
+
718
+ it "includes the through date when less than a perfect interval" do
719
+ starts = Date.parse("2003-06-07")
720
+ ends = Date.parse("2018-07-12")
721
+
722
+ @recurrence = recurrence(
723
+ :every => :year,
724
+ :on => [starts.month, starts.day],
725
+ :starts => starts,
726
+ :through => ends
727
+ )
728
+ expect(@recurrence.events[-1].to_s).to eq('2019-06-07')
585
729
  end
586
730
 
587
- it "should run until next available date when chosen settings are greater than start date" do
731
+ it "runs until next available date when chosen settings are greater than start date" do
588
732
  starts = Date.parse("2008-09-03")
589
733
 
590
734
  @recurrence = recurrence(:every => :year, :on => [10, 27], :starts => starts)
591
- @recurrence.events[0].to_s.should == "2008-10-27"
735
+ expect(@recurrence.events[0].to_s).to eq("2008-10-27")
592
736
  end
593
737
 
594
- it "should run until next available date when chosen settings are smaller than start date" do
738
+ it "runs until next available date when chosen settings are smaller than start date" do
595
739
  starts = Date.parse("2008-09-03")
596
740
  @recurrence = recurrence(:every => :year, :on => [7, 1], :starts => starts)
597
- @recurrence.events[0].to_s.should == "2009-07-01"
741
+ expect(@recurrence.events[0].to_s).to eq("2009-07-01")
598
742
 
599
743
  starts = Date.parse("2008-09-03")
600
744
  @recurrence = recurrence(:every => :year, :on => [9, 1], :starts => starts)
601
- @recurrence.events[0].to_s.should == "2009-09-01"
745
+ expect(@recurrence.events[0].to_s).to eq("2009-09-01")
746
+ end
747
+
748
+ it "uses except" do
749
+ @recurrence = Recurrence.yearly(:on => [12,31], :except => "#{Time.now.year+3}-12-31")
750
+
751
+ expect(@recurrence.events.include?("#{Time.now.year+2}-12-31".to_date)).to be_truthy
752
+ expect(@recurrence.events.include?("#{Time.now.year+3}-12-31".to_date)).to be_falsey
753
+ end
754
+ end
755
+
756
+ context "with except", :focus => true do
757
+ it "accepts only valid date strings or Dates" do
758
+ expect { recurrence(:except => :symbol) }.to raise_error(ArgumentError)
759
+ expect { recurrence(:except => "invalid") }.to raise_error(ArgumentError)
760
+ end
761
+
762
+ it "skips day specified in except" do
763
+ @recurrence = recurrence(:every => :day, :except => Date.tomorrow)
764
+ expect(@recurrence.include?(Date.today)).to be_truthy
765
+ expect(@recurrence.include?(Date.tomorrow)).to be_falsey
766
+ expect(@recurrence.include?(Date.tomorrow+1.day)).to be_truthy
767
+ end
768
+
769
+ it "skips multiple days specified in except" do
770
+ @recurrence = recurrence(:every => :day, :except => [Date.tomorrow, "2012-02-29"])
771
+ expect(@recurrence.include?(Date.today)).to be_truthy
772
+ expect(@recurrence.include?(Date.tomorrow)).to be_falsey
773
+ expect(@recurrence.include?("2012-02-29")).to be_falsey
602
774
  end
603
775
  end
604
776
 
605
777
  describe "#options" do
606
- it "should return passed-in options" do
778
+ it "returns passed-in options" do
607
779
  @recurrence = recurrence(:every => :day)
608
- @recurrence.options.should == {:every => :day}
780
+ expect(@recurrence.options).to eq({:every => :day})
609
781
  end
610
782
  end
611
783
 
612
784
  describe "#include?" do
613
- it "should include date (day)" do
785
+ it "includes date (day)" do
614
786
  @recurrence = recurrence(:every => :day, :starts => "2008-09-30")
615
- @recurrence.include?("2008-09-30").should be_true
616
- @recurrence.include?("2008-10-01").should be_true
787
+ expect(@recurrence.include?("2008-09-30")).to be_truthy
788
+ expect(@recurrence.include?("2008-10-01")).to be_truthy
617
789
  end
618
790
 
619
- it "should include date (week)" do
791
+ it "includes date (week)" do
620
792
  @recurrence = recurrence(:every => :week, :on => :thursday, :starts => "2008-09-30")
621
- @recurrence.include?("2008-09-30").should be_false
622
- @recurrence.include?("2008-10-02").should be_true
793
+ expect(@recurrence.include?("2008-09-30")).to be_falsey
794
+ expect(@recurrence.include?("2008-10-02")).to be_truthy
623
795
 
624
796
  @recurrence = recurrence(:every => :week, :on => :monday, :starts => "2008-09-29")
625
- @recurrence.include?("2008-09-29").should be_true
626
- @recurrence.include?("2008-10-06").should be_true
797
+ expect(@recurrence.include?("2008-09-29")).to be_truthy
798
+ expect(@recurrence.include?("2008-10-06")).to be_truthy
627
799
  end
628
800
 
629
- it "should include date (month)" do
801
+ it "includes date (month)" do
630
802
  @recurrence = recurrence(:every => :month, :on => 10, :starts => "2008-09-30")
631
- @recurrence.include?("2008-09-30").should be_false
632
- @recurrence.include?("2008-10-10").should be_true
803
+ expect(@recurrence.include?("2008-09-30")).to be_falsey
804
+ expect(@recurrence.include?("2008-10-10")).to be_truthy
633
805
 
634
806
  @recurrence = recurrence(:every => :month, :on => 10, :starts => "2008-09-10")
635
- @recurrence.include?("2008-09-10").should be_true
636
- @recurrence.include?("2008-10-10").should be_true
807
+ expect(@recurrence.include?("2008-09-10")).to be_truthy
808
+ expect(@recurrence.include?("2008-10-10")).to be_truthy
637
809
  end
638
810
 
639
- it "should include date (year)" do
811
+ it "includes date (year)" do
640
812
  @recurrence = recurrence(:every => :year, :on => [6,28], :starts => "2008-09-30")
641
- @recurrence.include?("2009-09-30").should be_false
642
- @recurrence.include?("2009-06-28").should be_true
813
+ expect(@recurrence.include?("2009-09-30")).to be_falsey
814
+ expect(@recurrence.include?("2009-06-28")).to be_truthy
643
815
 
644
816
  @recurrence = recurrence(:every => :year, :on => [6,28], :starts => "2008-06-28")
645
- @recurrence.include?("2009-06-28").should be_true
646
- @recurrence.include?("2009-06-28").should be_true
817
+ expect(@recurrence.include?("2009-06-28")).to be_truthy
818
+ expect(@recurrence.include?("2009-06-28")).to be_truthy
647
819
  end
648
820
 
649
- it "should not include date when is smaller than starting date (day)" do
821
+ it "doesn't include date when is smaller than starting date (day)" do
650
822
  @recurrence = recurrence(:every => :day, :starts => "2008-09-30")
651
- @recurrence.include?("2008-09-29").should be_false
823
+ expect(@recurrence.include?("2008-09-29")).to be_falsey
652
824
  end
653
825
 
654
- it "should not include date when is smaller than starting date (week)" do
826
+ it "doesn't include date when is smaller than starting date (week)" do
655
827
  @recurrence = recurrence(:every => :week, :on => :friday, :starts => "2008-09-30")
656
- @recurrence.include?("2008-09-24").should be_false
828
+ expect(@recurrence.include?("2008-09-24")).to be_falsey
657
829
  end
658
830
 
659
- it "should not include date when is smaller than starting date (month)" do
831
+ it "doesn't include date when is smaller than starting date (month)" do
660
832
  @recurrence = recurrence(:every => :month, :on => 10, :starts => "2008-09-30")
661
- @recurrence.include?("2008-09-10").should be_false
833
+ expect(@recurrence.include?("2008-09-10")).to be_falsey
662
834
  end
663
835
 
664
- it "should not include date when is smaller than starting date (year)" do
836
+ it "doesn't include date when is smaller than starting date (year)" do
665
837
  @recurrence = recurrence(:every => :year, :on => [6,28], :starts => "2008-09-30")
666
- @recurrence.include?("2008-06-28").should be_false
838
+ expect(@recurrence.include?("2008-06-28")).to be_falsey
667
839
  end
668
840
 
669
- it "should not include date when is greater than ending date (day)" do
841
+ it "doesn't include date when is greater than ending date (day)" do
670
842
  @recurrence = recurrence(:every => :day, :until => "2008-09-30")
671
- @recurrence.include?("2008-10-01").should be_false
843
+ expect(@recurrence.include?("2008-10-01")).to be_falsey
672
844
  end
673
845
 
674
- it "should not include date when is greater than ending date (week)" do
846
+ it "doesn't include date when is greater than ending date (week)" do
675
847
  @recurrence = recurrence(:every => :week, :on => :friday, :until => "2008-09-30")
676
- @recurrence.include?("2008-10-03").should be_false
848
+ expect(@recurrence.include?("2008-10-03")).to be_falsey
677
849
  end
678
850
 
679
- it "should not include date when is greater than ending date (year)" do
851
+ it "doesn't include date when is greater than ending date (year)" do
680
852
  @recurrence = recurrence(:every => :year, :on => [6,28], :until => "2008-09-30")
681
- @recurrence.include?("2009-06-28").should be_false
853
+ expect(@recurrence.include?("2009-06-28")).to be_falsey
682
854
  end
683
855
  end
684
856
 
685
857
  describe "#next" do
686
- it "should return next date" do
858
+ it "returns next date" do
687
859
  @recurrence = recurrence(:every => :day)
688
860
 
689
- @recurrence.next.to_s.should == Date.today.to_s
690
- @recurrence.next.to_s.should == Date.today.to_s
861
+ expect(@recurrence.next.to_s).to eq(Date.today.to_s)
862
+ expect(@recurrence.next.to_s).to eq(Date.today.to_s)
691
863
  end
692
864
 
693
- it "should return next! date" do
865
+ it "returns next! date" do
694
866
  @recurrence = recurrence(:every => :day)
695
867
 
696
- @recurrence.next!.to_s.should == Date.today.to_s
697
- @recurrence.next!.to_s.should == 1.day.from_now.to_date.to_s
698
- @recurrence.next!.to_s.should == 2.days.from_now.to_date.to_s
699
- @recurrence.next!.to_s.should == 3.days.from_now.to_date.to_s
868
+ expect(@recurrence.next!.to_s).to eq(Date.today.to_s)
869
+ expect(@recurrence.next!.to_s).to eq(1.day.from_now.to_date.to_s)
870
+ expect(@recurrence.next!.to_s).to eq(2.days.from_now.to_date.to_s)
871
+ expect(@recurrence.next!.to_s).to eq(3.days.from_now.to_date.to_s)
700
872
  end
701
873
  end
702
874
 
703
875
  describe "#reset!" do
704
- it "should reset to the first available date" do
876
+ it "resets to the first available date" do
705
877
  @recurrence = recurrence(:every => :year, :on => [2, 31], :starts => "2008-01-01")
706
- @recurrence.next!.to_s.should == "2008-02-29"
707
- @recurrence.next!.to_s.should == "2009-02-28"
878
+ expect(@recurrence.next!.to_s).to eq("2008-02-29")
879
+ expect(@recurrence.next!.to_s).to eq("2009-02-28")
708
880
  @recurrence.reset!
709
- @recurrence.next.to_s.should == "2008-02-29"
881
+ expect(@recurrence.next.to_s).to eq("2008-02-29")
710
882
  end
711
883
  end
712
884
 
713
885
  describe "event initialization" do
714
- it "should return the first available date" do
886
+ it "returns the first available date" do
715
887
  @recurrence = recurrence(:every => :year, :on => [2, 31], :starts => "2008-01-01")
716
- @recurrence.next!.to_s.should == "2008-02-29"
717
- @recurrence.next!.to_s.should == "2009-02-28"
718
- @recurrence.next!.to_s.should == "2010-02-28"
719
- @recurrence.next!.to_s.should == "2011-02-28"
720
- @recurrence.next!.to_s.should == "2012-02-29"
888
+ expect(@recurrence.next!.to_s).to eq("2008-02-29")
889
+ expect(@recurrence.next!.to_s).to eq("2009-02-28")
890
+ expect(@recurrence.next!.to_s).to eq("2010-02-28")
891
+ expect(@recurrence.next!.to_s).to eq("2011-02-28")
892
+ expect(@recurrence.next!.to_s).to eq("2012-02-29")
721
893
  end
722
894
  end
723
895
 
@@ -726,44 +898,44 @@ describe Recurrence do
726
898
  @recurrence = recurrence(:every => :day, :starts => "2009-01-06", :until => "2009-01-15")
727
899
  end
728
900
 
729
- it "should return starting and ending recurrences" do
730
- @recurrence.events[0].to_s.should == "2009-01-06"
731
- @recurrence.events[-1].to_s.should == "2009-01-15"
901
+ it "returns starting and ending recurrences" do
902
+ expect(@recurrence.events[0].to_s).to eq("2009-01-06")
903
+ expect(@recurrence.events[-1].to_s).to eq("2009-01-15")
732
904
  end
733
905
 
734
- it "should reset cache" do
735
- @recurrence.event.should_receive(:reset!).exactly(3).times
906
+ it "resets cache" do
907
+ expect(@recurrence.event).to receive(:reset!).exactly(3).times
736
908
  @recurrence.events(:starts => "2009-01-11")
737
909
  @recurrence.events(:until => "2009-01-14")
738
910
  @recurrence.events(:starts => "2009-01-11", :until => "2009-01-14")
739
911
  end
740
912
 
741
- it "should return only events greater than starting date" do
913
+ it "returns only events greater than starting date" do
742
914
  @events = @recurrence.events(:starts => "2009-01-10")
743
- @events[0].to_s.should == "2009-01-10"
915
+ expect(@events[0].to_s).to eq("2009-01-10")
744
916
  end
745
917
 
746
- it "should return only events smaller than until date" do
918
+ it "returns only events smaller than until date" do
747
919
  @events = @recurrence.events(:until => "2009-01-10")
748
- @events[0].to_s.should == "2009-01-06"
749
- @events[-1].to_s.should == "2009-01-10"
920
+ expect(@events[0].to_s).to eq("2009-01-06")
921
+ expect(@events[-1].to_s).to eq("2009-01-10")
750
922
  end
751
923
 
752
- it "should return only events between starting and until date" do
924
+ it "returns only events between starting and until date" do
753
925
  @events = @recurrence.events(:starts => "2009-01-12", :until => "2009-01-14")
754
- @events[0].to_s.should == "2009-01-12"
755
- @events[-1].to_s.should == "2009-01-14"
926
+ expect(@events[0].to_s).to eq("2009-01-12")
927
+ expect(@events[-1].to_s).to eq("2009-01-14")
756
928
  end
757
929
 
758
- it "should not iterate all dates when using until" do
930
+ it "doesn't iterate all dates when using until" do
759
931
  @events = @recurrence.events(:starts => "2009-01-06", :until => "2009-01-08")
760
- @recurrence.instance_variable_get("@events").size.should == 3
761
- @events.size.should == 3
762
- @events[-1].to_s.should == "2009-01-08"
932
+ expect(@recurrence.instance_variable_get("@events").size).to eq(3)
933
+ expect(@events.size).to eq(3)
934
+ expect(@events[-1].to_s).to eq("2009-01-08")
763
935
  end
764
936
 
765
937
  context "bug fixes" do
766
- specify "using name as symbol [http://github.com/fnando/recurrence/issues#issue/3]" do
938
+ it "uses name as symbol [issue#3]" do
767
939
  expect {
768
940
  @recurrence = recurrence(:every => :year, :on => [:jan, 31])
769
941
  }.to_not raise_error
@@ -777,10 +949,10 @@ describe Recurrence do
777
949
 
778
950
  it "offsets every other month day" do
779
951
  r = recurrence(:every => :month, :on => 1, :starts => "2011-01-01", :handler => shift_handler)
780
- r.events[0].should == Date.new(2011, 1, 1)
781
- r.events[1].should == Date.new(2011, 2, 2)
782
- r.events[2].should == Date.new(2011, 3, 1)
783
- r.events[3].should == Date.new(2011, 4, 2)
952
+ expect(r.events[0]).to eq(Date.new(2011, 1, 1))
953
+ expect(r.events[1]).to eq(Date.new(2011, 2, 2))
954
+ expect(r.events[2]).to eq(Date.new(2011, 3, 1))
955
+ expect(r.events[3]).to eq(Date.new(2011, 4, 2))
784
956
  end
785
957
 
786
958
  it "raises an exception from the handler" do
@@ -791,37 +963,37 @@ describe Recurrence do
791
963
  context "with shifting enabled" do
792
964
  it "shifts yearly recurrences around February 29" do
793
965
  r = recurrence(:every => :year, :starts => "2012-02-29", :on => [2,29], :shift => true)
794
- r.events[0].should == Date.new(2012, 2, 29)
795
- r.events[1].should == Date.new(2013, 2, 28)
796
- r.events[2].should == Date.new(2014, 2, 28)
797
- r.events[3].should == Date.new(2015, 2, 28)
798
- r.events[4].should == Date.new(2016, 2, 28)
966
+ expect(r.events[0]).to eq(Date.new(2012, 2, 29))
967
+ expect(r.events[1]).to eq(Date.new(2013, 2, 28))
968
+ expect(r.events[2]).to eq(Date.new(2014, 2, 28))
969
+ expect(r.events[3]).to eq(Date.new(2015, 2, 28))
970
+ expect(r.events[4]).to eq(Date.new(2016, 2, 28))
799
971
  end
800
972
 
801
973
  it "shifts monthly recurrences around the 31st" do
802
974
  r = recurrence(:every => :month, :starts => "2011-01-31", :on => 31, :shift => true)
803
- r.events[0].should == Date.new(2011, 1, 31)
804
- r.events[1].should == Date.new(2011, 2, 28)
805
- r.events[2].should == Date.new(2011, 3, 28)
975
+ expect(r.events[0]).to eq(Date.new(2011, 1, 31))
976
+ expect(r.events[1]).to eq(Date.new(2011, 2, 28))
977
+ expect(r.events[2]).to eq(Date.new(2011, 3, 28))
806
978
  end
807
979
 
808
980
  it "shifts monthly recurrences around the 30th" do
809
981
  r = recurrence(:every => :month, :starts => "2011-01-30", :on => 30, :shift => true)
810
- r.events[0].should == Date.new(2011, 1, 30)
811
- r.events[1].should == Date.new(2011, 2, 28)
812
- r.events[2].should == Date.new(2011, 3, 28)
982
+ expect(r.events[0]).to eq(Date.new(2011, 1, 30))
983
+ expect(r.events[1]).to eq(Date.new(2011, 2, 28))
984
+ expect(r.events[2]).to eq(Date.new(2011, 3, 28))
813
985
  end
814
986
 
815
987
  it "shifts monthly recurrences around the 29th" do
816
988
  r = recurrence(:every => :month, :starts => "2011-01-29", :on => 29, :shift => true)
817
- r.events[0].should == Date.new(2011, 1, 29)
818
- r.events[1].should == Date.new(2011, 2, 28)
819
- r.events[2].should == Date.new(2011, 3, 28)
989
+ expect(r.events[0]).to eq(Date.new(2011, 1, 29))
990
+ expect(r.events[1]).to eq(Date.new(2011, 2, 28))
991
+ expect(r.events[2]).to eq(Date.new(2011, 3, 28))
820
992
 
821
993
  r = recurrence(:every => :month, :starts => "2012-01-29", :on => 29, :shift => true)
822
- r.events[0].should == Date.new(2012, 1, 29)
823
- r.events[1].should == Date.new(2012, 2, 29)
824
- r.events[2].should == Date.new(2012, 3, 29)
994
+ expect(r.events[0]).to eq(Date.new(2012, 1, 29))
995
+ expect(r.events[1]).to eq(Date.new(2012, 2, 29))
996
+ expect(r.events[2]).to eq(Date.new(2012, 3, 29))
825
997
  end
826
998
 
827
999
  it "correctly resets to original day for monthly" do