Created
July 29, 2010 23:45
-
-
Save kristjan/499529 to your computer and use it in GitHub Desktop.
Tests that a Birthday can handle Feb 29 properly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "February 29" do | |
freeze_time | |
before(:each) do | |
@birthday = new_birthday(:month => 2, :day => 29, :year => 1984) | |
end | |
it "knows it's a jerk" do | |
@birthday.should be_feb_29 | |
end | |
it "knows it's not a jerk" do | |
new_birthday(:month => 1).should_not be_feb_29 | |
end | |
describe "in a leap year" do | |
before(:all) do | |
set_time(Date.new(2008, 1, 1)) | |
end | |
it "converts to Date Feb 29 when it has a year" do | |
@birthday.to_date.should == Date.new(1984, 2, 29) | |
end | |
it "converts to Date Feb 29 when it does not have a year" do | |
@birthday.year = nil | |
@birthday.to_date(:allow_empty_year => true). | |
should == Date.new(2008, 2, 29) | |
end | |
it "gets this_year right" do | |
@birthday.this_year.should == Date.new(2008, 2, 29) | |
end | |
end | |
describe "in a non-leap year" do | |
before(:all) do | |
set_time(Date.new(2010, 1, 1).to_time) | |
end | |
it "converts to Date Feb 29 when it has a year" do | |
@birthday.to_date.should == Date.new(1984, 2, 29) | |
end | |
it "converts to Date March 1 when it does not have a year" do | |
@birthday.year = nil | |
@birthday.to_date(:allow_empty_year => true). | |
should == Date.new(2010, 3, 1) | |
end | |
it "treats this_year as March 1" do | |
@birthday.this_year.should == Date.new(2010, 3, 1) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment