diff options
Diffstat (limited to 'spec/ruby/library/date')
121 files changed, 442 insertions, 285 deletions
diff --git a/spec/ruby/library/date/accessor_spec.rb b/spec/ruby/library/date/accessor_spec.rb index 91e0c3fc88..74ed0e9c21 100644 --- a/spec/ruby/library/date/accessor_spec.rb +++ b/spec/ruby/library/date/accessor_spec.rb @@ -1,5 +1,5 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' describe "Date#ajd" do it "determines the Astronomical Julian day" do @@ -38,7 +38,7 @@ describe "Date#year" do end describe "Date#yday" do - it "determines the year" do + it "determines the day of the year" do Date.civil(2007, 1, 17).yday.should == 17 Date.civil(2008, 10, 28).yday.should == 302 end diff --git a/spec/ruby/library/date/add_month_spec.rb b/spec/ruby/library/date/add_month_spec.rb index 46f1915b70..ab802ea97a 100644 --- a/spec/ruby/library/date/add_month_spec.rb +++ b/spec/ruby/library/date/add_month_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#>>" do @@ -21,18 +21,18 @@ describe "Date#>>" do end it "raise a TypeError when passed a Symbol" do - lambda { Date.civil(2007,2,27) >> :hello }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) >> :hello }.should.raise(TypeError) end it "raise a TypeError when passed a String" do - lambda { Date.civil(2007,2,27) >> "hello" }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) >> "hello" }.should.raise(TypeError) end it "raise a TypeError when passed a Date" do - lambda { Date.civil(2007,2,27) >> Date.new }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) >> Date.new }.should.raise(TypeError) end it "raise a TypeError when passed an Object" do - lambda { Date.civil(2007,2,27) >> Object.new }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) >> Object.new }.should.raise(TypeError) end end diff --git a/spec/ruby/library/date/add_spec.rb b/spec/ruby/library/date/add_spec.rb index 022b793318..5e368decdc 100644 --- a/spec/ruby/library/date/add_spec.rb +++ b/spec/ruby/library/date/add_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#+" do @@ -13,18 +13,18 @@ describe "Date#+" do end it "raises a TypeError when passed a Symbol" do - lambda { Date.civil(2007,2,27) + :hello }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) + :hello }.should.raise(TypeError) end it "raises a TypeError when passed a String" do - lambda { Date.civil(2007,2,27) + "hello" }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) + "hello" }.should.raise(TypeError) end it "raises a TypeError when passed a Date" do - lambda { Date.civil(2007,2,27) + Date.new }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) + Date.new }.should.raise(TypeError) end it "raises a TypeError when passed an Object" do - lambda { Date.civil(2007,2,27) + Object.new }.should raise_error(TypeError) + -> { Date.civil(2007,2,27) + Object.new }.should.raise(TypeError) end end diff --git a/spec/ruby/library/date/ajd_spec.rb b/spec/ruby/library/date/ajd_spec.rb index fcbcea2426..10f1302354 100644 --- a/spec/ruby/library/date/ajd_spec.rb +++ b/spec/ruby/library/date/ajd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#ajd" do diff --git a/spec/ruby/library/date/ajd_to_amjd_spec.rb b/spec/ruby/library/date/ajd_to_amjd_spec.rb index fc6a35d0c6..948f4c2236 100644 --- a/spec/ruby/library/date/ajd_to_amjd_spec.rb +++ b/spec/ruby/library/date/ajd_to_amjd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.ajd_to_amjd" do diff --git a/spec/ruby/library/date/ajd_to_jd_spec.rb b/spec/ruby/library/date/ajd_to_jd_spec.rb index 1d8d6d0eb5..e55ce9f4f2 100644 --- a/spec/ruby/library/date/ajd_to_jd_spec.rb +++ b/spec/ruby/library/date/ajd_to_jd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.ajd_to_jd" do diff --git a/spec/ruby/library/date/amjd_spec.rb b/spec/ruby/library/date/amjd_spec.rb index 212871ee18..ad7bc14965 100644 --- a/spec/ruby/library/date/amjd_spec.rb +++ b/spec/ruby/library/date/amjd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#amjd" do diff --git a/spec/ruby/library/date/amjd_to_ajd_spec.rb b/spec/ruby/library/date/amjd_to_ajd_spec.rb index f45f202a40..66c26a16a8 100644 --- a/spec/ruby/library/date/amjd_to_ajd_spec.rb +++ b/spec/ruby/library/date/amjd_to_ajd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.amjd_to_ajd" do diff --git a/spec/ruby/library/date/append_spec.rb b/spec/ruby/library/date/append_spec.rb index d90eff9a7a..4305a00321 100644 --- a/spec/ruby/library/date/append_spec.rb +++ b/spec/ruby/library/date/append_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#<<" do diff --git a/spec/ruby/library/date/asctime_spec.rb b/spec/ruby/library/date/asctime_spec.rb index 13dede0f05..67d158cc01 100644 --- a/spec/ruby/library/date/asctime_spec.rb +++ b/spec/ruby/library/date/asctime_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#asctime" do diff --git a/spec/ruby/library/date/boat_spec.rb b/spec/ruby/library/date/boat_spec.rb index 3004c6bfbc..e4f1b797fc 100644 --- a/spec/ruby/library/date/boat_spec.rb +++ b/spec/ruby/library/date/boat_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#<=>" do diff --git a/spec/ruby/library/date/case_compare_spec.rb b/spec/ruby/library/date/case_compare_spec.rb index 2144a616a3..87d522ee6a 100644 --- a/spec/ruby/library/date/case_compare_spec.rb +++ b/spec/ruby/library/date/case_compare_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#===" do diff --git a/spec/ruby/library/date/civil_spec.rb b/spec/ruby/library/date/civil_spec.rb index 36e790aecd..1c780fce56 100644 --- a/spec/ruby/library/date/civil_spec.rb +++ b/spec/ruby/library/date/civil_spec.rb @@ -1,12 +1,7 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/civil', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/civil' require 'date' -describe "Date#civil" do - it_behaves_like(:date_civil, :civil) -end - - describe "Date.civil" do - it "needs to be reviewed for spec completeness" + it_behaves_like :date_civil, :civil end diff --git a/spec/ruby/library/date/commercial_spec.rb b/spec/ruby/library/date/commercial_spec.rb index bb6671eda1..d7fc34d74a 100644 --- a/spec/ruby/library/date/commercial_spec.rb +++ b/spec/ruby/library/date/commercial_spec.rb @@ -1,10 +1,10 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/commercial', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/commercial' describe "Date#commercial" do - it_behaves_like(:date_commercial, :commercial) + it_behaves_like :date_commercial, :commercial end @@ -15,4 +15,3 @@ end # 17 18 19 20 21 22 23 # 24 25 26 27 28 29 30 # 31 - diff --git a/spec/ruby/library/date/commercial_to_jd_spec.rb b/spec/ruby/library/date/commercial_to_jd_spec.rb index 61631a7977..9b77f1229f 100644 --- a/spec/ruby/library/date/commercial_to_jd_spec.rb +++ b/spec/ruby/library/date/commercial_to_jd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.commercial_to_jd" do diff --git a/spec/ruby/library/date/comparison_spec.rb b/spec/ruby/library/date/comparison_spec.rb index 04bfa2e8f7..1a94b9dcd2 100644 --- a/spec/ruby/library/date/comparison_spec.rb +++ b/spec/ruby/library/date/comparison_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#<=>" do diff --git a/spec/ruby/library/date/constants_spec.rb b/spec/ruby/library/date/constants_spec.rb index ae343f07ec..3494b0c296 100644 --- a/spec/ruby/library/date/constants_spec.rb +++ b/spec/ruby/library/date/constants_spec.rb @@ -1,5 +1,5 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' describe "Date constants" do @@ -34,13 +34,13 @@ describe "Date constants" do it "freezes MONTHNAMES, DAYNAMES, ABBR_MONTHNAMES, ABBR_DAYSNAMES" do [Date::MONTHNAMES, Date::DAYNAMES, Date::ABBR_MONTHNAMES, Date::ABBR_DAYNAMES].each do |ary| - lambda { + -> { ary << "Unknown" - }.should raise_error(RuntimeError, /frozen/) + }.should.raise(FrozenError, /frozen/) ary.compact.each do |name| - lambda { + -> { name << "modified" - }.should raise_error(RuntimeError, /frozen/) + }.should.raise(FrozenError, /frozen/) end end end diff --git a/spec/ruby/library/date/conversions_spec.rb b/spec/ruby/library/date/conversions_spec.rb index c52ade7012..a9a320b0fc 100644 --- a/spec/ruby/library/date/conversions_spec.rb +++ b/spec/ruby/library/date/conversions_spec.rb @@ -1,5 +1,5 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' describe "Date#new_start" do diff --git a/spec/ruby/library/date/ctime_spec.rb b/spec/ruby/library/date/ctime_spec.rb index 0f5d594842..3faa7c6380 100644 --- a/spec/ruby/library/date/ctime_spec.rb +++ b/spec/ruby/library/date/ctime_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#ctime" do diff --git a/spec/ruby/library/date/cwday_spec.rb b/spec/ruby/library/date/cwday_spec.rb index 33ede37b2c..c5a39f277f 100644 --- a/spec/ruby/library/date/cwday_spec.rb +++ b/spec/ruby/library/date/cwday_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#cwday" do diff --git a/spec/ruby/library/date/cweek_spec.rb b/spec/ruby/library/date/cweek_spec.rb index d988bdd9db..6f7aab3922 100644 --- a/spec/ruby/library/date/cweek_spec.rb +++ b/spec/ruby/library/date/cweek_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#cweek" do diff --git a/spec/ruby/library/date/cwyear_spec.rb b/spec/ruby/library/date/cwyear_spec.rb index 00544927bc..a85ee29920 100644 --- a/spec/ruby/library/date/cwyear_spec.rb +++ b/spec/ruby/library/date/cwyear_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#cwyear" do diff --git a/spec/ruby/library/date/day_fraction_spec.rb b/spec/ruby/library/date/day_fraction_spec.rb index 64896a421e..12b873773f 100644 --- a/spec/ruby/library/date/day_fraction_spec.rb +++ b/spec/ruby/library/date/day_fraction_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#day_fraction" do diff --git a/spec/ruby/library/date/day_fraction_to_time_spec.rb b/spec/ruby/library/date/day_fraction_to_time_spec.rb index 609367371a..d4741d65ec 100644 --- a/spec/ruby/library/date/day_fraction_to_time_spec.rb +++ b/spec/ruby/library/date/day_fraction_to_time_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.day_fraction_to_time" do diff --git a/spec/ruby/library/date/day_spec.rb b/spec/ruby/library/date/day_spec.rb index d3561d802d..bc727c4717 100644 --- a/spec/ruby/library/date/day_spec.rb +++ b/spec/ruby/library/date/day_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#day" do diff --git a/spec/ruby/library/date/deconstruct_keys_spec.rb b/spec/ruby/library/date/deconstruct_keys_spec.rb new file mode 100644 index 0000000000..1fa1e70250 --- /dev/null +++ b/spec/ruby/library/date/deconstruct_keys_spec.rb @@ -0,0 +1,42 @@ +require_relative '../../spec_helper' +require 'date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' + +describe "Date#deconstruct_keys" do + it "returns whole hash for nil as an argument" do + d = Date.new(2022, 10, 5) + d.deconstruct_keys(nil).should == { year: 2022, month: 10, day: 5, yday: 278, wday: 3 } + end + + it "returns only specified keys" do + d = Date.new(2022, 10, 5) + d.deconstruct_keys([:year, :month]).should == { year: 2022, month: 10 } + end + + it "requires one argument" do + -> { + Date.new(2022, 10, 5).deconstruct_keys + }.should.raise(ArgumentError) + end + + it "it raises error when argument is neither nil nor array" do + d = Date.new(2022, 10, 5) + + -> { d.deconstruct_keys(1) }.should.raise(TypeError, "wrong argument type Integer (expected Array or nil)") + -> { d.deconstruct_keys("asd") }.should.raise(TypeError, "wrong argument type String (expected Array or nil)") + -> { d.deconstruct_keys(:x) }.should.raise(TypeError, "wrong argument type Symbol (expected Array or nil)") + -> { d.deconstruct_keys({}) }.should.raise(TypeError, "wrong argument type Hash (expected Array or nil)") + end + + it "returns {} when passed []" do + Date.new(2022, 10, 5).deconstruct_keys([]).should == {} + end + + it "ignores non-Symbol keys" do + Date.new(2022, 10, 5).deconstruct_keys(['year', []]).should == {} + end + + it "ignores not existing Symbol keys" do + Date.new(2022, 10, 5).deconstruct_keys([:year, :a]).should == { year: 2022 } + end +end diff --git a/spec/ruby/library/date/downto_spec.rb b/spec/ruby/library/date/downto_spec.rb index ab9bf11952..84c641ee14 100644 --- a/spec/ruby/library/date/downto_spec.rb +++ b/spec/ruby/library/date/downto_spec.rb @@ -1,5 +1,5 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' describe "Date#downto" do diff --git a/spec/ruby/library/date/england_spec.rb b/spec/ruby/library/date/england_spec.rb index 6c67c6ee86..2e30530c5a 100644 --- a/spec/ruby/library/date/england_spec.rb +++ b/spec/ruby/library/date/england_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#england" do diff --git a/spec/ruby/library/date/eql_spec.rb b/spec/ruby/library/date/eql_spec.rb index efecde8944..79fabc47f4 100644 --- a/spec/ruby/library/date/eql_spec.rb +++ b/spec/ruby/library/date/eql_spec.rb @@ -1,12 +1,12 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#eql?" do it "returns true if self is equal to another date" do - Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 11)).should be_true + Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 11)).should == true end it "returns false if self is not equal to another date" do - Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 12)).should be_false + Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 12)).should == false end end diff --git a/spec/ruby/library/date/format/bag/method_missing_spec.rb b/spec/ruby/library/date/format/bag/method_missing_spec.rb index 529fde05d2..03e4fbcd30 100644 --- a/spec/ruby/library/date/format/bag/method_missing_spec.rb +++ b/spec/ruby/library/date/format/bag/method_missing_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../../spec_helper', __FILE__) +require_relative '../../../../spec_helper' require 'date' describe "Date::Format::Bag#method_missing" do diff --git a/spec/ruby/library/date/format/bag/to_hash_spec.rb b/spec/ruby/library/date/format/bag/to_hash_spec.rb index ba9525e5e8..76734624b9 100644 --- a/spec/ruby/library/date/format/bag/to_hash_spec.rb +++ b/spec/ruby/library/date/format/bag/to_hash_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../../spec_helper', __FILE__) +require_relative '../../../../spec_helper' require 'date' describe "Date::Format::Bag#to_hash" do diff --git a/spec/ruby/library/date/friday_spec.rb b/spec/ruby/library/date/friday_spec.rb index 369b943419..62f050346e 100644 --- a/spec/ruby/library/date/friday_spec.rb +++ b/spec/ruby/library/date/friday_spec.rb @@ -1,12 +1,12 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#friday?" do it "should be friday" do - Date.new(2000, 1, 7).friday?.should be_true + Date.new(2000, 1, 7).friday?.should == true end it "should not be friday" do - Date.new(2000, 1, 8).friday?.should be_false + Date.new(2000, 1, 8).friday?.should == false end end diff --git a/spec/ruby/library/date/gregorian_leap_spec.rb b/spec/ruby/library/date/gregorian_leap_spec.rb index 043d57aa93..c27890faf4 100644 --- a/spec/ruby/library/date/gregorian_leap_spec.rb +++ b/spec/ruby/library/date/gregorian_leap_spec.rb @@ -1,16 +1,15 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' 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 + 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 be_false - Date.gregorian_leap?(1999).should be_false - Date.gregorian_leap?(2002).should be_false + Date.gregorian_leap?(1900).should == false + Date.gregorian_leap?(1999).should == false + Date.gregorian_leap?(2002).should == false end end - diff --git a/spec/ruby/library/date/gregorian_spec.rb b/spec/ruby/library/date/gregorian_spec.rb index 5d8b38b2d8..bbda13af08 100644 --- a/spec/ruby/library/date/gregorian_spec.rb +++ b/spec/ruby/library/date/gregorian_spec.rb @@ -1,16 +1,16 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#gregorian?" do it "marks a day before the calendar reform as Julian" do - Date.civil(1007, 2, 27).gregorian?.should be_false - Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).gregorian?.should be_false + Date.civil(1007, 2, 27).gregorian?.should == false + Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).gregorian?.should == 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 be_true + Date.civil(2007, 2, 27).should.gregorian? + Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).gregorian?.should == true end end diff --git a/spec/ruby/library/date/hash_spec.rb b/spec/ruby/library/date/hash_spec.rb index 271d565253..4fb452d486 100644 --- a/spec/ruby/library/date/hash_spec.rb +++ b/spec/ruby/library/date/hash_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#hash" do diff --git a/spec/ruby/library/date/infinity/abs_spec.rb b/spec/ruby/library/date/infinity/abs_spec.rb index a1107679f6..c08189155d 100644 --- a/spec/ruby/library/date/infinity/abs_spec.rb +++ b/spec/ruby/library/date/infinity/abs_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'date' describe "Date::Infinity#abs" do diff --git a/spec/ruby/library/date/infinity/coerce_spec.rb b/spec/ruby/library/date/infinity/coerce_spec.rb index e09b948064..75e5ebeab7 100644 --- a/spec/ruby/library/date/infinity/coerce_spec.rb +++ b/spec/ruby/library/date/infinity/coerce_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'date' describe "Date::Infinity#coerce" do diff --git a/spec/ruby/library/date/infinity/comparison_spec.rb b/spec/ruby/library/date/infinity/comparison_spec.rb index 7bf8fb7b9f..a9b9d124fd 100644 --- a/spec/ruby/library/date/infinity/comparison_spec.rb +++ b/spec/ruby/library/date/infinity/comparison_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'date' describe "Date::Infinity#<=>" do diff --git a/spec/ruby/library/date/infinity/d_spec.rb b/spec/ruby/library/date/infinity/d_spec.rb index 9ef1f71408..a5bd2427c7 100644 --- a/spec/ruby/library/date/infinity/d_spec.rb +++ b/spec/ruby/library/date/infinity/d_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'date' describe "Date::Infinity#d" do diff --git a/spec/ruby/library/date/infinity/finite_spec.rb b/spec/ruby/library/date/infinity/finite_spec.rb index 92806935fc..8971c2213e 100644 --- a/spec/ruby/library/date/infinity/finite_spec.rb +++ b/spec/ruby/library/date/infinity/finite_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'date' describe "Date::Infinity#finite?" do diff --git a/spec/ruby/library/date/infinity/infinite_spec.rb b/spec/ruby/library/date/infinity/infinite_spec.rb index 8c7e0bc86a..848f538672 100644 --- a/spec/ruby/library/date/infinity/infinite_spec.rb +++ b/spec/ruby/library/date/infinity/infinite_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'date' describe "Date::Infinity#infinite?" do diff --git a/spec/ruby/library/date/infinity/nan_spec.rb b/spec/ruby/library/date/infinity/nan_spec.rb index 19c7ae0af3..b0f5d8ac7a 100644 --- a/spec/ruby/library/date/infinity/nan_spec.rb +++ b/spec/ruby/library/date/infinity/nan_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'date' describe "Date::Infinity#nan?" do diff --git a/spec/ruby/library/date/infinity/uminus_spec.rb b/spec/ruby/library/date/infinity/uminus_spec.rb index 110e197231..1b1f568103 100644 --- a/spec/ruby/library/date/infinity/uminus_spec.rb +++ b/spec/ruby/library/date/infinity/uminus_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'date' describe "Date::Infinity#-@" do diff --git a/spec/ruby/library/date/infinity/uplus_spec.rb b/spec/ruby/library/date/infinity/uplus_spec.rb index dfc60b6b61..6a3b2d8442 100644 --- a/spec/ruby/library/date/infinity/uplus_spec.rb +++ b/spec/ruby/library/date/infinity/uplus_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'date' describe "Date::Infinity#+@" do diff --git a/spec/ruby/library/date/infinity/zero_spec.rb b/spec/ruby/library/date/infinity/zero_spec.rb index 2f4347255b..7df5518785 100644 --- a/spec/ruby/library/date/infinity/zero_spec.rb +++ b/spec/ruby/library/date/infinity/zero_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'date' describe "Date::Infinity#zero?" do diff --git a/spec/ruby/library/date/infinity_spec.rb b/spec/ruby/library/date/infinity_spec.rb index 127fb8c2f4..721fd76066 100644 --- a/spec/ruby/library/date/infinity_spec.rb +++ b/spec/ruby/library/date/infinity_spec.rb @@ -1,20 +1,20 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' describe "Date::Infinity" do it "should be able to check whether Infinity is zero" do i = Date::Infinity.new - i.zero?.should == false + i.should_not.zero? end it "should be able to check whether Infinity is finite" do i1 = Date::Infinity.new - i1.finite?.should == false + i1.should_not.finite? i2 = Date::Infinity.new(-1) - i2.finite?.should == false + i2.should_not.finite? i3 = Date::Infinity.new(0) - i3.finite?.should == false + i3.should_not.finite? end it "should be able to check whether Infinity is infinite" do @@ -28,11 +28,11 @@ describe "Date::Infinity" do it "should be able to check whether Infinity is not a number" do i1 = Date::Infinity.new - i1.nan?.should == false + i1.should_not.nan? i2 = Date::Infinity.new(-1) - i2.nan?.should == false + i2.should_not.nan? i3 = Date::Infinity.new(0) - i3.nan?.should == true + i3.should.nan? end it "should be able to compare Infinity objects" do diff --git a/spec/ruby/library/date/inspect_spec.rb b/spec/ruby/library/date/inspect_spec.rb index 150eb6bf24..81c2cc8003 100644 --- a/spec/ruby/library/date/inspect_spec.rb +++ b/spec/ruby/library/date/inspect_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#inspect" do diff --git a/spec/ruby/library/date/iso8601_spec.rb b/spec/ruby/library/date/iso8601_spec.rb new file mode 100644 index 0000000000..26815bd76c --- /dev/null +++ b/spec/ruby/library/date/iso8601_spec.rb @@ -0,0 +1,56 @@ +require_relative '../../spec_helper' +require 'date' + +describe "Date.iso8601" do + it "parses YYYY-MM-DD into a Date object" do + d = Date.iso8601("2018-01-01") + d.should == Date.civil(2018, 1, 1) + end + + it "parses YYYYMMDD into a Date object" do + d = Date.iso8601("20180715") + d.should == Date.civil(2018, 7, 15) + end + + it "parses a negative Date" do + d = Date.iso8601("-4712-01-01") + d.should == Date.civil(-4712, 1, 1) + end + + it "parses a StringSubclass into a Date object" do + d = Date.iso8601(Class.new(String).new("-4712-01-01")) + d.should == Date.civil(-4712, 1, 1) + end + + it "raises a Date::Error if the argument is a invalid Date" do + -> { + Date.iso8601('invalid') + }.should.raise(Date::Error, "invalid date") + end + + it "raises a Date::Error when passed a nil" do + -> { + Date.iso8601(nil) + }.should.raise(Date::Error, "invalid date") + end + + it "raises a TypeError when passed an Object" do + -> { Date.iso8601(Object.new) }.should.raise(TypeError) + end +end + +describe "Date._iso8601" do + it "returns an empty hash if the argument is a invalid Date" do + h = Date._iso8601('invalid') + h.should == {} + end + + it "returns an empty hash if the argument is nil" do + h = Date._iso8601(nil) + h.should == {} + end + + it "raises a TypeError when passed an Object" do + -> { Date._iso8601(Object.new) }.should.raise(TypeError) + end +end diff --git a/spec/ruby/library/date/italy_spec.rb b/spec/ruby/library/date/italy_spec.rb index 2d251db1b0..9369b05180 100644 --- a/spec/ruby/library/date/italy_spec.rb +++ b/spec/ruby/library/date/italy_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#italy" do diff --git a/spec/ruby/library/date/jd_spec.rb b/spec/ruby/library/date/jd_spec.rb index ccf6b93e06..336b783e8d 100644 --- a/spec/ruby/library/date/jd_spec.rb +++ b/spec/ruby/library/date/jd_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/jd', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/jd' require 'date' describe "Date#jd" do diff --git a/spec/ruby/library/date/jd_to_ajd_spec.rb b/spec/ruby/library/date/jd_to_ajd_spec.rb index 38a12bd65d..f946c46b8a 100644 --- a/spec/ruby/library/date/jd_to_ajd_spec.rb +++ b/spec/ruby/library/date/jd_to_ajd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.jd_to_ajd" do diff --git a/spec/ruby/library/date/jd_to_civil_spec.rb b/spec/ruby/library/date/jd_to_civil_spec.rb index 8608de2698..13b6e47ee2 100644 --- a/spec/ruby/library/date/jd_to_civil_spec.rb +++ b/spec/ruby/library/date/jd_to_civil_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.jd_to_civil" do diff --git a/spec/ruby/library/date/jd_to_commercial_spec.rb b/spec/ruby/library/date/jd_to_commercial_spec.rb index 97d76130f2..2256b74f2a 100644 --- a/spec/ruby/library/date/jd_to_commercial_spec.rb +++ b/spec/ruby/library/date/jd_to_commercial_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.jd_to_commercial" do diff --git a/spec/ruby/library/date/jd_to_ld_spec.rb b/spec/ruby/library/date/jd_to_ld_spec.rb index d27ada6b6c..5954014f85 100644 --- a/spec/ruby/library/date/jd_to_ld_spec.rb +++ b/spec/ruby/library/date/jd_to_ld_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.jd_to_ld" do diff --git a/spec/ruby/library/date/jd_to_mjd_spec.rb b/spec/ruby/library/date/jd_to_mjd_spec.rb index 064134c7ed..24eb84e171 100644 --- a/spec/ruby/library/date/jd_to_mjd_spec.rb +++ b/spec/ruby/library/date/jd_to_mjd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.jd_to_mjd" do diff --git a/spec/ruby/library/date/jd_to_ordinal_spec.rb b/spec/ruby/library/date/jd_to_ordinal_spec.rb index a5f5c79641..c7c1704948 100644 --- a/spec/ruby/library/date/jd_to_ordinal_spec.rb +++ b/spec/ruby/library/date/jd_to_ordinal_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.jd_to_ordinal" do diff --git a/spec/ruby/library/date/jd_to_wday_spec.rb b/spec/ruby/library/date/jd_to_wday_spec.rb index 569a53e409..27e00b2044 100644 --- a/spec/ruby/library/date/jd_to_wday_spec.rb +++ b/spec/ruby/library/date/jd_to_wday_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.jd_to_wday" do diff --git a/spec/ruby/library/date/julian_leap_spec.rb b/spec/ruby/library/date/julian_leap_spec.rb index 3915f97693..42231e012f 100644 --- a/spec/ruby/library/date/julian_leap_spec.rb +++ b/spec/ruby/library/date/julian_leap_spec.rb @@ -1,15 +1,15 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.julian_leap?" do 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 + Date.julian_leap?(1900).should == true + Date.julian_leap?(2000).should == true + Date.julian_leap?(2004).should == 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 + Date.julian_leap?(1999).should == false + Date.julian_leap?(2002).should == false end end diff --git a/spec/ruby/library/date/julian_spec.rb b/spec/ruby/library/date/julian_spec.rb index 8cbe27b881..9f8a670899 100644 --- a/spec/ruby/library/date/julian_spec.rb +++ b/spec/ruby/library/date/julian_spec.rb @@ -1,16 +1,16 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' 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 be_true + Date.civil(1007, 2, 27).should.julian? + Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).julian?.should == 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 be_false + Date.civil(2007, 2, 27).should_not.julian? + Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).julian?.should == false end end diff --git a/spec/ruby/library/date/ld_spec.rb b/spec/ruby/library/date/ld_spec.rb index a59b519c04..73a47d2382 100644 --- a/spec/ruby/library/date/ld_spec.rb +++ b/spec/ruby/library/date/ld_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#ld" do diff --git a/spec/ruby/library/date/ld_to_jd_spec.rb b/spec/ruby/library/date/ld_to_jd_spec.rb index 7adbbede37..37abe01449 100644 --- a/spec/ruby/library/date/ld_to_jd_spec.rb +++ b/spec/ruby/library/date/ld_to_jd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.ld_to_jd" do diff --git a/spec/ruby/library/date/leap_spec.rb b/spec/ruby/library/date/leap_spec.rb index bb8e920a3e..674b191c9f 100644 --- a/spec/ruby/library/date/leap_spec.rb +++ b/spec/ruby/library/date/leap_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#leap?" do diff --git a/spec/ruby/library/date/mday_spec.rb b/spec/ruby/library/date/mday_spec.rb index 8a1d6e8d59..53f6f98169 100644 --- a/spec/ruby/library/date/mday_spec.rb +++ b/spec/ruby/library/date/mday_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#mday" do diff --git a/spec/ruby/library/date/minus_month_spec.rb b/spec/ruby/library/date/minus_month_spec.rb index 51befcc6d4..d56e19dc31 100644 --- a/spec/ruby/library/date/minus_month_spec.rb +++ b/spec/ruby/library/date/minus_month_spec.rb @@ -1,5 +1,5 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' describe "Date#<<" do @@ -13,13 +13,11 @@ describe "Date#<<" do d.should == Date.civil(2008, 2, 29) end - ruby_version_is "2.3" do - it "raises an error on non numeric parameters" 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) << Date.new }.should raise_error(TypeError) - lambda { Date.civil(2007,2,27) << Object.new }.should raise_error(TypeError) - end + it "raises an error on non numeric parameters" do + -> { Date.civil(2007,2,27) << :hello }.should.raise(TypeError) + -> { Date.civil(2007,2,27) << "hello" }.should.raise(TypeError) + -> { Date.civil(2007,2,27) << Date.new }.should.raise(TypeError) + -> { Date.civil(2007,2,27) << Object.new }.should.raise(TypeError) end end diff --git a/spec/ruby/library/date/minus_spec.rb b/spec/ruby/library/date/minus_spec.rb index fd7f3fd14c..c2a08fa5b0 100644 --- a/spec/ruby/library/date/minus_spec.rb +++ b/spec/ruby/library/date/minus_spec.rb @@ -1,5 +1,5 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' describe "Date#-" do @@ -22,9 +22,9 @@ describe "Date#-" do end 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) + -> { Date.civil(2007,2,27) - :hello }.should.raise(TypeError) + -> { Date.civil(2007,2,27) - "hello" }.should.raise(TypeError) + -> { Date.civil(2007,2,27) - Object.new }.should.raise(TypeError) end end diff --git a/spec/ruby/library/date/mjd_spec.rb b/spec/ruby/library/date/mjd_spec.rb index 7de39f0047..6f03af346b 100644 --- a/spec/ruby/library/date/mjd_spec.rb +++ b/spec/ruby/library/date/mjd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#mjd" do diff --git a/spec/ruby/library/date/mjd_to_jd_spec.rb b/spec/ruby/library/date/mjd_to_jd_spec.rb index fdda1330e5..2009261103 100644 --- a/spec/ruby/library/date/mjd_to_jd_spec.rb +++ b/spec/ruby/library/date/mjd_to_jd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.mjd_to_jd" do diff --git a/spec/ruby/library/date/mon_spec.rb b/spec/ruby/library/date/mon_spec.rb index c3508b53bf..616d72cf88 100644 --- a/spec/ruby/library/date/mon_spec.rb +++ b/spec/ruby/library/date/mon_spec.rb @@ -1,6 +1,7 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/month' require 'date' describe "Date#mon" do - it "needs to be reviewed for spec completeness" + it_behaves_like :date_month, :mon end diff --git a/spec/ruby/library/date/monday_spec.rb b/spec/ruby/library/date/monday_spec.rb index f7d968b6d6..61d728f3c5 100644 --- a/spec/ruby/library/date/monday_spec.rb +++ b/spec/ruby/library/date/monday_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#monday?" do it "should be monday" do - Date.new(2000, 1, 3).monday?.should be_true + Date.new(2000, 1, 3).monday?.should == true end end diff --git a/spec/ruby/library/date/month_spec.rb b/spec/ruby/library/date/month_spec.rb index ea35430d6b..f493ec8119 100644 --- a/spec/ruby/library/date/month_spec.rb +++ b/spec/ruby/library/date/month_spec.rb @@ -1,9 +1,7 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/month' require 'date' describe "Date#month" do - it "returns the month" do - m = Date.new(2000, 7, 1).month - m.should == 7 - end + it_behaves_like :date_month, :month end diff --git a/spec/ruby/library/date/new_spec.rb b/spec/ruby/library/date/new_spec.rb index f468036a01..cb64cabce6 100644 --- a/spec/ruby/library/date/new_spec.rb +++ b/spec/ruby/library/date/new_spec.rb @@ -1,8 +1,7 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/civil', __FILE__) -require File.expand_path('../shared/new_bang', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/civil' describe "Date.new" do - it_behaves_like(:date_civil, :new) + it_behaves_like :date_civil, :new end diff --git a/spec/ruby/library/date/new_start_spec.rb b/spec/ruby/library/date/new_start_spec.rb index 94ec6bee46..aef78f2320 100644 --- a/spec/ruby/library/date/new_start_spec.rb +++ b/spec/ruby/library/date/new_start_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#new_start" do diff --git a/spec/ruby/library/date/next_day_spec.rb b/spec/ruby/library/date/next_day_spec.rb index 795bfecf0a..3b066630e7 100644 --- a/spec/ruby/library/date/next_day_spec.rb +++ b/spec/ruby/library/date/next_day_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#next_day" do diff --git a/spec/ruby/library/date/next_month_spec.rb b/spec/ruby/library/date/next_month_spec.rb index 9becd7e37f..6ee664433f 100644 --- a/spec/ruby/library/date/next_month_spec.rb +++ b/spec/ruby/library/date/next_month_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#next_month" do diff --git a/spec/ruby/library/date/next_spec.rb b/spec/ruby/library/date/next_spec.rb index d88d31e974..8063d6a2e4 100644 --- a/spec/ruby/library/date/next_spec.rb +++ b/spec/ruby/library/date/next_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#next" do diff --git a/spec/ruby/library/date/next_year_spec.rb b/spec/ruby/library/date/next_year_spec.rb index 70f2f7ab77..dda9a44008 100644 --- a/spec/ruby/library/date/next_year_spec.rb +++ b/spec/ruby/library/date/next_year_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#next_year" do diff --git a/spec/ruby/library/date/ordinal_spec.rb b/spec/ruby/library/date/ordinal_spec.rb index a373692a7b..ec490fd49c 100644 --- a/spec/ruby/library/date/ordinal_spec.rb +++ b/spec/ruby/library/date/ordinal_spec.rb @@ -1,8 +1,7 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/ordinal', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/ordinal' describe "Date.ordinal" do it_behaves_like :date_ordinal, :ordinal end - diff --git a/spec/ruby/library/date/ordinal_to_jd_spec.rb b/spec/ruby/library/date/ordinal_to_jd_spec.rb index 0a76c69c00..44f4b3321e 100644 --- a/spec/ruby/library/date/ordinal_to_jd_spec.rb +++ b/spec/ruby/library/date/ordinal_to_jd_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.ordinal_to_jd" do diff --git a/spec/ruby/library/date/parse_spec.rb b/spec/ruby/library/date/parse_spec.rb index 092c658809..4d655f516e 100644 --- a/spec/ruby/library/date/parse_spec.rb +++ b/spec/ruby/library/date/parse_spec.rb @@ -1,7 +1,7 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/parse', __FILE__) -require File.expand_path('../shared/parse_us', __FILE__) -require File.expand_path('../shared/parse_eu', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/parse' +require_relative 'shared/parse_us' +require_relative 'shared/parse_eu' require 'date' describe "Date#parse" do @@ -23,7 +23,7 @@ describe "Date#parse" do # Specs using numbers it "throws an argument error for a single digit" do - lambda{ Date.parse("1") }.should raise_error(ArgumentError) + ->{ Date.parse("1") }.should.raise(ArgumentError) end it "parses DD as month day number" do @@ -64,6 +64,28 @@ describe "Date#parse" do d = Date.parse("19101101") d.should == Date.civil(1910, 11, 1) end + + it "raises a TypeError trying to parse non-String-like object" do + -> { Date.parse(1) }.should.raise(TypeError) + -> { Date.parse([]) }.should.raise(TypeError) + end + + it "coerces using to_str" do + c = Class.new do + attr_accessor :string + def to_str + @string + end + end + o = c.new + o.string = "19101101" + + d = Date.parse(o) + d.should == Date.civil(1910, 11, 1) + + # parse should not modify string value + o.to_str.should == "19101101" + end end describe "Date#parse with '.' separator" do @@ -71,7 +93,7 @@ describe "Date#parse with '.' separator" do @sep = '.' end - it_should_behave_like "date_parse" + it_should_behave_like :date_parse end describe "Date#parse with '/' separator" do @@ -79,7 +101,7 @@ describe "Date#parse with '/' separator" do @sep = '/' end - it_should_behave_like "date_parse" + it_should_behave_like :date_parse end describe "Date#parse with ' ' separator" do @@ -87,7 +109,7 @@ describe "Date#parse with ' ' separator" do @sep = ' ' end - it_should_behave_like "date_parse" + it_should_behave_like :date_parse end describe "Date#parse with '/' separator US-style" do @@ -95,7 +117,7 @@ describe "Date#parse with '/' separator US-style" do @sep = '/' end - it_should_behave_like "date_parse_us" + it_should_behave_like :date_parse_us end describe "Date#parse with '-' separator EU-style" do @@ -103,7 +125,7 @@ describe "Date#parse with '-' separator EU-style" do @sep = '-' end - it_should_behave_like "date_parse_eu" + it_should_behave_like :date_parse_eu end describe "Date#parse(.)" do diff --git a/spec/ruby/library/date/plus_spec.rb b/spec/ruby/library/date/plus_spec.rb index e33fb199eb..6179370fca 100644 --- a/spec/ruby/library/date/plus_spec.rb +++ b/spec/ruby/library/date/plus_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#+" do @@ -15,6 +15,6 @@ describe "Date#+" do end it "raises TypeError if argument is not Numeric" do - lambda { Date.today + Date.today }.should raise_error(TypeError) + -> { Date.today + Date.today }.should.raise(TypeError) end end diff --git a/spec/ruby/library/date/prev_day_spec.rb b/spec/ruby/library/date/prev_day_spec.rb index 149bfe9fa9..cce24da875 100644 --- a/spec/ruby/library/date/prev_day_spec.rb +++ b/spec/ruby/library/date/prev_day_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#prev_day" do diff --git a/spec/ruby/library/date/prev_month_spec.rb b/spec/ruby/library/date/prev_month_spec.rb index 440c17ffc9..3d0d1d437d 100644 --- a/spec/ruby/library/date/prev_month_spec.rb +++ b/spec/ruby/library/date/prev_month_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#prev_month" do diff --git a/spec/ruby/library/date/prev_year_spec.rb b/spec/ruby/library/date/prev_year_spec.rb index 4f27d1d1f9..ba06dd198b 100644 --- a/spec/ruby/library/date/prev_year_spec.rb +++ b/spec/ruby/library/date/prev_year_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#prev_year" do diff --git a/spec/ruby/library/date/relationship_spec.rb b/spec/ruby/library/date/relationship_spec.rb index 7c09457228..979516e164 100644 --- a/spec/ruby/library/date/relationship_spec.rb +++ b/spec/ruby/library/date/relationship_spec.rb @@ -1,5 +1,5 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' describe "Date#===" do diff --git a/spec/ruby/library/date/rfc3339_spec.rb b/spec/ruby/library/date/rfc3339_spec.rb new file mode 100644 index 0000000000..a8711d47b2 --- /dev/null +++ b/spec/ruby/library/date/rfc3339_spec.rb @@ -0,0 +1,13 @@ +require_relative '../../spec_helper' +require 'date' + +describe "Date.rfc3339" do + it "needs to be reviewed for spec completeness" +end + +describe "Date._rfc3339" do + it "returns an empty hash if the argument is a invalid Date" do + h = Date._rfc3339('invalid') + h.should == {} + end +end diff --git a/spec/ruby/library/date/right_shift_spec.rb b/spec/ruby/library/date/right_shift_spec.rb index 3d55e5abed..bd7de0e3d5 100644 --- a/spec/ruby/library/date/right_shift_spec.rb +++ b/spec/ruby/library/date/right_shift_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#>>" do diff --git a/spec/ruby/library/date/saturday_spec.rb b/spec/ruby/library/date/saturday_spec.rb index 1360050a69..29f8267a2b 100644 --- a/spec/ruby/library/date/saturday_spec.rb +++ b/spec/ruby/library/date/saturday_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#saturday?" do it "should be saturday" do - Date.new(2000, 1, 1).saturday?.should be_true + Date.new(2000, 1, 1).saturday?.should == true end end diff --git a/spec/ruby/library/date/shared/civil.rb b/spec/ruby/library/date/shared/civil.rb index 47dbed49fc..4499cdf8e9 100644 --- a/spec/ruby/library/date/shared/civil.rb +++ b/spec/ruby/library/date/shared/civil.rb @@ -5,7 +5,7 @@ describe :date_civil, shared: true do d.year.should == -4712 d.month.should == 1 d.day.should == 1 - d.julian?.should == true + d.should.julian? d.jd.should == 0 end @@ -14,7 +14,7 @@ describe :date_civil, shared: true do d.year.should == 2000 d.month.should == 3 d.day.should == 5 - d.julian?.should == false + d.should_not.julian? d.jd.should == 2451609 # Should also work with years far in the past and future @@ -23,27 +23,27 @@ describe :date_civil, shared: true do d.year.should == -9000 d.month.should == 7 d.day.should == 5 - d.julian?.should == true + d.should.julian? d.jd.should == -1566006 d = Date.send(@method, 9000, 10, 14) d.year.should == 9000 d.month.should == 10 d.day.should == 14 - d.julian?.should == false + d.should_not.julian? d.jd.should == 5008529 end it "doesn't create dates for invalid arguments" do - lambda { Date.send(@method, 2000, 13, 31) }.should raise_error(ArgumentError) - lambda { Date.send(@method, 2000, 12, 32) }.should raise_error(ArgumentError) - lambda { Date.send(@method, 2000, 2, 30) }.should raise_error(ArgumentError) - lambda { Date.send(@method, 1900, 2, 29) }.should raise_error(ArgumentError) - lambda { Date.send(@method, 2000, 2, 29) }.should_not raise_error(ArgumentError) - - lambda { Date.send(@method, 1582, 10, 14) }.should raise_error(ArgumentError) - lambda { Date.send(@method, 1582, 10, 15) }.should_not raise_error(ArgumentError) + -> { Date.send(@method, 2000, 13, 31) }.should.raise(ArgumentError) + -> { Date.send(@method, 2000, 12, 32) }.should.raise(ArgumentError) + -> { Date.send(@method, 2000, 2, 30) }.should.raise(ArgumentError) + -> { Date.send(@method, 1900, 2, 29) }.should.raise(ArgumentError) + -> { Date.send(@method, 2000, 2, 29) }.should_not.raise(ArgumentError) + + -> { Date.send(@method, 1582, 10, 14) }.should.raise(ArgumentError) + -> { Date.send(@method, 1582, 10, 15) }.should_not.raise(ArgumentError) end diff --git a/spec/ruby/library/date/shared/commercial.rb b/spec/ruby/library/date/shared/commercial.rb index 354a5d5cd0..f53d83235a 100644 --- a/spec/ruby/library/date/shared/commercial.rb +++ b/spec/ruby/library/date/shared/commercial.rb @@ -25,15 +25,15 @@ describe :date_commercial, shared: true do end it "creates only Date objects for valid weeks" do - lambda { Date.send(@method, 2004, 53, 1) }.should_not raise_error(ArgumentError) - lambda { Date.send(@method, 2004, 53, 0) }.should raise_error(ArgumentError) - lambda { Date.send(@method, 2004, 53, 8) }.should raise_error(ArgumentError) - lambda { Date.send(@method, 2004, 54, 1) }.should raise_error(ArgumentError) - lambda { Date.send(@method, 2004, 0, 1) }.should raise_error(ArgumentError) + -> { Date.send(@method, 2004, 53, 1) }.should_not.raise(ArgumentError) + -> { Date.send(@method, 2004, 53, 0) }.should.raise(ArgumentError) + -> { Date.send(@method, 2004, 53, 8) }.should.raise(ArgumentError) + -> { Date.send(@method, 2004, 54, 1) }.should.raise(ArgumentError) + -> { Date.send(@method, 2004, 0, 1) }.should.raise(ArgumentError) - lambda { Date.send(@method, 2003, 52, 1) }.should_not raise_error(ArgumentError) - lambda { Date.send(@method, 2003, 53, 1) }.should raise_error(ArgumentError) - lambda { Date.send(@method, 2003, 52, 0) }.should raise_error(ArgumentError) - lambda { Date.send(@method, 2003, 52, 8) }.should raise_error(ArgumentError) + -> { Date.send(@method, 2003, 52, 1) }.should_not.raise(ArgumentError) + -> { Date.send(@method, 2003, 53, 1) }.should.raise(ArgumentError) + -> { Date.send(@method, 2003, 52, 0) }.should.raise(ArgumentError) + -> { Date.send(@method, 2003, 52, 8) }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/date/shared/month.rb b/spec/ruby/library/date/shared/month.rb new file mode 100644 index 0000000000..5fcb2cbeb0 --- /dev/null +++ b/spec/ruby/library/date/shared/month.rb @@ -0,0 +1,6 @@ +describe :date_month, shared: true do + it "returns the month" do + m = Date.new(2000, 7, 1).send(@method) + m.should == 7 + end +end diff --git a/spec/ruby/library/date/shared/new_bang.rb b/spec/ruby/library/date/shared/new_bang.rb deleted file mode 100644 index 90f1b432f0..0000000000 --- a/spec/ruby/library/date/shared/new_bang.rb +++ /dev/null @@ -1,14 +0,0 @@ -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 diff --git a/spec/ruby/library/date/shared/parse.rb b/spec/ruby/library/date/shared/parse.rb index 1015285e04..40af908386 100644 --- a/spec/ruby/library/date/shared/parse.rb +++ b/spec/ruby/library/date/shared/parse.rb @@ -13,7 +13,7 @@ describe :date_parse, shared: true do d.day.should == 23 end - it "can parse a 'mmm DD YYYY' string into a Date object" do + it "can parse a 'DD mmm YYYY' string into a Date object" do d = Date.parse("23#{@sep}feb#{@sep}2008") d.year.should == 2008 d.month.should == 2 @@ -42,7 +42,7 @@ describe :date_parse, shared: true do d.should == Date.civil(2005, 11, 5) end - it "can parse a year, day and month name into a Date object" do + it "can parse a day, month name and year into a Date object" do d = Date.parse("5th#{@sep}november#{@sep}2005") d.should == Date.civil(2005, 11, 5) end diff --git a/spec/ruby/library/date/shared/parse_eu.rb b/spec/ruby/library/date/shared/parse_eu.rb index ecb15e3c0e..3819524a57 100644 --- a/spec/ruby/library/date/shared/parse_eu.rb +++ b/spec/ruby/library/date/shared/parse_eu.rb @@ -7,28 +7,28 @@ describe :date_parse_eu, shared: true do d.day.should == 1 end - it "can parse a MM-DD-YYYY string into a Date object" do + it "can parse a DD-MM-YYYY string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}2007") d.year.should == 2007 d.month.should == 1 d.day.should == 10 end - it "can parse a MM-DD-YY string into a Date object" do + it "can parse a YY-MM-DD string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}07") d.year.should == 2010 d.month.should == 1 d.day.should == 7 end - it "can parse a MM-DD-YY string into a Date object NOT using the year digits as 20XX" do + it "can parse a YY-MM-DD string into a Date object NOT using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", false) d.year.should == 10 d.month.should == 1 d.day.should == 7 end - it "can parse a MM-DD-YY string into a Date object using the year digits as 20XX" do + it "can parse a YY-MM-DD string into a Date object using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", true) d.year.should == 2010 d.month.should == 1 diff --git a/spec/ruby/library/date/shared/parse_us.rb b/spec/ruby/library/date/shared/parse_us.rb index 7be62b1af1..17e2fc96c1 100644 --- a/spec/ruby/library/date/shared/parse_us.rb +++ b/spec/ruby/library/date/shared/parse_us.rb @@ -6,28 +6,28 @@ describe :date_parse_us, shared: true do d.day.should == 1 end - it "parses a MM#{@sep}DD#{@sep}YYYY string into a Date object" do + it "parses a DD#{@sep}MM#{@sep}YYYY string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}2007") d.year.should == 2007 d.month.should == 1 d.day.should == 10 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}07") d.year.should == 2010 d.month.should == 1 d.day.should == 7 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object NOT using the year digits as 20XX" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object NOT using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", false) d.year.should == 10 d.month.should == 1 d.day.should == 7 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object using the year digits as 20XX" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", true) d.year.should == 2010 d.month.should == 1 diff --git a/spec/ruby/library/date/shared/valid_civil.rb b/spec/ruby/library/date/shared/valid_civil.rb index 545c207bbe..425fee4d2d 100644 --- a/spec/ruby/library/date/shared/valid_civil.rb +++ b/spec/ruby/library/date/shared/valid_civil.rb @@ -9,8 +9,8 @@ describe :date_valid_civil?, shared: true do # 31 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 + Date.send(@method, 1582, 10, 15).should == true + Date.send(@method, 1582, 10, 14, Date::ENGLAND).should == true end it "returns false if it is not a valid civil date" do @@ -24,13 +24,13 @@ describe :date_valid_civil?, shared: true do # -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, 1582, -3, -22).should == false + Date.send(@method, 1582, -3, -21).should == true + Date.send(@method, 1582, -3, -18).should == true + Date.send(@method, 1582, -3, -17).should == true - Date.send(@method, 2007, -11, -10).should be_true - Date.send(@method, 2008, -11, -10).should be_true + Date.send(@method, 2007, -11, -10).should == true + Date.send(@method, 2008, -11, -10).should == true end end diff --git a/spec/ruby/library/date/shared/valid_commercial.rb b/spec/ruby/library/date/shared/valid_commercial.rb index 117dfe1d3d..573b851fdd 100644 --- a/spec/ruby/library/date/shared/valid_commercial.rb +++ b/spec/ruby/library/date/shared/valid_commercial.rb @@ -6,16 +6,16 @@ describe :date_valid_commercial?, shared: true do # 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 + Date.send(@method, 1582, 39, 4).should == true + Date.send(@method, 1582, 39, 5).should == true + Date.send(@method, 1582, 41, 4).should == true + Date.send(@method, 1582, 41, 5).should == true + Date.send(@method, 1582, 41, 4, Date::ENGLAND).should == true + Date.send(@method, 1752, 37, 4, Date::ENGLAND).should == true end it "returns false it is not a valid commercial date" do - Date.send(@method, 1999, 53, 1).should be_false + Date.send(@method, 1999, 53, 1).should == false end it "handles negative week and day numbers" do @@ -24,11 +24,11 @@ describe :date_valid_commercial?, shared: true do # -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 + Date.send(@method, 1582, -12, -4).should == true + Date.send(@method, 1582, -12, -3).should == true + Date.send(@method, 2007, -44, -2).should == true + Date.send(@method, 2008, -44, -2).should == true + Date.send(@method, 1999, -53, -1).should == false end end diff --git a/spec/ruby/library/date/shared/valid_jd.rb b/spec/ruby/library/date/shared/valid_jd.rb index bd71f5abba..0c01710208 100644 --- a/spec/ruby/library/date/shared/valid_jd.rb +++ b/spec/ruby/library/date/shared/valid_jd.rb @@ -1,15 +1,20 @@ describe :date_valid_jd?, shared: true 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 + it "returns true if passed a number value" do + Date.send(@method, -100).should == true + Date.send(@method, 100.0).should == true + Date.send(@method, 2**100).should == true + Date.send(@method, Rational(1,2)).should == true end it "returns false if passed nil" do - Date.send(@method, nil).should be_false + Date.send(@method, nil).should == false end - it "returns true if passed false" do - Date.send(@method, false).should be_true + it "returns false if passed symbol" do + Date.send(@method, :number).should == false + end + + it "returns false if passed false" do + Date.send(@method, false).should == false end end diff --git a/spec/ruby/library/date/start_spec.rb b/spec/ruby/library/date/start_spec.rb index 285037b094..8ba272a7f3 100644 --- a/spec/ruby/library/date/start_spec.rb +++ b/spec/ruby/library/date/start_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#start" do diff --git a/spec/ruby/library/date/step_spec.rb b/spec/ruby/library/date/step_spec.rb index 249633e807..6bbd671840 100644 --- a/spec/ruby/library/date/step_spec.rb +++ b/spec/ruby/library/date/step_spec.rb @@ -1,5 +1,5 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' describe "Date#step" do diff --git a/spec/ruby/library/date/strftime_spec.rb b/spec/ruby/library/date/strftime_spec.rb index 81bb162ff7..1b93a8d1b2 100644 --- a/spec/ruby/library/date/strftime_spec.rb +++ b/spec/ruby/library/date/strftime_spec.rb @@ -1,9 +1,11 @@ +require_relative "../../spec_helper" require 'date' -require File.expand_path('../../../shared/time/strftime_for_date', __FILE__) +require_relative '../../shared/time/strftime_for_date' +date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0' describe "Date#strftime" do before :all do - @new_date = lambda { |y,m,d| Date.civil(y,m,d) } + @new_date = -> y, m, d { Date.civil(y,m,d) } @date = Date.civil(2000, 4, 9) end @@ -21,10 +23,9 @@ describe "Date#strftime" do @date.strftime("%Z").should == "+00:00" end - # %v is %e-%b-%Y for Date/DateTime it "should be able to show the commercial week" do - @date.strftime("%v").should == " 9-Apr-2000" - @date.strftime("%v").should == @date.strftime('%e-%b-%Y') + @date.strftime("%v").should == " 9-APR-2000" + @date.strftime("%v").should != @date.strftime('%e-%b-%Y') end # additional conversion specifiers only in Date/DateTime diff --git a/spec/ruby/library/date/strptime_spec.rb b/spec/ruby/library/date/strptime_spec.rb index 21a73da086..c90721751e 100644 --- a/spec/ruby/library/date/strptime_spec.rb +++ b/spec/ruby/library/date/strptime_spec.rb @@ -1,5 +1,5 @@ require 'date' -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' describe "Date#strptime" do diff --git a/spec/ruby/library/date/succ_spec.rb b/spec/ruby/library/date/succ_spec.rb index 2650810e73..c4a902aa63 100644 --- a/spec/ruby/library/date/succ_spec.rb +++ b/spec/ruby/library/date/succ_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#succ" do diff --git a/spec/ruby/library/date/sunday_spec.rb b/spec/ruby/library/date/sunday_spec.rb index d805006264..548f36a4f0 100644 --- a/spec/ruby/library/date/sunday_spec.rb +++ b/spec/ruby/library/date/sunday_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#sunday?" do it "should be sunday" do - Date.new(2000, 1, 2).sunday?.should be_true + Date.new(2000, 1, 2).sunday?.should == true end end diff --git a/spec/ruby/library/date/thursday_spec.rb b/spec/ruby/library/date/thursday_spec.rb index a59ca3f6cf..4df3b9103a 100644 --- a/spec/ruby/library/date/thursday_spec.rb +++ b/spec/ruby/library/date/thursday_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#thursday?" do it "should be thursday" do - Date.new(2000, 1, 6).thursday?.should be_true + Date.new(2000, 1, 6).thursday?.should == true end end diff --git a/spec/ruby/library/date/time/to_date_spec.rb b/spec/ruby/library/date/time/to_date_spec.rb new file mode 100644 index 0000000000..f9132da289 --- /dev/null +++ b/spec/ruby/library/date/time/to_date_spec.rb @@ -0,0 +1,42 @@ + +require_relative '../../../spec_helper' +require 'time' + +describe "Time#to_date" do + it "yields accurate julian date for ambiguous pre-Gregorian reform value" do + Time.utc(1582, 10, 4).to_date.jd.should == Date::ITALY - 11 # 2299150j + end + + it "yields accurate julian date for Julian-Gregorian gap value" do + Time.utc(1582, 10, 14).to_date.jd.should == Date::ITALY - 1 # 2299160j + end + + it "yields accurate julian date for post-Gregorian reform value" do + Time.utc(1582, 10, 15).to_date.jd.should == Date::ITALY # 2299161j + end + + it "yields same julian day regardless of UTC time value" do + Time.utc(1582, 10, 15, 00, 00, 00).to_date.jd.should == Date::ITALY + Time.utc(1582, 10, 15, 23, 59, 59).to_date.jd.should == Date::ITALY + end + + it "yields same julian day regardless of local time or zone" do + + with_timezone("Pacific/Pago_Pago", -11) do + Time.local(1582, 10, 15, 00, 00, 00).to_date.jd.should == Date::ITALY + Time.local(1582, 10, 15, 23, 59, 59).to_date.jd.should == Date::ITALY + end + + with_timezone("Asia/Kamchatka", +12) do + Time.local(1582, 10, 15, 00, 00, 00).to_date.jd.should == Date::ITALY + Time.local(1582, 10, 15, 23, 59, 59).to_date.jd.should == Date::ITALY + end + + end + + it "yields date with default Calendar reform day" do + Time.utc(1582, 10, 4).to_date.start.should == Date::ITALY + Time.utc(1582, 10, 14).to_date.start.should == Date::ITALY + Time.utc(1582, 10, 15).to_date.start.should == Date::ITALY + end +end diff --git a/spec/ruby/library/date/time_to_day_fraction_spec.rb b/spec/ruby/library/date/time_to_day_fraction_spec.rb index 06d477b601..e59980e036 100644 --- a/spec/ruby/library/date/time_to_day_fraction_spec.rb +++ b/spec/ruby/library/date/time_to_day_fraction_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.time_to_day_fraction" do diff --git a/spec/ruby/library/date/to_s_spec.rb b/spec/ruby/library/date/to_s_spec.rb index a81297d689..fe7cb19a46 100644 --- a/spec/ruby/library/date/to_s_spec.rb +++ b/spec/ruby/library/date/to_s_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#to_s" do diff --git a/spec/ruby/library/date/today_spec.rb b/spec/ruby/library/date/today_spec.rb index d487be089f..4be8d8e931 100644 --- a/spec/ruby/library/date/today_spec.rb +++ b/spec/ruby/library/date/today_spec.rb @@ -1,9 +1,9 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.today" do it "returns a Date object" do - Date.today.should be_kind_of Date + Date.today.should.is_a? Date end it "sets Date object to the current date" do diff --git a/spec/ruby/library/date/tuesday_spec.rb b/spec/ruby/library/date/tuesday_spec.rb index 10ed6755d1..db31387aed 100644 --- a/spec/ruby/library/date/tuesday_spec.rb +++ b/spec/ruby/library/date/tuesday_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#tuesday?" do it "should be tuesday" do - Date.new(2000, 1, 4).tuesday?.should be_true + Date.new(2000, 1, 4).tuesday?.should == true end end diff --git a/spec/ruby/library/date/upto_spec.rb b/spec/ruby/library/date/upto_spec.rb index c99aabd1d7..8745be85b3 100644 --- a/spec/ruby/library/date/upto_spec.rb +++ b/spec/ruby/library/date/upto_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#upto" do diff --git a/spec/ruby/library/date/valid_civil_spec.rb b/spec/ruby/library/date/valid_civil_spec.rb index 09185674ee..00f2c57205 100644 --- a/spec/ruby/library/date/valid_civil_spec.rb +++ b/spec/ruby/library/date/valid_civil_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/valid_civil', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/valid_civil' require 'date' describe "Date#valid_civil?" do @@ -7,4 +7,3 @@ describe "Date#valid_civil?" do it_behaves_like :date_valid_civil?, :valid_civil? end - diff --git a/spec/ruby/library/date/valid_commercial_spec.rb b/spec/ruby/library/date/valid_commercial_spec.rb index 187d818233..7e96782b6b 100644 --- a/spec/ruby/library/date/valid_commercial_spec.rb +++ b/spec/ruby/library/date/valid_commercial_spec.rb @@ -1,10 +1,8 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/valid_commercial', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/valid_commercial' require 'date' describe "Date#valid_commercial?" do it_behaves_like :date_valid_commercial?, :valid_commercial? end - - diff --git a/spec/ruby/library/date/valid_date_spec.rb b/spec/ruby/library/date/valid_date_spec.rb index ffaf007cd1..f12a71d966 100644 --- a/spec/ruby/library/date/valid_date_spec.rb +++ b/spec/ruby/library/date/valid_date_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/valid_civil', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/valid_civil' require 'date' describe "Date#valid_date?" do diff --git a/spec/ruby/library/date/valid_jd_spec.rb b/spec/ruby/library/date/valid_jd_spec.rb index 9764c02f2b..aecaaabcf4 100644 --- a/spec/ruby/library/date/valid_jd_spec.rb +++ b/spec/ruby/library/date/valid_jd_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/valid_jd', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/valid_jd' require 'date' describe "Date.valid_jd?" do @@ -7,4 +7,3 @@ describe "Date.valid_jd?" do it_behaves_like :date_valid_jd?, :valid_jd? end - diff --git a/spec/ruby/library/date/valid_ordinal_spec.rb b/spec/ruby/library/date/valid_ordinal_spec.rb index e197bb2051..58d548c704 100644 --- a/spec/ruby/library/date/valid_ordinal_spec.rb +++ b/spec/ruby/library/date/valid_ordinal_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/valid_ordinal', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/valid_ordinal' require 'date' describe "Date.valid_ordinal?" do @@ -7,4 +7,3 @@ describe "Date.valid_ordinal?" do it_behaves_like :date_valid_ordinal?, :valid_ordinal? end - diff --git a/spec/ruby/library/date/valid_time_spec.rb b/spec/ruby/library/date/valid_time_spec.rb index e96f9041b7..87c239bedb 100644 --- a/spec/ruby/library/date/valid_time_spec.rb +++ b/spec/ruby/library/date/valid_time_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.valid_time?" do diff --git a/spec/ruby/library/date/wday_spec.rb b/spec/ruby/library/date/wday_spec.rb index 7303423123..303905ed35 100644 --- a/spec/ruby/library/date/wday_spec.rb +++ b/spec/ruby/library/date/wday_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#wday" do diff --git a/spec/ruby/library/date/wednesday_spec.rb b/spec/ruby/library/date/wednesday_spec.rb index 99478f21c2..4bbeead5b8 100644 --- a/spec/ruby/library/date/wednesday_spec.rb +++ b/spec/ruby/library/date/wednesday_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#wednesday?" do it "should be wednesday" do - Date.new(2000, 1, 5).wednesday?.should be_true + Date.new(2000, 1, 5).wednesday?.should == true end end diff --git a/spec/ruby/library/date/yday_spec.rb b/spec/ruby/library/date/yday_spec.rb index 92bf616406..7dd42e52a5 100644 --- a/spec/ruby/library/date/yday_spec.rb +++ b/spec/ruby/library/date/yday_spec.rb @@ -1,6 +1,7 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' +require_relative '../../shared/time/yday' require 'date' describe "Date#yday" do - it "needs to be reviewed for spec completeness" + it_behaves_like :time_yday, -> year, month, day { Date.new(year, month, day).yday } end diff --git a/spec/ruby/library/date/year_spec.rb b/spec/ruby/library/date/year_spec.rb index 4720ddcd9a..90d14e5a39 100644 --- a/spec/ruby/library/date/year_spec.rb +++ b/spec/ruby/library/date/year_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date#year" do diff --git a/spec/ruby/library/date/zone_to_diff_spec.rb b/spec/ruby/library/date/zone_to_diff_spec.rb index a39de0b58e..354daaaee4 100644 --- a/spec/ruby/library/date/zone_to_diff_spec.rb +++ b/spec/ruby/library/date/zone_to_diff_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'date' describe "Date.zone_to_diff" do |
