spec/date_spec.rb in partial-date-1.1.4 vs spec/date_spec.rb in partial-date-1.1.5
- old
+ new
@@ -42,11 +42,11 @@
new_date.day.should == 0
new_date.value.should == 20120000
end
it "should not allow an invalid date value to be set in a date instance" do
- expect {new_date = PartialDate::Date.new {|d| d.value = 100000000}}.to raise_error(PartialDate::PartialDateError, "Date value must be an integer betwen 10000 and 99991231")
+ expect {new_date = PartialDate::Date.new {|d| d.value = 10485761232 }}.to raise_error(PartialDate::PartialDateError, "Date value must be an integer betwen -10485761231 and 10485761231")
end
it "should return a string representation of date in the correct format" do
new_date = PartialDate::Date.new {|d| d.year = 2012; d.month = 12; d.day = 31}
new_date.to_s.should match(/\A\d{4}-\d{2}-\d{2}\z/)
@@ -60,59 +60,67 @@
it "should return a string representation of a partial date in the correct format" do
new_date = PartialDate::Date.new {|d| d.year = 2012}
new_date.to_s.should match(/\A\d{4}\z/)
end
- describe "Year" do
- it "should raise an error if year is set to nil" do
- expect {date.year = nil}.to raise_error(PartialDate::PartialDateError)
+ describe "Sign" do
+ it "should be set to 1" do
+ register = 0
+ register = PartialDate::Date.set_sign(register, 1)
+ PartialDate::Date.get_sign(register).should == 1
end
-
- it "should raise an error if year is set to an invalid string" do
- expect {date.year = "ABCD" }.to raise_error(PartialDate::PartialDateError, "Year must be a valid four digit string or integer between 1 and 9999")
+ it "should be 1 if year is a negative value" do
+ register = 0
+ register = PartialDate::Date.set_year(register, -9999)
+ PartialDate::Date.get_sign(register).should == 1
end
- it "should raise an error if year is set to a five digit string" do
- expect {date.year = "10000" }.to raise_error(PartialDate::PartialDateError, "Year must be a valid four digit string or integer between 1 and 9999")
+ it "should be 0 if year is a positive value" do
+ register = 0
+ register = PartialDate::Date.set_year(register, 9999)
+ PartialDate::Date.get_sign(register).should == 0
end
+ end
- it "should raise an error if year is set to a value greater than 9999" do
- expect {date.year = 10000 }.to raise_error(PartialDate::PartialDateError, "Year must be an integer between 1 and 9999")
+
+ describe "Year" do
+ it "should raise an error if year is set to nil" do
+ expect {date.year = nil}.to raise_error(PartialDate::YearError)
end
- it "should raise an error if year is set to zero" do
- expect {date.year = 0 }.to raise_error(PartialDate::PartialDateError, "Year must be an integer between 1 and 9999")
+ it "should raise an error if year is set to an invalid string" do
+ expect {date.year = "ABCD" }.to raise_error(PartialDate::YearError, "Year must be a valid string or integer from -1048576 to 1048576")
end
- it "should raise an error if year is set to a value less than zero" do
- expect {date.year = -1 }.to raise_error(PartialDate::PartialDateError, "Year must be an integer between 1 and 9999")
+ it "should raise an error if year is set to a value greater than 1048576" do
+ expect {date.year = 1048577 }.to raise_error(PartialDate::YearError, "Year must be an integer integer from -1048576 to 1048576")
end
- it "should return a year when a year is set" do
+ it "should return a postive year when a positive year is set" do
date.year = 2050
date.year.should == 2050
end
+
+ it "should return a negative year when a negative year is set" do
+ date.year = -9999
+ date.year.should == -9999
+ end
end
describe "Month" do
before(:each) { date.year = 2000 }
- it "should raise an error if a month is set before a year" do
- no_year = PartialDate::Date.new
- expect {no_year.month = 10}.to raise_error(PartialDate::PartialDateError, "A year must be set before a month")
- end
-
it "should raise an error if month is set to an invalid string" do
- expect {date.month = "AB"}.to raise_error(PartialDate::PartialDateError, "Month must be a valid one or two digit string or integer between 0 and 12")
+ expect {date.month = "AB"}.to raise_error(PartialDate::MonthError, "Month must be a valid one or two digit string or integer between 0 and 12")
end
it "should raise an error if month is set to a value greater than 12" do
- expect {date.month = 13}.to raise_error(PartialDate::PartialDateError, "Month must an be integer between 0 and 12")
+ expect {date.month = 13}.to raise_error(PartialDate::MonthError, "Month must an be integer between 0 and 12")
end
it "should raise an error if month is set to a value less than zero" do
- expect {date.month = -1}.to raise_error(PartialDate::PartialDateError, "Month must an be integer between 0 and 12")
+ expect {date.month = -1}.to raise_error(PartialDate::MonthError, "Month must an be integer between 0 and 12")
end
it "should allow the month to be set to zero" do
date.month = 0
date.month.should == 0
@@ -132,26 +140,26 @@
describe "Day" do
before(:each) { date.year = 2000; date.month = 6 }
it "should raise an error if a day is set before a year and month" do
no_month = PartialDate::Date.new
- expect {no_month.day = 10}.to raise_error(PartialDate::PartialDateError, "A month must be set before a day")
+ expect {no_month.day = 10}.to raise_error(PartialDate::DayError, "A month must be set before a day")
end
it "should raise an error if day is set to an invalid string" do
- expect {date.day = "AB"}.to raise_error(PartialDate::PartialDateError, "Day must be a valid one or two digit string or integer between 0 and 31")
+ expect {date.day = "AB"}.to raise_error(PartialDate::DayError, "Day must be a valid one or two digit string or integer between 0 and 31")
end
it "should raise an error if day is set to a value less than zero" do
- expect {date.day = -1}.to raise_error(PartialDate::PartialDateError, "Day must be an integer between 0 and 31")
+ expect {date.day = -1}.to raise_error(PartialDate::DayError, "Day must be an integer between 0 and 31")
end
it "should raise an error if day is set to a value greater than 31" do
- expect {date.day = 32}.to raise_error(PartialDate::PartialDateError, "Day must be an integer between 0 and 31")
+ expect {date.day = 32}.to raise_error(PartialDate::DayError, "Day must be an integer between 0 and 31")
end
it "should raise an error if the day is an invalid day for the given month" do
- expect {date.day = 31}.to raise_error(PartialDate::PartialDateError, "Day must be a valid day for the given month")
+ expect {date.day = 31}.to raise_error(PartialDate::DayError, "Day must be a valid day for the given month")
end
it "should return zero when set to nil" do
date.day = nil
date.day.should == 0