summaryrefslogtreecommitdiff
path: root/spec/ruby/library/date
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/date')
-rw-r--r--spec/ruby/library/date/accessor_spec.rb2
-rw-r--r--spec/ruby/library/date/add_month_spec.rb8
-rw-r--r--spec/ruby/library/date/add_spec.rb8
-rw-r--r--spec/ruby/library/date/civil_spec.rb7
-rw-r--r--spec/ruby/library/date/constants_spec.rb4
-rw-r--r--spec/ruby/library/date/deconstruct_keys_spec.rb42
-rw-r--r--spec/ruby/library/date/eql_spec.rb4
-rw-r--r--spec/ruby/library/date/friday_spec.rb4
-rw-r--r--spec/ruby/library/date/gregorian_leap_spec.rb10
-rw-r--r--spec/ruby/library/date/gregorian_spec.rb6
-rw-r--r--spec/ruby/library/date/iso8601_spec.rb23
-rw-r--r--spec/ruby/library/date/julian_leap_spec.rb10
-rw-r--r--spec/ruby/library/date/julian_spec.rb4
-rw-r--r--spec/ruby/library/date/minus_month_spec.rb8
-rw-r--r--spec/ruby/library/date/minus_spec.rb6
-rw-r--r--spec/ruby/library/date/mon_spec.rb3
-rw-r--r--spec/ruby/library/date/monday_spec.rb2
-rw-r--r--spec/ruby/library/date/month_spec.rb6
-rw-r--r--spec/ruby/library/date/new_spec.rb1
-rw-r--r--spec/ruby/library/date/parse_spec.rb16
-rw-r--r--spec/ruby/library/date/plus_spec.rb2
-rw-r--r--spec/ruby/library/date/saturday_spec.rb2
-rw-r--r--spec/ruby/library/date/shared/civil.rb16
-rw-r--r--spec/ruby/library/date/shared/commercial.rb18
-rw-r--r--spec/ruby/library/date/shared/month.rb6
-rw-r--r--spec/ruby/library/date/shared/new_bang.rb14
-rw-r--r--spec/ruby/library/date/shared/parse.rb4
-rw-r--r--spec/ruby/library/date/shared/parse_eu.rb8
-rw-r--r--spec/ruby/library/date/shared/parse_us.rb8
-rw-r--r--spec/ruby/library/date/shared/valid_civil.rb16
-rw-r--r--spec/ruby/library/date/shared/valid_commercial.rb24
-rw-r--r--spec/ruby/library/date/shared/valid_jd.rb14
-rw-r--r--spec/ruby/library/date/strftime_spec.rb18
-rw-r--r--spec/ruby/library/date/sunday_spec.rb2
-rw-r--r--spec/ruby/library/date/thursday_spec.rb2
-rw-r--r--spec/ruby/library/date/time/to_date_spec.rb42
-rw-r--r--spec/ruby/library/date/today_spec.rb2
-rw-r--r--spec/ruby/library/date/tuesday_spec.rb2
-rw-r--r--spec/ruby/library/date/wednesday_spec.rb2
-rw-r--r--spec/ruby/library/date/yday_spec.rb3
40 files changed, 231 insertions, 148 deletions
diff --git a/spec/ruby/library/date/accessor_spec.rb b/spec/ruby/library/date/accessor_spec.rb
index 68a2d9f3de..74ed0e9c21 100644
--- a/spec/ruby/library/date/accessor_spec.rb
+++ b/spec/ruby/library/date/accessor_spec.rb
@@ -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 40833f6487..ab802ea97a 100644
--- a/spec/ruby/library/date/add_month_spec.rb
+++ b/spec/ruby/library/date/add_month_spec.rb
@@ -21,18 +21,18 @@ describe "Date#>>" do
end
it "raise a TypeError when passed a Symbol" do
- -> { 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
- -> { 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
- -> { 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
- -> { 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 2b9cc62023..5e368decdc 100644
--- a/spec/ruby/library/date/add_spec.rb
+++ b/spec/ruby/library/date/add_spec.rb
@@ -13,18 +13,18 @@ describe "Date#+" do
end
it "raises a TypeError when passed a Symbol" do
- -> { 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
- -> { 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
- -> { 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
- -> { 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/civil_spec.rb b/spec/ruby/library/date/civil_spec.rb
index f3537c2f84..1c780fce56 100644
--- a/spec/ruby/library/date/civil_spec.rb
+++ b/spec/ruby/library/date/civil_spec.rb
@@ -2,11 +2,6 @@ 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/constants_spec.rb b/spec/ruby/library/date/constants_spec.rb
index 1d18dd1b0c..3494b0c296 100644
--- a/spec/ruby/library/date/constants_spec.rb
+++ b/spec/ruby/library/date/constants_spec.rb
@@ -36,11 +36,11 @@ describe "Date constants" do
[Date::MONTHNAMES, Date::DAYNAMES, Date::ABBR_MONTHNAMES, Date::ABBR_DAYNAMES].each do |ary|
-> {
ary << "Unknown"
- }.should raise_error(FrozenError, /frozen/)
+ }.should.raise(FrozenError, /frozen/)
ary.compact.each do |name|
-> {
name << "modified"
- }.should raise_error(FrozenError, /frozen/)
+ }.should.raise(FrozenError, /frozen/)
end
end
end
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/eql_spec.rb b/spec/ruby/library/date/eql_spec.rb
index a1819cae3a..79fabc47f4 100644
--- a/spec/ruby/library/date/eql_spec.rb
+++ b/spec/ruby/library/date/eql_spec.rb
@@ -3,10 +3,10 @@ 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/friday_spec.rb b/spec/ruby/library/date/friday_spec.rb
index 3dc040fabe..62f050346e 100644
--- a/spec/ruby/library/date/friday_spec.rb
+++ b/spec/ruby/library/date/friday_spec.rb
@@ -3,10 +3,10 @@ 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 c3d25cf90f..c27890faf4 100644
--- a/spec/ruby/library/date/gregorian_leap_spec.rb
+++ b/spec/ruby/library/date/gregorian_leap_spec.rb
@@ -3,13 +3,13 @@ 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 ea7ece2ade..bbda13af08 100644
--- a/spec/ruby/library/date/gregorian_spec.rb
+++ b/spec/ruby/library/date/gregorian_spec.rb
@@ -4,13 +4,13 @@ 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).should.gregorian?
- Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).gregorian?.should be_true
+ Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).gregorian?.should == true
end
end
diff --git a/spec/ruby/library/date/iso8601_spec.rb b/spec/ruby/library/date/iso8601_spec.rb
index a29652014e..26815bd76c 100644
--- a/spec/ruby/library/date/iso8601_spec.rb
+++ b/spec/ruby/library/date/iso8601_spec.rb
@@ -22,8 +22,20 @@ describe "Date.iso8601" do
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_error(TypeError)
+ -> { Date.iso8601(Object.new) }.should.raise(TypeError)
end
end
@@ -32,4 +44,13 @@ describe "Date._iso8601" 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/julian_leap_spec.rb b/spec/ruby/library/date/julian_leap_spec.rb
index 2ef2d65d81..42231e012f 100644
--- a/spec/ruby/library/date/julian_leap_spec.rb
+++ b/spec/ruby/library/date/julian_leap_spec.rb
@@ -3,13 +3,13 @@ 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 db2629d1e7..9f8a670899 100644
--- a/spec/ruby/library/date/julian_spec.rb
+++ b/spec/ruby/library/date/julian_spec.rb
@@ -5,12 +5,12 @@ describe "Date#julian?" do
it "marks a day before the calendar reform as Julian" do
Date.civil(1007, 2, 27).should.julian?
- Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).julian?.should be_true
+ 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).should_not.julian?
- Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).julian?.should be_false
+ Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).julian?.should == false
end
end
diff --git a/spec/ruby/library/date/minus_month_spec.rb b/spec/ruby/library/date/minus_month_spec.rb
index 470c4d8a76..d56e19dc31 100644
--- a/spec/ruby/library/date/minus_month_spec.rb
+++ b/spec/ruby/library/date/minus_month_spec.rb
@@ -14,10 +14,10 @@ describe "Date#<<" do
end
it "raises an error on non numeric parameters" do
- -> { Date.civil(2007,2,27) << :hello }.should raise_error(TypeError)
- -> { Date.civil(2007,2,27) << "hello" }.should raise_error(TypeError)
- -> { Date.civil(2007,2,27) << Date.new }.should raise_error(TypeError)
- -> { 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) << 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 5a2a29e04a..c2a08fa5b0 100644
--- a/spec/ruby/library/date/minus_spec.rb
+++ b/spec/ruby/library/date/minus_spec.rb
@@ -22,9 +22,9 @@ describe "Date#-" do
end
it "raises an error for non Numeric arguments" do
- -> { Date.civil(2007,2,27) - :hello }.should raise_error(TypeError)
- -> { Date.civil(2007,2,27) - "hello" }.should raise_error(TypeError)
- -> { 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/mon_spec.rb b/spec/ruby/library/date/mon_spec.rb
index 724e7d6564..616d72cf88 100644
--- a/spec/ruby/library/date/mon_spec.rb
+++ b/spec/ruby/library/date/mon_spec.rb
@@ -1,6 +1,7 @@
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 14a117b73c..61d728f3c5 100644
--- a/spec/ruby/library/date/monday_spec.rb
+++ b/spec/ruby/library/date/monday_spec.rb
@@ -3,6 +3,6 @@ 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 e040f9a94c..f493ec8119 100644
--- a/spec/ruby/library/date/month_spec.rb
+++ b/spec/ruby/library/date/month_spec.rb
@@ -1,9 +1,7 @@
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 18120118c0..cb64cabce6 100644
--- a/spec/ruby/library/date/new_spec.rb
+++ b/spec/ruby/library/date/new_spec.rb
@@ -1,7 +1,6 @@
require 'date'
require_relative '../../spec_helper'
require_relative 'shared/civil'
-require_relative 'shared/new_bang'
describe "Date.new" do
it_behaves_like :date_civil, :new
diff --git a/spec/ruby/library/date/parse_spec.rb b/spec/ruby/library/date/parse_spec.rb
index bfbe86fbac..4d655f516e 100644
--- a/spec/ruby/library/date/parse_spec.rb
+++ b/spec/ruby/library/date/parse_spec.rb
@@ -23,7 +23,7 @@ describe "Date#parse" do
# Specs using numbers
it "throws an argument error for a single digit" do
- ->{ Date.parse("1") }.should raise_error(ArgumentError)
+ ->{ Date.parse("1") }.should.raise(ArgumentError)
end
it "parses DD as month day number" do
@@ -66,8 +66,8 @@ describe "Date#parse" do
end
it "raises a TypeError trying to parse non-String-like object" do
- -> { Date.parse(1) }.should raise_error(TypeError)
- -> { Date.parse([]) }.should raise_error(TypeError)
+ -> { Date.parse(1) }.should.raise(TypeError)
+ -> { Date.parse([]) }.should.raise(TypeError)
end
it "coerces using to_str" do
@@ -93,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
@@ -101,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
@@ -109,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
@@ -117,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
@@ -125,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 0cb99fd4ca..6179370fca 100644
--- a/spec/ruby/library/date/plus_spec.rb
+++ b/spec/ruby/library/date/plus_spec.rb
@@ -15,6 +15,6 @@ describe "Date#+" do
end
it "raises TypeError if argument is not Numeric" do
- -> { Date.today + Date.today }.should raise_error(TypeError)
+ -> { Date.today + Date.today }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/date/saturday_spec.rb b/spec/ruby/library/date/saturday_spec.rb
index 1527b71d00..29f8267a2b 100644
--- a/spec/ruby/library/date/saturday_spec.rb
+++ b/spec/ruby/library/date/saturday_spec.rb
@@ -3,6 +3,6 @@ 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 bbed4a8866..4499cdf8e9 100644
--- a/spec/ruby/library/date/shared/civil.rb
+++ b/spec/ruby/library/date/shared/civil.rb
@@ -36,14 +36,14 @@ describe :date_civil, shared: true do
end
it "doesn't create dates for invalid arguments" do
- -> { Date.send(@method, 2000, 13, 31) }.should raise_error(ArgumentError)
- -> { Date.send(@method, 2000, 12, 32) }.should raise_error(ArgumentError)
- -> { Date.send(@method, 2000, 2, 30) }.should raise_error(ArgumentError)
- -> { Date.send(@method, 1900, 2, 29) }.should raise_error(ArgumentError)
- -> { Date.send(@method, 2000, 2, 29) }.should_not raise_error(ArgumentError)
-
- -> { Date.send(@method, 1582, 10, 14) }.should raise_error(ArgumentError)
- -> { 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 39c9af47b6..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
- -> { Date.send(@method, 2004, 53, 1) }.should_not raise_error(ArgumentError)
- -> { Date.send(@method, 2004, 53, 0) }.should raise_error(ArgumentError)
- -> { Date.send(@method, 2004, 53, 8) }.should raise_error(ArgumentError)
- -> { Date.send(@method, 2004, 54, 1) }.should raise_error(ArgumentError)
- -> { 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)
- -> { Date.send(@method, 2003, 52, 1) }.should_not raise_error(ArgumentError)
- -> { Date.send(@method, 2003, 53, 1) }.should raise_error(ArgumentError)
- -> { Date.send(@method, 2003, 52, 0) }.should raise_error(ArgumentError)
- -> { 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 e474dfb450..0c01710208 100644
--- a/spec/ruby/library/date/shared/valid_jd.rb
+++ b/spec/ruby/library/date/shared/valid_jd.rb
@@ -1,20 +1,20 @@
describe :date_valid_jd?, shared: true do
it "returns true if passed a number value" do
- Date.send(@method, -100).should be_true
- Date.send(@method, 100.0).should be_true
- Date.send(@method, 2**100).should be_true
- Date.send(@method, Rational(1,2)).should be_true
+ 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 false if passed symbol" do
- Date.send(@method, :number).should be_false
+ Date.send(@method, :number).should == false
end
it "returns false if passed false" do
- Date.send(@method, false).should be_false
+ Date.send(@method, false).should == false
end
end
diff --git a/spec/ruby/library/date/strftime_spec.rb b/spec/ruby/library/date/strftime_spec.rb
index 8b1ebe061c..1b93a8d1b2 100644
--- a/spec/ruby/library/date/strftime_spec.rb
+++ b/spec/ruby/library/date/strftime_spec.rb
@@ -1,5 +1,7 @@
+require_relative "../../spec_helper"
require 'date'
require_relative '../../shared/time/strftime_for_date'
+date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
describe "Date#strftime" do
before :all do
@@ -21,19 +23,9 @@ describe "Date#strftime" do
@date.strftime("%Z").should == "+00:00"
end
- # %v is %e-%b-%Y for Date/DateTime
- ruby_version_is ""..."3.1" do
- 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')
- end
- end
-
- ruby_version_is "3.1" do
- 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')
- end
+ 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')
end
# additional conversion specifiers only in Date/DateTime
diff --git a/spec/ruby/library/date/sunday_spec.rb b/spec/ruby/library/date/sunday_spec.rb
index c3a817fa86..548f36a4f0 100644
--- a/spec/ruby/library/date/sunday_spec.rb
+++ b/spec/ruby/library/date/sunday_spec.rb
@@ -3,6 +3,6 @@ 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 74b5f40365..4df3b9103a 100644
--- a/spec/ruby/library/date/thursday_spec.rb
+++ b/spec/ruby/library/date/thursday_spec.rb
@@ -3,6 +3,6 @@ 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/today_spec.rb b/spec/ruby/library/date/today_spec.rb
index 7c6ebc9cb4..4be8d8e931 100644
--- a/spec/ruby/library/date/today_spec.rb
+++ b/spec/ruby/library/date/today_spec.rb
@@ -3,7 +3,7 @@ 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 052837b54e..db31387aed 100644
--- a/spec/ruby/library/date/tuesday_spec.rb
+++ b/spec/ruby/library/date/tuesday_spec.rb
@@ -3,6 +3,6 @@ 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/wednesday_spec.rb b/spec/ruby/library/date/wednesday_spec.rb
index e80ec23dd2..4bbeead5b8 100644
--- a/spec/ruby/library/date/wednesday_spec.rb
+++ b/spec/ruby/library/date/wednesday_spec.rb
@@ -3,6 +3,6 @@ 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 cfb174a4c2..7dd42e52a5 100644
--- a/spec/ruby/library/date/yday_spec.rb
+++ b/spec/ruby/library/date/yday_spec.rb
@@ -1,6 +1,7 @@
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