Skip to content

Instantly share code, notes, and snippets.

@6ewis
Created December 11, 2013 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 6ewis/7919715 to your computer and use it in GitHub Desktop.
Save 6ewis/7919715 to your computer and use it in GitHub Desktop.
random task =)
#task_helper.rb
require 'spec_helper'
describe Task do
describe '#reccurent' do
it 'raises an Argument error' do
expect { Task.new.reccurent }.to raise_error {|error| error.should be_a(ArgumentError)}
end
it 'raises an Argument error if the nbr of reccurences is greater than 12' do
expect { Task.new.reccurent Date.today, rand(12..100)}.to raise_error {|error| error.should be_a(ArgumentError)}
end
it 'does not raise' do
expect { Task.new.reccurent Date.today, rand(1..12) }.to_not raise_error
end
it "produce an array of recurring dates" do
expect(Task.new.reccurent Date.parse("December 1 2013"), 5).to eq [" 1 of January, 2014", " 1 of February, 2014", " 1 of March, 2014", " 1 of April, 2014", " 1 of May, 2014"]
end
it "ensures that if the date of the next recurring dates does not exist, the last day of the month should be used" do
expect(Task.new.reccurent Date.parse("December 31 2013"), 8).to eq ["31 of January, 2014", "28 of February, 2014", "31 of March, 2014", "30 of April, 2014", "31 of May, 2014", "30 of June, 2014", "31 of July, 2014", "31 of August, 2014"]
end
end
end
#spec_helper.rb
require_relative '../task'
#task.rb
class Task
def reccurent(starting_date,nbr_of_recurrences)
raise ArgumentError, "The number of recurrences should have value between 1 and 12" if nbr_of_recurrences > 12
response = []
nbr_of_recurrences.times do |occurence|
response << starting_date.>>(occurence+1).strftime("%e of %B, %Y")
end
response
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment