Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated Date specs

  • Loading branch information...
commit 3c2c7c35a54e9cbdbb4e97b7e4470f59f83b47d8 1 parent 00df2e2
@hosiawak hosiawak authored brixen committed
Showing with 484 additions and 395 deletions.
  1. +0 −63 library/date/civil_spec.rb
  2. +0 −64 library/date/commercial_spec.rb
  3. +9 −9 library/date/constants_spec.rb
  4. +5 −2 library/date/exist1_spec.rb
  5. +5 −2 library/date/exist2_spec.rb
  6. +5 −2 library/date/exist3_spec.rb
  7. +5 −2 library/date/exist_spec.rb
  8. +5 −2 library/date/existw_spec.rb
  9. +12 −2 library/date/gregorian_leap_spec.rb
  10. +11 −24 library/date/gregorian_spec.rb
  11. +7 −2 library/date/jd_spec.rb
  12. +10 −1 library/date/julian_leap_spec.rb
  13. +10 −65 library/date/julian_spec.rb
  14. +4 −4 library/date/minus_spec.rb
  15. +5 −2 library/date/new0_spec.rb
  16. +5 −2 library/date/new1_spec.rb
  17. +5 −2 library/date/new2_spec.rb
  18. +5 −2 library/date/new3_spec.rb
  19. +6 −9 library/date/new_spec.rb
  20. +4 −2 library/date/newsg_spec.rb
  21. +4 −2 library/date/neww_spec.rb
  22. +7 −5 library/date/ns_spec.rb
  23. +3 −108 library/date/ordinal_spec.rb
  24. +7 −5 library/date/os_spec.rb
  25. +15 −1 library/date/plus_spec.rb
  26. +4 −2 library/date/sg_spec.rb
  27. +2 −2 library/date/shared/civil.rb
  28. +14 −0 library/date/shared/jd.rb
  29. +14 −0 library/date/shared/new_bang.rb
  30. +42 −0 library/date/shared/ordinal.rb
  31. +69 −0 library/date/shared/valid_civil.rb
  32. +66 −0 library/date/shared/valid_commercial.rb
  33. +36 −0 library/date/shared/valid_jd.rb
  34. +60 −0 library/date/shared/valid_ordinal.rb
  35. +6 −2 library/date/valid_civil_spec.rb
  36. +6 −2 library/date/valid_commercial_spec.rb
  37. +1 −1  library/date/valid_date_spec.rb
  38. +5 −1 library/date/valid_jd_spec.rb
  39. +5 −1 library/date/valid_ordinal_spec.rb
View
63 library/date/civil_spec.rb
@@ -6,69 +6,6 @@
it_behaves_like(:date_civil, :civil)
end
-# reference:
-# October 1582 (the Gregorian calendar, Civil Date)
-# S M Tu W Th F S
-# 1 2 3 4 15 16
-# 17 18 19 20 21 22 23
-# 24 25 26 27 28 29 30
-# 31
-
-describe "Date#valid_civil?" do
-
- ruby_version_is "" ... "1.9" do
- it "should be able to determine if a date is valid" do
- Date.valid_civil?(1582, 10, 14).should == nil
- Date.valid_civil?(1582, 10, 15).should == Date.civil(1582, 10, 15).jd
- Date.valid_civil?(1582, 10, 14, Date::ENGLAND).should_not == nil
- Date.valid_civil?(1582, 10, 14, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND).jd
- end
-
- it "should be able to handle negative months and days" do
- # October 1582 (the Gregorian calendar, Civil Date in 1.8)
- # S M Tu W Th F S
- # -31 -30 -29 -28 -17 -16
- # -15 -14 -13 -12 -11 -10 -9
- # -8 -7 -6 -5 -4 -3 -2
- # -1
- Date.valid_civil?(1582, -3, -31).should == Date.civil(1582, 10, 1).jd
- Date.valid_civil?(1582, -3, -28).should == Date.civil(1582, 10, 4).jd
- Date.valid_civil?(1582, -3, -27).should == nil
- Date.valid_civil?(1582, -3, -22).should == nil
- Date.valid_civil?(1582, -3, -21).should == nil
- Date.valid_civil?(1582, -3, -18).should == nil
- Date.valid_civil?(1582, -3, -17).should == Date.civil(1582, 10, 15).jd
-
- Date.valid_civil?(2007, -11, -10).should == Date.civil(2007, 2, 19).jd
- Date.valid_civil?(2008, -11, -10).should == Date.civil(2008, 2, 20).jd
- end
- end
-
- ruby_version_is "1.9" do
- it "should be able to determine if a date is valid" do
- Date.valid_civil?(1582, 10, 14).should == false
- Date.valid_civil?(1582, 10, 15).should == true
- Date.valid_civil?(1582, 10, 14, Date::ENGLAND).should == true
- end
-
- it "should be able to handle negative months and days" do
- # October 1582 (the Gregorian calendar, Civil Date in 1.9)
- # S M Tu W Th F S
- # -21 -20 -19 -18 -17 -16
- # -15 -14 -13 -12 -11 -10 -9
- # -8 -7 -6 -5 -4 -3 -2
- # -1
- Date.valid_civil?(1582, -3, -22).should == false
- Date.valid_civil?(1582, -3, -21).should == true
- Date.valid_civil?(1582, -3, -18).should == true
- Date.valid_civil?(1582, -3, -17).should == true
-
- Date.valid_civil?(2007, -11, -10).should == true
- Date.valid_civil?(2008, -11, -10).should == true
- end
- end
-
-end
describe "Date.civil" do
it "needs to be reviewed for spec completeness"
View
64 library/date/commercial_spec.rb
@@ -16,67 +16,3 @@
# 24 25 26 27 28 29 30
# 31
-describe "Date#valid_commercial?" do
-
- ruby_version_is "" ... "1.9" do
- it "should be able to determine if the date is a valid commercial date" do
- # October 1582 (the Gregorian calendar, Commercial Date in 1.8)
- # M Tu W Th F Sa Su
- # 41: - - - - 5 6 7
- # 42: 1 2 3 4 5 6 7
- # 43: 1 2 3 4 5 6 7
- Date.valid_commercial?(1582, 41, 4).should == nil
- Date.valid_commercial?(1582, 41, 5).should == Date.civil(1582, 10, 15).jd
- # valid_commercial? can't handle dates before the Gregorian calendar
- Date.valid_commercial?(1582, 41, 4, Date::ENGLAND).should == nil
- Date.valid_commercial?(1752, 37, 4, Date::ENGLAND).should == Date.civil(1752, 9, 14, Date::ENGLAND).jd
- end
-
- it "should be able to handle negative week and day numbers" do
- # October 1582 (the Gregorian calendar, Commercial Date in 1.8)
- # M Tu W Th F Sa Su
- # -12: - - - - -3 -2 -1
- # -11: -7 -6 -5 -4 -3 -2 -1
- # -10: -7 -6 -5 -4 -3 -2 -1
- Date.valid_commercial?(1582, -12, -4).should == nil
- Date.valid_commercial?(1582, -12, -3).should == Date.civil(1582, 10, 15).jd
-
- Date.valid_commercial?(2007, -44, -2).should == Date.civil(2007, 3, 3).jd
- Date.valid_commercial?(2008, -44, -2).should == Date.civil(2008, 3, 1).jd
- end
- end
-
- ruby_version_is "1.9" do
- it "should be able to determine if the date is a valid commercial date" do
- # October 1582 (the Gregorian calendar, Commercial Date in 1.9)
- # M Tu W Th F Sa Su
- # 39: 1 2 3 4 5 6 7
- # 40: 1 2 3 4 5 6 7
- # 41: 1 2 3 4 5 6 7
- Date.valid_commercial?(1582, 39, 4).should == true
- Date.valid_commercial?(1582, 39, 5).should == true
- Date.valid_commercial?(1582, 41, 4).should == true
- Date.valid_commercial?(1582, 41, 5).should == true
- Date.valid_commercial?(1582, 41, 4, Date::ENGLAND).should == true
- Date.valid_commercial?(1752, 37, 4, Date::ENGLAND).should == true
- end
-
- it "should be able to handle negative week and day numbers" do
- # October 1582 (the Gregorian calendar, Commercial Date in 1.9)
- # M Tu W Th F Sa Su
- # -12: -7 -6 -5 -4 -3 -2 -1
- # -11: -7 -6 -5 -4 -3 -2 -1
- # -10: -7 -6 -5 -4 -3 -2 -1
- Date.valid_commercial?(1582, -12, -4).should == true
- Date.valid_commercial?(1582, -12, -3).should == true
-
- Date.valid_commercial?(2007, -44, -2).should == true
- Date.valid_commercial?(2008, -44, -2).should == true
- end
- end
-
-end
-
-describe "Date.commercial" do
- it "needs to be reviewed for spec completeness"
-end
View
18 library/date/constants_spec.rb
@@ -3,14 +3,6 @@
describe "Date constants" do
- it "defines ITALY" do
- Date::ITALY.should == 2299161 # 1582-10-15
- end
-
- it "defines ENGLAND" do
- Date::ENGLAND.should == 2361222 # 1752-09-14
- end
-
# Fixes in 1.8.7
ruby_bug "#", "1.8.6" do
it "defines JULIAN" do
@@ -25,6 +17,14 @@
end
end
+ it "defines ITALY" do
+ Date::ITALY.should == 2299161 # 1582-10-15
+ end
+
+ it "defines ENGLAND" do
+ Date::ENGLAND.should == 2361222 # 1752-09-14
+ end
+
it "defines MONTHNAMES" do
Date::MONTHNAMES.should == [nil] + %w(January February March April May June July
August September October November December)
@@ -53,7 +53,7 @@
end
end
- ruby_version_is '1.8.7' do
+ ruby_version_is "1.8.7" ... "1.9.3"do
it "defines HALF_DAYS_IN_DAY" do
Date::HALF_DAYS_IN_DAY.should == Rational(1, 2)
View
7 library/date/exist1_spec.rb
@@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/valid_jd', __FILE__)
require 'date'
-describe "Date.exist1?" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date.exist1?" do
+ it_behaves_like :date_valid_jd?, :exist1?
+ end
end
View
7 library/date/exist2_spec.rb
@@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/valid_ordinal', __FILE__)
require 'date'
-describe "Date.exist2?" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date.exist2?" do
+ it_behaves_like :date_valid_ordinal?, :exist2?
+ end
end
View
7 library/date/exist3_spec.rb
@@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/valid_civil', __FILE__)
require 'date'
-describe "Date.exist3?" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date.exist3?" do
+ it_behaves_like :date_valid_civil?, :exist3?
+ end
end
View
7 library/date/exist_spec.rb
@@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/valid_civil', __FILE__)
require 'date'
-describe "Date.exist?" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date.exist?" do
+ it_behaves_like :date_valid_civil?, :exist?
+ end
end
View
7 library/date/existw_spec.rb
@@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/valid_commercial', __FILE__)
require 'date'
-describe "Date.existw?" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date.existw?" do
+ it_behaves_like :date_valid_commercial?, :existw?
+ end
end
View
14 library/date/gregorian_leap_spec.rb
@@ -1,6 +1,16 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
-describe "Date.gregorian_leap?" do
- it "needs to be reviewed for spec completeness"
+describe "Date#gregorian_leap?" do
+ it "returns true if a year is a leap year in the Gregorian calendar" do
+ Date.gregorian_leap?(2000).should be_true
+ Date.gregorian_leap?(2004).should be_true
+ end
+
+ it "returns false if a year is not a leap year in the Gregorian calendar" do
+ Date.gregorian_leap?(1900).should be_false
+ Date.gregorian_leap?(1999).should be_false
+ Date.gregorian_leap?(2002).should be_false
+ end
end
+
View
35 library/date/gregorian_spec.rb
@@ -4,55 +4,42 @@
describe "Date#gregorian?" do
it "marks a day before the calendar reform as Julian" do
- Date.civil(1007, 2, 27).gregorian?.should == false
- Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).gregorian?.should == false
+ Date.civil(1007, 2, 27).gregorian?.should be_false
+ Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).gregorian?.should be_false
end
it "marks a day after the calendar reform as Julian" do
Date.civil(2007, 2, 27).gregorian?.should == true
- Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).gregorian?.should == true
+ Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).gregorian?.should be_true
end
end
-describe "Date#gregorian_leap?" do
- it "returns true if a year is a leap year in the Gregorian calendar" do
- Date.gregorian_leap?(2000).should == true
- Date.gregorian_leap?(2004).should == true
- end
-
- it "returns false if a year is not a leap year in the Gregorian calendar" do
- Date.gregorian_leap?(1900).should == false
- Date.gregorian_leap?(1999).should == false
- Date.gregorian_leap?(2002).should == false
- end
-end
-
-describe "Date.gregorian?" do
- ruby_version_is "" ... "1.9" do
+ruby_version_is "" ... "1.9" do
+ describe "Date.gregorian?" do
it "marks the date as Gregorian if using the Gregorian calendar" do
- Date.gregorian?(Date.civil(1007, 2, 27).jd, Date::GREGORIAN).should == true
+ Date.gregorian?(Date.civil(1007, 2, 27).jd, Date::GREGORIAN).should be_true
end
it "marks the date as not Gregorian if using the Julian calendar" do
- Date.gregorian?(Date.civil(1007, 2, 27).jd, Date::JULIAN).should == false
+ Date.gregorian?(Date.civil(1007, 2, 27).jd, Date::JULIAN).should be_false
end
it "marks the date before the English Day of Calendar Reform as not Gregorian" do
- Date.gregorian?(Date.civil(1752, 9, 13).jd, Date::ENGLAND).should == false
+ Date.gregorian?(Date.civil(1752, 9, 13).jd, Date::ENGLAND).should be_false
end
it "marks the date after the English Day of Calendar Reform as Gregorian" do
- Date.gregorian?(Date.civil(1752, 9, 14).jd, Date::ENGLAND).should == true
+ Date.gregorian?(Date.civil(1752, 9, 14).jd, Date::ENGLAND).should be_true
end
it "marks the date before the Italian Day of Calendar Reform as not Gregorian" do
- Date.gregorian?(Date.civil(1582, 10, 4).jd, Date::ITALY).should == false
+ Date.gregorian?(Date.civil(1582, 10, 4).jd, Date::ITALY).should be_false
end
it "marks the date after the Italian Day of Calendar Reform as Gregorian" do
- Date.gregorian?(Date.civil(1582, 10, 15).jd, Date::ITALY).should == true
+ Date.gregorian?(Date.civil(1582, 10, 15).jd, Date::ITALY).should be_true
end
end
View
9 library/date/jd_spec.rb
@@ -1,10 +1,15 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/jd', __FILE__)
require 'date'
describe "Date#jd" do
- it "needs to be reviewed for spec completeness"
+
+ it "determines the Julian day for a Date object" do
+ Date.civil(2008, 1, 16).jd.should == 2454482
+ end
+
end
describe "Date.jd" do
- it "needs to be reviewed for spec completeness"
+ it_behaves_like :date_jd, :jd
end
View
11 library/date/julian_leap_spec.rb
@@ -2,5 +2,14 @@
require 'date'
describe "Date.julian_leap?" do
- it "needs to be reviewed for spec completeness"
+ it "determines whether a year is a leap year in the Julian calendar" do
+ Date.julian_leap?(1900).should be_true
+ Date.julian_leap?(2000).should be_true
+ Date.julian_leap?(2004).should be_true
+ end
+
+ it "determines whether a year is not a leap year in the Julian calendar" do
+ Date.julian_leap?(1999).should be_false
+ Date.julian_leap?(2002).should be_false
+ end
end
View
75 library/date/julian_spec.rb
@@ -1,103 +1,48 @@
require 'date'
require File.expand_path('../../../spec_helper', __FILE__)
-describe "Date#jd" do
-
- it "constructs a Date object based on the Julian day" do
- Date.jd(2454482).should == Date.civil(2008, 1, 16)
- end
-
- it "determines the Julian day for a Date object" do
- Date.civil(2008, 1, 16).jd.should == 2454482
- end
-
-end
-
describe "Date#julian?" do
it "marks a day before the calendar reform as Julian" do
Date.civil(1007, 2, 27).julian?.should == true
- Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).julian?.should == true
+ Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).julian?.should be_true
end
it "marks a day after the calendar reform as Julian" do
Date.civil(2007, 2, 27).julian?.should == false
- Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).julian?.should == false
+ Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).julian?.should be_false
end
end
-describe "Date#julian_leap?" do
-
- it "determines whether a year is a leap year in the Julian calendar" do
- Date.julian_leap?(1900).should == true
- Date.julian_leap?(1999).should == false
- Date.julian_leap?(2000).should == true
- Date.julian_leap?(2002).should == false
- Date.julian_leap?(2004).should == true
- end
-
-end
-
-describe "Date#valid_jd?" do
- ruby_version_is "" ... "1.9" do
-
- it "determines if a day number is a valid Julian day number, true for all numbers" do
- # This might need to check the type of the jd parameter. Date.valid_jd?(:number) is of course
- # bogus but returns itself with the current implementation
- Date.valid_jd?(-100).should == -100
- Date.valid_jd?(0).should == 0
- Date.valid_jd?(100).should == 100
- end
- end
-
-end
-
-describe "Date.julian?" do
- ruby_version_is "" ... "1.9" do
+ruby_version_is "" ... "1.9" do
+ describe "Date.julian?" do
it "marks the date as not Julian if using the Gregorian calendar" do
- Date.julian?(Date.civil(1007, 2, 27).jd, Date::GREGORIAN).should == false
+ Date.julian?(Date.civil(1007, 2, 27).jd, Date::GREGORIAN).should be_false
end
it "marks the date as Julian if using the Julian calendar" do
- Date.julian?(Date.civil(1007, 2, 27).jd, Date::JULIAN).should == true
+ Date.julian?(Date.civil(1007, 2, 27).jd, Date::JULIAN).should be_true
end
it "marks the date before the English Day of Calendar Reform as Julian" do
- Date.julian?(Date.civil(1752, 9, 13).jd, Date::ENGLAND).should == true
+ Date.julian?(Date.civil(1752, 9, 13).jd, Date::ENGLAND).should be_true
end
it "marks the date after the English Day of Calendar Reform as not Julian" do
- Date.julian?(Date.civil(1752, 9, 14).jd, Date::ENGLAND).should == false
+ Date.julian?(Date.civil(1752, 9, 14).jd, Date::ENGLAND).should be_false
end
it "marks the date before the Italian Day of Calendar Reform as Julian" do
- Date.julian?(Date.civil(1582, 10, 4).jd, Date::ITALY).should == true
+ Date.julian?(Date.civil(1582, 10, 4).jd, Date::ITALY).should be_true
end
it "marks the date after the Italian Day of Calendar Reform as not Julian" do
- Date.julian?(Date.civil(1582, 10, 15).jd, Date::ITALY).should == false
+ Date.julian?(Date.civil(1582, 10, 15).jd, Date::ITALY).should be_false
end
end
end
-describe "Date#valid_jd?" do
- ruby_version_is "1.9" do
-
- it "determines if a day number is a valid Julian day number, true for all numbers" do
- # This might need to check the type of the jd parameter. Date.valid_jd?(:number) is of course
- # bogus but returns itself with the current implementation
- Date.valid_jd?(-100).should == true
- Date.valid_jd?(0).should == true
- Date.valid_jd?(100).should == true
- end
-
- end
-end
-
-describe "Date.julian?" do
- it "needs to be reviewed for spec completeness"
-end
View
8 library/date/minus_spec.rb
@@ -3,17 +3,17 @@
describe "Date#-" do
- it "should substract a number of days from a Date" do
+ it "substracts a number of days from a Date" do
d = Date.civil(2007, 5 ,2) - 13
d.should == Date.civil(2007, 4, 19)
end
- it "should substract a negative number of days from a Date" do
+ it "substracts a negative number of days from a Date" do
d = Date.civil(2007, 4, 19).-(-13)
d.should == Date.civil(2007, 5 ,2)
end
- it "should be able to compute the different between two dates" do
+ it "computes the difference between two dates" do
(Date.civil(2007,2,27) - Date.civil(2007,2,27)).should == 0
(Date.civil(2007,2,27) - Date.civil(2007,2,26)).should == 1
(Date.civil(2006,2,27) - Date.civil(2007,2,27)).should == -365
@@ -21,7 +21,7 @@
end
- it "should raise an error on non numeric parameters" do
+ it "raises an error for non Numeric arguments" do
lambda { Date.civil(2007,2,27) - :hello }.should raise_error(TypeError)
lambda { Date.civil(2007,2,27) - "hello" }.should raise_error(TypeError)
lambda { Date.civil(2007,2,27) - Object.new }.should raise_error(TypeError)
View
7 library/date/new0_spec.rb
@@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/new_bang', __FILE__)
require 'date'
-describe "Date.new0" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date.new0" do
+ it_behaves_like :date_new_bang, :new0
+ end
end
View
7 library/date/new1_spec.rb
@@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/jd', __FILE__)
require 'date'
-describe "Date.new1" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date.new1" do
+ it_behaves_like :date_jd, :new1
+ end
end
View
7 library/date/new2_spec.rb
@@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/ordinal', __FILE__)
require 'date'
-describe "Date.new2" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date.new2" do
+ it_behaves_like :date_ordinal, :new2
+ end
end
View
7 library/date/new3_spec.rb
@@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/civil', __FILE__)
require 'date'
-describe "Date.new3" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date.new3" do
+ it_behaves_like :date_civil, :new3
+ end
end
View
15 library/date/new_spec.rb
@@ -1,17 +1,14 @@
require 'date'
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/civil', __FILE__)
-
-describe "Date#new" do
-
- it_behaves_like(:date_civil, :new)
-
-end
+require File.expand_path('../shared/new_bang', __FILE__)
describe "Date.new" do
- it "needs to be reviewed for spec completeness"
+ it_behaves_like(:date_civil, :new)
end
-describe "Date.new!" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9.3" do
+ describe "Date.new!" do
+ it_behaves_like(:date_new_bang, :new!)
+ end
end
View
6 library/date/newsg_spec.rb
@@ -1,6 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
-describe "Date#newsg" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date#newsg" do
+ it "needs to be reviewed for spec completeness"
+ end
end
View
6 library/date/neww_spec.rb
@@ -1,6 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
-describe "Date.neww" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date.neww" do
+ it_behaves_like :date_commercial, :neww
+ end
end
View
12 library/date/ns_spec.rb
@@ -1,10 +1,12 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
-describe "Date#ns?" do
- it "needs to be reviewed for spec completeness"
-end
+ruby_version_is "" ... "1.9" do
+ describe "Date#ns?" do
+ it "needs to be reviewed for spec completeness"
+ end
-describe "Date.ns?" do
- it "needs to be reviewed for spec completeness"
+ describe "Date.ns?" do
+ it "needs to be reviewed for spec completeness"
+ end
end
View
111 library/date/ordinal_spec.rb
@@ -1,113 +1,8 @@
require 'date'
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/commercial', __FILE__)
-
-# reference:
-# October 1582 (the Gregorian calendar, Civil Date)
-# S M Tu W Th F S
-# 1 2 3 4 15 16
-# 17 18 19 20 21 22 23
-# 24 25 26 27 28 29 30
-# 31
-
-describe "Date#ordinal" do
-
- ruby_version_is "" ... "1.9" do
- it "should be able to construct a Date object from an ordinal date" do
- # October 1582 (the Gregorian calendar, Ordinal Date in 1.8)
- # S M Tu W Th F S
- # 274 275 276 277 288 289
- # 290 291 292 293 294 295 296
- # 297 298 299 300 301 302 303
- # 304
- Date.ordinal(1582, 274).should == Date.civil(1582, 10, 1)
- Date.ordinal(1582, 277).should == Date.civil(1582, 10, 4)
- lambda { Date.ordinal(1582, 278) }.should raise_error(ArgumentError)
- lambda { Date.ordinal(1582, 287) }.should raise_error(ArgumentError)
- Date.ordinal(1582, 288).should == Date.civil(1582, 10, 15)
- Date.ordinal(1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
- end
- end
-
- ruby_version_is "1.9" do
- it "should be able to construct a Date object from an ordinal date" do
- # October 1582 (the Gregorian calendar, Ordinal Date in 1.9)
- # S M Tu W Th F S
- # 274 275 276 277 278 279
- # 280 281 282 283 284 285 286
- # 287 288 289 290 291 292 293
- # 294
- Date.ordinal(1582, 274).should == Date.civil(1582, 10, 1)
- Date.ordinal(1582, 277).should == Date.civil(1582, 10, 4)
- Date.ordinal(1582, 278).should == Date.civil(1582, 10, 15)
- Date.ordinal(1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
- end
- end
-
-end
-
-describe "Date#valid_ordinal?" do
-
- ruby_version_is "" ... "1.9" do
- it "should be able to determine if the date is a valid ordinal date" do
- # October 1582 (the Gregorian calendar, Ordinal Date in 1.8)
- # S M Tu W Th F S
- # 274 275 276 277 278 279
- # 280 281 282 283 284 285 286
- # 287 288 289 290 291 292 293
- # 294
- Date.valid_ordinal?(1582, 277).should == Date.civil(1582, 10, 4).jd
- Date.valid_ordinal?(1582, 278).should == nil
- Date.valid_ordinal?(1582, 287).should == nil
- Date.valid_ordinal?(1582, 288).should == Date.civil(1582, 10, 15).jd
- Date.valid_ordinal?(1582, 287, Date::ENGLAND).should_not == nil
- Date.valid_ordinal?(1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND).jd
- end
-
- it "should be able to handle negative day numbers" do
- # October 1582 (the Gregorian calendar, Ordinal Date in 1.8)
- # S M Tu W Th F S
- # -92 -91 -90 -89 -78 -77
- # -76 -75 -74 -73 -72 -71 -70
- # -69 -68 -67 -66 -65 -64 -63
- # -62
- Date.valid_ordinal?(1582, -89).should == Date.civil(1582, 10, 4).jd
- Date.valid_ordinal?(1582, -88).should == nil
- Date.valid_ordinal?(1582, -79).should == nil
- Date.valid_ordinal?(1582, -78).should == Date.civil(1582, 10, 15).jd
- Date.valid_ordinal?(2007, -100).should == Date.valid_ordinal?(2007, 266)
- end
- end
-
- ruby_version_is "1.9" do
- it "should be able to determine if the date is a valid ordinal date" do
- # October 1582 (the Gregorian calendar, Ordinal Date in 1.9)
- # S M Tu W Th F S
- # 274 275 276 277 278 279
- # 280 281 282 283 284 285 286
- # 287 288 289 290 291 292 293
- # 294
- Date.valid_ordinal?(1582, 277).should == true
- Date.valid_ordinal?(1582, 278).should == true
- Date.valid_ordinal?(1582, 287).should == true
- Date.valid_ordinal?(1582, 288).should == true
- end
-
- it "should be able to handle negative day numbers" do
- # October 1582 (the Gregorian calendar, Ordinal Date in 1.9)
- # S M Tu W Th F S
- # -82 -81 -80 -79 -78 -77
- # -76 -75 -74 -73 -72 -71 -70
- # -69 -68 -67 -66 -65 -64 -63
- # -62
- Date.valid_ordinal?(1582, -79).should == true
- Date.valid_ordinal?(1582, -78).should == true
- Date.valid_ordinal?(2007, -100).should == true
- end
- end
-
-end
+require File.expand_path('../shared/ordinal', __FILE__)
describe "Date.ordinal" do
- it "needs to be reviewed for spec completeness"
+ it_behaves_like :date_ordinal, :ordinal
end
+
View
12 library/date/os_spec.rb
@@ -1,10 +1,12 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
-describe "Date#os?" do
- it "needs to be reviewed for spec completeness"
-end
+ruby_version_is "" ... "1.9" do
+ describe "Date#os?" do
+ it "needs to be reviewed for spec completeness"
+ end
-describe "Date.os?" do
- it "needs to be reviewed for spec completeness"
+ describe "Date.os?" do
+ it "needs to be reviewed for spec completeness"
+ end
end
View
16 library/date/plus_spec.rb
@@ -2,5 +2,19 @@
require 'date'
describe "Date#+" do
- it "needs to be reviewed for spec completeness"
+ before :all do
+ @date = Date.civil(2000, 1, 1)
+ end
+
+ it "returns a new Date object that is n days later than the current one" do
+ (@date + 31).should == Date.civil(2000, 2, 1)
+ end
+
+ it "accepts a negative argument and returns a new Date that is earlier than the current one" do
+ (@date + -1).should == Date.civil(1999, 12, 31)
+ end
+
+ it "raises TypeError if argument is not Numeric" do
+ lambda { Date.today + Date.today }.should raise_error(TypeError)
+ end
end
View
6 library/date/sg_spec.rb
@@ -1,6 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
-describe "Date#sg" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is "" ... "1.9" do
+ describe "Date#sg" do
+ it "needs to be reviewed for spec completeness"
+ end
end
View
4 library/date/shared/civil.rb
@@ -47,7 +47,7 @@
end
- it "creats a Date for different calendar reform dates" do
+ it "creates a Date for different calendar reform dates" do
d1 = Date.send(@method, 1582, 10, 4)
d1.succ.day.should == 15
@@ -56,7 +56,7 @@
end
ruby_version_is ""..."1.9.3" do
- it "choose an arbitrary reform date" do
+ it "chooses an arbitrary reform date" do
r = Date.send(@method, 2000, 2, 3)
d3 = Date.send(@method, 2000, 2, 3, r.jd)
View
14 library/date/shared/jd.rb
@@ -0,0 +1,14 @@
+describe :date_jd, :shared => true do
+ it "constructs a Date object if passed a Julian day" do
+ Date.send(@method, 2454482).should == Date.civil(2008, 1, 16)
+ end
+
+ it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed"do
+ Date.send(@method).should == Date.civil(-4712, 1, 1)
+ end
+
+ it "constructs a Date object if passed a negative number" do
+ Date.send(@method, -1).should == Date.civil(-4713, 12, 31)
+ end
+
+end
View
14 library/date/shared/new_bang.rb
@@ -0,0 +1,14 @@
+describe :date_new_bang, :shared => true do
+
+ it "returns a new Date object set to Astronomical Julian Day 0 if no arguments passed" do
+ d = Date.send(@method)
+ d.ajd.should == 0
+ end
+
+ it "accepts astronomical julian day number, offset as a fraction of a day and returns a new Date object" do
+ d = Date.send(@method, 10, 0.5)
+ d.ajd.should == 10
+ d.jd.should == 11
+ end
+
+end
View
42 library/date/shared/ordinal.rb
@@ -0,0 +1,42 @@
+# reference:
+# October 1582 (the Gregorian calendar, Civil Date)
+# S M Tu W Th F S
+# 1 2 3 4 15 16
+# 17 18 19 20 21 22 23
+# 24 25 26 27 28 29 30
+# 31
+
+describe :date_ordinal, :shared => true do
+
+ ruby_version_is "" ... "1.9" do
+ it "should be able to construct a Date object from an ordinal date" do
+ # October 1582 (the Gregorian calendar, Ordinal Date in 1.8)
+ # S M Tu W Th F S
+ # 274 275 276 277 288 289
+ # 290 291 292 293 294 295 296
+ # 297 298 299 300 301 302 303
+ # 304
+ Date.send(@method, 1582, 274).should == Date.civil(1582, 10, 1)
+ Date.send(@method, 1582, 277).should == Date.civil(1582, 10, 4)
+ lambda { Date.send(@method, 1582, 278) }.should raise_error(ArgumentError)
+ lambda { Date.send(@method, 1582, 287) }.should raise_error(ArgumentError)
+ Date.send(@method, 1582, 288).should == Date.civil(1582, 10, 15)
+ Date.send(@method, 1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "should be able to construct a Date object from an ordinal date" do
+ # October 1582 (the Gregorian calendar, Ordinal Date in 1.9)
+ # S M Tu W Th F S
+ # 274 275 276 277 278 279
+ # 280 281 282 283 284 285 286
+ # 287 288 289 290 291 292 293
+ # 294
+ Date.send(@method, 1582, 274).should == Date.civil(1582, 10, 1)
+ Date.send(@method, 1582, 277).should == Date.civil(1582, 10, 4)
+ Date.send(@method, 1582, 278).should == Date.civil(1582, 10, 15)
+ Date.send(@method, 1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
+ end
+ end
+end
View
69 library/date/shared/valid_civil.rb
@@ -0,0 +1,69 @@
+describe :date_valid_civil?, :shared => true do
+
+ # reference:
+ # October 1582 (the Gregorian calendar, Civil Date)
+ # S M Tu W Th F S
+ # 1 2 3 4 15 16
+ # 17 18 19 20 21 22 23
+ # 24 25 26 27 28 29 30
+ # 31
+
+ ruby_version_is "" ... "1.9" do
+ it "returns the corresponding Julian Day Number if it is a valid civil date" do
+ Date.send(@method, 1582, 10, 15).should == Date.civil(1582, 10, 15).jd
+ Date.send(@method, 1582, 10, 14, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND).jd
+ end
+
+ it "returns nil if it is not a valid civil date" do
+ Date.send(@method, 1582, 10, 14).should be_nil
+ Date.send(@method, 1582, 10, 14, Date::ENGLAND).should_not be_nil
+ end
+
+ it "handles negative months and days" do
+ # October 1582 (the Gregorian calendar, Civil Date in 1.8)
+ # S M Tu W Th F S
+ # -31 -30 -29 -28 -17 -16
+ # -15 -14 -13 -12 -11 -10 -9
+ # -8 -7 -6 -5 -4 -3 -2
+ # -1
+ Date.send(@method, 1582, -3, -31).should == Date.civil(1582, 10, 1).jd
+ Date.send(@method, 1582, -3, -28).should == Date.civil(1582, 10, 4).jd
+ Date.send(@method, 1582, -3, -27).should be_nil
+ Date.send(@method, 1582, -3, -22).should be_nil
+ Date.send(@method, 1582, -3, -21).should be_nil
+ Date.send(@method, 1582, -3, -18).should be_nil
+ Date.send(@method, 1582, -3, -17).should == Date.civil(1582, 10, 15).jd
+
+ Date.send(@method, 2007, -11, -10).should == Date.civil(2007, 2, 19).jd
+ Date.send(@method, 2008, -11, -10).should == Date.civil(2008, 2, 20).jd
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "returns true if it is a valid civil date" do
+ Date.send(@method, 1582, 10, 15).should be_true
+ Date.send(@method, 1582, 10, 14, Date::ENGLAND).should be_true
+ end
+
+ it "returns false if it is not a valid civil date" do
+ Date.send(@method, 1582, 10, 14).should == false
+ end
+
+ it "handles negative months and days" do
+ # October 1582 (the Gregorian calendar, Civil Date in 1.9)
+ # S M Tu W Th F S
+ # -21 -20 -19 -18 -17 -16
+ # -15 -14 -13 -12 -11 -10 -9
+ # -8 -7 -6 -5 -4 -3 -2
+ # -1
+ Date.send(@method, 1582, -3, -22).should be_false
+ Date.send(@method, 1582, -3, -21).should be_true
+ Date.send(@method, 1582, -3, -18).should be_true
+ Date.send(@method, 1582, -3, -17).should be_true
+
+ Date.send(@method, 2007, -11, -10).should be_true
+ Date.send(@method, 2008, -11, -10).should be_true
+ end
+ end
+
+end
View
66 library/date/shared/valid_commercial.rb
@@ -0,0 +1,66 @@
+describe :date_valid_commercial?, :shared => true do
+ ruby_version_is "" ... "1.9" do
+ it "returns the corresponding Julian Day Number if it is a valid commercial date" do
+ # October 1582 (the Gregorian calendar, Commercial Date in 1.8)
+ # M Tu W Th F Sa Su
+ # 41: - - - - 5 6 7
+ # 42: 1 2 3 4 5 6 7
+ # 43: 1 2 3 4 5 6 7
+ Date.send(@method, 1582, 41, 5).should == Date.civil(1582, 10, 15).jd
+ Date.send(@method, 1752, 37, 4, Date::ENGLAND).should == Date.civil(1752, 9, 14, Date::ENGLAND).jd
+ end
+
+ it "returns nil if it is not a valid commercial date" do
+ Date.send(@method, 1582, 41, 4).should be_nil
+ # valid_commercial? can't handle dates before the Gregorian calendar
+ Date.send(@method, 1582, 41, 4, Date::ENGLAND).should be_nil
+ end
+
+ it "handles negative week and day numbers" do
+ # October 1582 (the Gregorian calendar, Commercial Date in 1.8)
+ # M Tu W Th F Sa Su
+ # -12: - - - - -3 -2 -1
+ # -11: -7 -6 -5 -4 -3 -2 -1
+ # -10: -7 -6 -5 -4 -3 -2 -1
+ Date.send(@method, 1582, -12, -4).should be_nil
+ Date.send(@method, 1582, -12, -3).should == Date.civil(1582, 10, 15).jd
+
+ Date.send(@method, 2007, -44, -2).should == Date.civil(2007, 3, 3).jd
+ Date.send(@method, 2008, -44, -2).should == Date.civil(2008, 3, 1).jd
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "returns true if it is a valid commercial date" do
+ # October 1582 (the Gregorian calendar, Commercial Date in 1.9)
+ # M Tu W Th F Sa Su
+ # 39: 1 2 3 4 5 6 7
+ # 40: 1 2 3 4 5 6 7
+ # 41: 1 2 3 4 5 6 7
+ Date.send(@method, 1582, 39, 4).should be_true
+ Date.send(@method, 1582, 39, 5).should be_true
+ Date.send(@method, 1582, 41, 4).should be_true
+ Date.send(@method, 1582, 41, 5).should be_true
+ Date.send(@method, 1582, 41, 4, Date::ENGLAND).should be_true
+ Date.send(@method, 1752, 37, 4, Date::ENGLAND).should be_true
+ end
+
+ it "returns false it is not a valid commercial date" do
+ Date.send(@method, 1999, 53, 1).should be_false
+ end
+
+ it "handles negative week and day numbers" do
+ # October 1582 (the Gregorian calendar, Commercial Date in 1.9)
+ # M Tu W Th F Sa Su
+ # -12: -7 -6 -5 -4 -3 -2 -1
+ # -11: -7 -6 -5 -4 -3 -2 -1
+ # -10: -7 -6 -5 -4 -3 -2 -1
+ Date.send(@method, 1582, -12, -4).should be_true
+ Date.send(@method, 1582, -12, -3).should be_true
+ Date.send(@method, 2007, -44, -2).should be_true
+ Date.send(@method, 2008, -44, -2).should be_true
+ Date.send(@method, 1999, -53, -1).should be_false
+ end
+ end
+
+end
View
36 library/date/shared/valid_jd.rb
@@ -0,0 +1,36 @@
+describe :date_valid_jd?, :shared => true do
+ ruby_version_is "" ... "1.9" do
+ it "returns passed argument" do
+ Date.send(@method, -100).should == -100
+ Date.send(@method, :number).should == :number
+ Date.send(@method, nil).should == nil
+ end
+
+ end
+
+ ruby_version_is "1.9" do
+ it "returns true if passed any value other than nil" do
+ Date.send(@method, -100).should be_true
+ Date.send(@method, :number).should be_true
+ Date.send(@method, Rational(1,2)).should be_true
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "returns false if passed nil" do
+ Date.send(@method, nil).should be_false
+ end
+ end
+
+ ruby_version_is "1.9" ... "1.9.3" do
+ it "returns false if passed false" do
+ Date.send(@method, false).should be_false
+ end
+ end
+
+ ruby_version_is "1.9.3" do
+ it "returns true if passed false" do
+ Date.send(@method, false).should be_true
+ end
+ end
+end
View
60 library/date/shared/valid_ordinal.rb
@@ -0,0 +1,60 @@
+describe :date_valid_ordinal?, :shared => true do
+ ruby_version_is "" ... "1.9" do
+ it "should be able to determine if the date is a valid ordinal date" do
+ # October 1582 (the Gregorian calendar, Ordinal Date in 1.8)
+ # S M Tu W Th F S
+ # 274 275 276 277 278 279
+ # 280 281 282 283 284 285 286
+ # 287 288 289 290 291 292 293
+ # 294
+ Date.send(@method, 1582, 277).should == Date.civil(1582, 10, 4).jd
+ Date.send(@method, 1582, 278).should == nil
+ Date.send(@method, 1582, 287).should == nil
+ Date.send(@method, 1582, 288).should == Date.civil(1582, 10, 15).jd
+ Date.send(@method, 1582, 287, Date::ENGLAND).should_not == nil
+ Date.send(@method, 1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND).jd
+ end
+
+ it "should be able to handle negative day numbers" do
+ # October 1582 (the Gregorian calendar, Ordinal Date in 1.8)
+ # S M Tu W Th F S
+ # -92 -91 -90 -89 -78 -77
+ # -76 -75 -74 -73 -72 -71 -70
+ # -69 -68 -67 -66 -65 -64 -63
+ # -62
+ Date.send(@method, 1582, -89).should == Date.civil(1582, 10, 4).jd
+ Date.send(@method, 1582, -88).should == nil
+ Date.send(@method, 1582, -79).should == nil
+ Date.send(@method, 1582, -78).should == Date.civil(1582, 10, 15).jd
+ Date.send(@method, 2007, -100).should == Date.send(@method, 2007, 266)
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "should be able to determine if the date is a valid ordinal date" do
+ # October 1582 (the Gregorian calendar, Ordinal Date in 1.9)
+ # S M Tu W Th F S
+ # 274 275 276 277 278 279
+ # 280 281 282 283 284 285 286
+ # 287 288 289 290 291 292 293
+ # 294
+ Date.send(@method, 1582, 277).should == true
+ Date.send(@method, 1582, 278).should == true
+ Date.send(@method, 1582, 287).should == true
+ Date.send(@method, 1582, 288).should == true
+ end
+
+ it "should be able to handle negative day numbers" do
+ # October 1582 (the Gregorian calendar, Ordinal Date in 1.9)
+ # S M Tu W Th F S
+ # -82 -81 -80 -79 -78 -77
+ # -76 -75 -74 -73 -72 -71 -70
+ # -69 -68 -67 -66 -65 -64 -63
+ # -62
+ Date.send(@method, 1582, -79).should == true
+ Date.send(@method, 1582, -78).should == true
+ Date.send(@method, 2007, -100).should == true
+ end
+ end
+
+end
View
8 library/date/valid_civil_spec.rb
@@ -1,6 +1,10 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/valid_civil', __FILE__)
require 'date'
-describe "Date.valid_civil?" do
- it "needs to be reviewed for spec completeness"
+describe "Date#valid_civil?" do
+
+ it_behaves_like :date_valid_civil?, :valid_civil?
+
end
+
View
8 library/date/valid_commercial_spec.rb
@@ -1,6 +1,10 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/valid_commercial', __FILE__)
require 'date'
-describe "Date.valid_commercial?" do
- it "needs to be reviewed for spec completeness"
+describe "Date#valid_commercial?" do
+
+ it_behaves_like :date_valid_commercial?, :valid_commercial?
end
+
+
View
2  library/date/valid_date_spec.rb
@@ -2,5 +2,5 @@
require 'date'
describe "Date.valid_date?" do
- it "needs to be reviewed for spec completeness"
+ it_behaves_like :date_valid_civil?, :valid_date?
end
View
6 library/date/valid_jd_spec.rb
@@ -1,6 +1,10 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/valid_jd', __FILE__)
require 'date'
describe "Date.valid_jd?" do
- it "needs to be reviewed for spec completeness"
+
+ it_behaves_like :date_valid_jd?, :valid_jd?
+
end
+
View
6 library/date/valid_ordinal_spec.rb
@@ -1,6 +1,10 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/valid_ordinal', __FILE__)
require 'date'
describe "Date.valid_ordinal?" do
- it "needs to be reviewed for spec completeness"
+
+ it_behaves_like :date_valid_ordinal?, :valid_ordinal?
+
end
+
Please sign in to comment.
Something went wrong with that request. Please try again.