diff options
Diffstat (limited to 'spec/ruby/core/time/shared')
| -rw-r--r-- | spec/ruby/core/time/shared/asctime.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/day.rb | 15 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/getgm.rb | 9 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/gm.rb | 70 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/gmt_offset.rb | 59 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/gmtime.rb | 33 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/inspect.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/isdst.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/local.rb | 11 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/month.rb | 15 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/now.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/time_params.rb | 41 | ||||
| -rw-r--r-- | spec/ruby/core/time/shared/to_i.rb | 16 |
13 files changed, 32 insertions, 257 deletions
diff --git a/spec/ruby/core/time/shared/asctime.rb b/spec/ruby/core/time/shared/asctime.rb deleted file mode 100644 index d096666863..0000000000 --- a/spec/ruby/core/time/shared/asctime.rb +++ /dev/null @@ -1,6 +0,0 @@ -describe :time_asctime, shared: true do - it "returns a canonical string representation of time" do - t = Time.now - t.send(@method).should == t.strftime("%a %b %e %H:%M:%S %Y") - end -end diff --git a/spec/ruby/core/time/shared/day.rb b/spec/ruby/core/time/shared/day.rb deleted file mode 100644 index 472dc959c1..0000000000 --- a/spec/ruby/core/time/shared/day.rb +++ /dev/null @@ -1,15 +0,0 @@ -describe :time_day, shared: true do - it "returns the day of the month (1..n) for a local Time" do - with_timezone("CET", 1) do - Time.local(1970, 1, 1).send(@method).should == 1 - end - end - - it "returns the day of the month for a UTC Time" do - Time.utc(1970, 1, 1).send(@method).should == 1 - end - - it "returns the day of the month for a Time with a fixed offset" do - Time.new(2012, 1, 1, 0, 0, 0, -3600).send(@method).should == 1 - end -end diff --git a/spec/ruby/core/time/shared/getgm.rb b/spec/ruby/core/time/shared/getgm.rb deleted file mode 100644 index 3576365772..0000000000 --- a/spec/ruby/core/time/shared/getgm.rb +++ /dev/null @@ -1,9 +0,0 @@ -describe :time_getgm, shared: true do - it "returns a new time which is the utc representation of time" do - # Testing with America/Regina here because it doesn't have DST. - with_timezone("CST", -6) do - t = Time.local(2007, 1, 9, 6, 0, 0) - t.send(@method).should == Time.gm(2007, 1, 9, 12, 0, 0) - end - end -end diff --git a/spec/ruby/core/time/shared/gm.rb b/spec/ruby/core/time/shared/gm.rb deleted file mode 100644 index 0ee602c837..0000000000 --- a/spec/ruby/core/time/shared/gm.rb +++ /dev/null @@ -1,70 +0,0 @@ -describe :time_gm, shared: true do - it "creates a time based on given values, interpreted as UTC (GMT)" do - Time.send(@method, 2000,"jan",1,20,15,1).inspect.should == "2000-01-01 20:15:01 UTC" - end - - it "creates a time based on given C-style gmtime arguments, interpreted as UTC (GMT)" do - time = Time.send(@method, 1, 15, 20, 1, 1, 2000, :ignored, :ignored, :ignored, :ignored) - time.inspect.should == "2000-01-01 20:15:01 UTC" - end - - it "interprets pre-Gregorian reform dates using Gregorian proleptic calendar" do - Time.send(@method, 1582, 10, 4, 12).to_i.should == -12220200000 # 2299150j - end - - it "interprets Julian-Gregorian gap dates using Gregorian proleptic calendar" do - Time.send(@method, 1582, 10, 14, 12).to_i.should == -12219336000 # 2299160j - end - - it "interprets post-Gregorian reform dates using Gregorian calendar" do - Time.send(@method, 1582, 10, 15, 12).to_i.should == -12219249600 # 2299161j - end - - it "handles fractional usec close to rounding limit" do - time = Time.send(@method, 2000, 1, 1, 12, 30, 0, 9999r/10000) - - time.usec.should == 0 - time.nsec.should == 999 - end - - guard -> { - with_timezone 'right/UTC' do - (Time.gm(1972, 6, 30, 23, 59, 59) + 1).sec == 60 - end - } do - it "handles real leap seconds in zone 'right/UTC'" do - with_timezone 'right/UTC' do - time = Time.send(@method, 1972, 6, 30, 23, 59, 60) - - time.sec.should == 60 - time.min.should == 59 - time.hour.should == 23 - time.day.should == 30 - time.month.should == 6 - end - end - end - - it "handles bad leap seconds by carrying values forward" do - with_timezone 'UTC' do - time = Time.send(@method, 2017, 7, 5, 23, 59, 60) - time.sec.should == 0 - time.min.should == 0 - time.hour.should == 0 - time.day.should == 6 - time.month.should == 7 - end - end - - it "handles a value of 60 for seconds by carrying values forward in zone 'UTC'" do - with_timezone 'UTC' do - time = Time.send(@method, 1972, 6, 30, 23, 59, 60) - - time.sec.should == 0 - time.min.should == 0 - time.hour.should == 0 - time.day.should == 1 - time.month.should == 7 - end - end -end diff --git a/spec/ruby/core/time/shared/gmt_offset.rb b/spec/ruby/core/time/shared/gmt_offset.rb deleted file mode 100644 index 839566c249..0000000000 --- a/spec/ruby/core/time/shared/gmt_offset.rb +++ /dev/null @@ -1,59 +0,0 @@ -describe :time_gmt_offset, shared: true do - it "returns the offset in seconds between the timezone of time and UTC" do - with_timezone("AST", 3) do - Time.new.send(@method).should == 10800 - end - end - - it "returns 0 when the date is UTC" do - with_timezone("AST", 3) do - Time.new.utc.send(@method).should == 0 - end - end - - platform_is_not :windows do - it "returns the correct offset for US Eastern time zone around daylight savings time change" do - # "2010-03-14 01:59:59 -0500" + 1 ==> "2010-03-14 03:00:00 -0400" - with_timezone("EST5EDT") do - t = Time.local(2010,3,14,1,59,59) - t.send(@method).should == -5*60*60 - (t + 1).send(@method).should == -4*60*60 - end - end - - it "returns the correct offset for Hawaii around daylight savings time change" do - # "2010-03-14 01:59:59 -1000" + 1 ==> "2010-03-14 02:00:00 -1000" - with_timezone("Pacific/Honolulu") do - t = Time.local(2010,3,14,1,59,59) - t.send(@method).should == -10*60*60 - (t + 1).send(@method).should == -10*60*60 - end - end - - it "returns the correct offset for New Zealand around daylight savings time change" do - # "2010-04-04 02:59:59 +1300" + 1 ==> "2010-04-04 02:00:00 +1200" - with_timezone("Pacific/Auckland") do - t = Time.local(2010,4,4,1,59,59) + (60 * 60) - t.send(@method).should == 13*60*60 - (t + 1).send(@method).should == 12*60*60 - end - end - end - - it "returns offset as Rational" do - Time.new(2010,4,4,1,59,59,7245).send(@method).should == 7245 - Time.new(2010,4,4,1,59,59,7245.5).send(@method).should == Rational(14491,2) - end - - context 'given positive offset' do - it 'returns a positive offset' do - Time.new(2013,3,17,nil,nil,nil,"+03:00").send(@method).should == 10800 - end - end - - context 'given negative offset' do - it 'returns a negative offset' do - Time.new(2013,3,17,nil,nil,nil,"-03:00").send(@method).should == -10800 - end - end -end diff --git a/spec/ruby/core/time/shared/gmtime.rb b/spec/ruby/core/time/shared/gmtime.rb deleted file mode 100644 index 5ed64c2ab6..0000000000 --- a/spec/ruby/core/time/shared/gmtime.rb +++ /dev/null @@ -1,33 +0,0 @@ -describe :time_gmtime, shared: true do - it "converts self to UTC, modifying the receiver" do - # Testing with America/Regina here because it doesn't have DST. - with_timezone("CST", -6) do - t = Time.local(2007, 1, 9, 6, 0, 0) - t.send(@method) - t.should == Time.gm(2007, 1, 9, 12, 0, 0) - end - end - - it "returns self" do - with_timezone("CST", -6) do - t = Time.local(2007, 1, 9, 12, 0, 0) - t.send(@method).should equal(t) - end - end - - describe "on a frozen time" do - it "does not raise an error if already in UTC" do - time = Time.gm(2007, 1, 9, 12, 0, 0) - time.freeze - time.send(@method).should equal(time) - end - - it "raises a RuntimeError if the time is not UTC" do - with_timezone("CST", -6) do - time = Time.now - time.freeze - -> { time.send(@method) }.should raise_error(RuntimeError) - end - end - end -end diff --git a/spec/ruby/core/time/shared/inspect.rb b/spec/ruby/core/time/shared/inspect.rb index 4133671924..82f7f3c686 100644 --- a/spec/ruby/core/time/shared/inspect.rb +++ b/spec/ruby/core/time/shared/inspect.rb @@ -16,6 +16,6 @@ describe :inspect, shared: true do end it "returns a US-ASCII encoded string" do - Time.now.send(@method).encoding.should equal(Encoding::US_ASCII) + Time.now.send(@method).encoding.should.equal?(Encoding::US_ASCII) end end diff --git a/spec/ruby/core/time/shared/isdst.rb b/spec/ruby/core/time/shared/isdst.rb deleted file mode 100644 index bc6d139230..0000000000 --- a/spec/ruby/core/time/shared/isdst.rb +++ /dev/null @@ -1,8 +0,0 @@ -describe :time_isdst, shared: true do - it "dst? returns whether time is during daylight saving time" do - with_timezone("America/Los_Angeles") do - Time.local(2007, 9, 9, 0, 0, 0).send(@method).should == true - Time.local(2007, 1, 9, 0, 0, 0).send(@method).should == false - end - end -end diff --git a/spec/ruby/core/time/shared/local.rb b/spec/ruby/core/time/shared/local.rb index 43f331c4c1..068e314999 100644 --- a/spec/ruby/core/time/shared/local.rb +++ b/spec/ruby/core/time/shared/local.rb @@ -7,12 +7,10 @@ describe :time_local, shared: true do end platform_is_not :windows do - describe "timezone changes" do - it "correctly adjusts the timezone change to 'CEST' on 'Europe/Amsterdam'" do - with_timezone("Europe/Amsterdam") do - Time.send(@method, 1940, 5, 16).to_a.should == - [0, 40, 1, 16, 5, 1940, 4, 137, true, "CEST"] - end + it "uses the 'CET' timezone with TZ=Europe/Amsterdam in 1970" do + with_timezone("Europe/Amsterdam") do + Time.send(@method, 1970, 5, 16).to_a.should == + [0, 0, 0, 16, 5, 1970, 6, 136, false, "CET"] end end end @@ -41,5 +39,4 @@ describe :time_local_10_arg, shared: true do end end end - end diff --git a/spec/ruby/core/time/shared/month.rb b/spec/ruby/core/time/shared/month.rb deleted file mode 100644 index 31ca679557..0000000000 --- a/spec/ruby/core/time/shared/month.rb +++ /dev/null @@ -1,15 +0,0 @@ -describe :time_month, shared: true do - it "returns the month of the year for a local Time" do - with_timezone("CET", 1) do - Time.local(1970, 1).send(@method).should == 1 - end - end - - it "returns the month of the year for a UTC Time" do - Time.utc(1970, 1).send(@method).should == 1 - end - - it "returns the four digit year for a Time with a fixed offset" do - Time.new(2012, 1, 1, 0, 0, 0, -3600).send(@method).should == 1 - end -end diff --git a/spec/ruby/core/time/shared/now.rb b/spec/ruby/core/time/shared/now.rb index f4018d72f4..839cfdcd2a 100644 --- a/spec/ruby/core/time/shared/now.rb +++ b/spec/ruby/core/time/shared/now.rb @@ -2,8 +2,8 @@ require_relative '../fixtures/classes' describe :time_now, shared: true do it "creates a subclass instance if called on a subclass" do - TimeSpecs::SubTime.send(@method).should be_an_instance_of(TimeSpecs::SubTime) - TimeSpecs::MethodHolder.send(@method).should be_an_instance_of(Time) + TimeSpecs::SubTime.send(@method).should.instance_of?(TimeSpecs::SubTime) + TimeSpecs::MethodHolder.send(@method).should.instance_of?(Time) end it "sets the current time" do diff --git a/spec/ruby/core/time/shared/time_params.rb b/spec/ruby/core/time/shared/time_params.rb index 63d0dbc120..f0de986b8e 100644 --- a/spec/ruby/core/time/shared/time_params.rb +++ b/spec/ruby/core/time/shared/time_params.rb @@ -30,7 +30,7 @@ describe :time_params, shared: true do end it "raises a TypeError if the year is nil" do - -> { Time.send(@method, nil) }.should raise_error(TypeError) + -> { Time.send(@method, nil) }.should.raise(TypeError) end it "accepts nil month, day, hour, minute, and second" do @@ -145,46 +145,55 @@ describe :time_params, shared: true do end it "raises an ArgumentError for out of range month" do + # For some reason MRI uses a different message for month in 13-15 and month>=16 -> { - Time.send(@method, 2008, 13, 31, 23, 59, 59) - }.should raise_error(ArgumentError) + Time.send(@method, 2008, 16, 31, 23, 59, 59) + }.should.raise(ArgumentError, /(mon|argument) out of range/) end it "raises an ArgumentError for out of range day" do -> { Time.send(@method, 2008, 12, 32, 23, 59, 59) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises an ArgumentError for out of range hour" do -> { Time.send(@method, 2008, 12, 31, 25, 59, 59) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises an ArgumentError for out of range minute" do -> { Time.send(@method, 2008, 12, 31, 23, 61, 59) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "raises an ArgumentError for out of range second" do + # For some reason MRI uses different messages for seconds 61-63 and seconds >= 64 -> { Time.send(@method, 2008, 12, 31, 23, 59, 61) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, /(sec|argument) out of range/) + -> { + Time.send(@method, 2008, 12, 31, 23, 59, -1) + }.should.raise(ArgumentError, "argument out of range") + end + + it "raises ArgumentError when given 8 arguments" do + -> { Time.send(@method, *[0]*8) }.should.raise(ArgumentError) end it "raises ArgumentError when given 9 arguments" do - -> { Time.send(@method, *[0]*9) }.should raise_error(ArgumentError) + -> { Time.send(@method, *[0]*9) }.should.raise(ArgumentError) end it "raises ArgumentError when given 11 arguments" do - -> { Time.send(@method, *[0]*11) }.should raise_error(ArgumentError) + -> { Time.send(@method, *[0]*11) }.should.raise(ArgumentError) end it "returns subclass instances" do c = Class.new(Time) - c.send(@method, 2008, "12").should be_an_instance_of(c) + c.send(@method, 2008, "12").should.instance_of?(c) end end @@ -204,23 +213,23 @@ describe :time_params_10_arg, shared: true do it "raises an ArgumentError for out of range values" do -> { Time.send(@method, 61, 59, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored) - }.should raise_error(ArgumentError) # sec + }.should.raise(ArgumentError) # sec -> { Time.send(@method, 59, 61, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored) - }.should raise_error(ArgumentError) # min + }.should.raise(ArgumentError) # min -> { Time.send(@method, 59, 59, 25, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored) - }.should raise_error(ArgumentError) # hour + }.should.raise(ArgumentError) # hour -> { Time.send(@method, 59, 59, 23, 32, 12, 2008, :ignored, :ignored, :ignored, :ignored) - }.should raise_error(ArgumentError) # day + }.should.raise(ArgumentError) # day -> { Time.send(@method, 59, 59, 23, 31, 13, 2008, :ignored, :ignored, :ignored, :ignored) - }.should raise_error(ArgumentError) # month + }.should.raise(ArgumentError) # month end end @@ -231,7 +240,7 @@ describe :time_params_microseconds, shared: true do end it "raises an ArgumentError for out of range microsecond" do - -> { Time.send(@method, 2000, 1, 1, 20, 15, 1, 1000000) }.should raise_error(ArgumentError) + -> { Time.send(@method, 2000, 1, 1, 20, 15, 1, 1000000) }.should.raise(ArgumentError) end it "handles fractional microseconds as a Float" do diff --git a/spec/ruby/core/time/shared/to_i.rb b/spec/ruby/core/time/shared/to_i.rb deleted file mode 100644 index 06c966b708..0000000000 --- a/spec/ruby/core/time/shared/to_i.rb +++ /dev/null @@ -1,16 +0,0 @@ -describe :time_to_i, shared: true do - it "returns the value of time as an integer number of seconds since epoch" do - Time.at(0).send(@method).should == 0 - end - - it "doesn't return an actual number of seconds in time" do - Time.at(65.5).send(@method).should == 65 - end - - it "rounds fractional seconds toward zero" do - t = Time.utc(1960, 1, 1, 0, 0, 0, 999_999) - - t.to_f.to_i.should == -315619199 - t.to_i.should == -315619200 - end -end |
