summaryrefslogtreecommitdiff
path: root/spec/ruby/core/time/getlocal_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/time/getlocal_spec.rb')
-rw-r--r--spec/ruby/core/time/getlocal_spec.rb73
1 files changed, 27 insertions, 46 deletions
diff --git a/spec/ruby/core/time/getlocal_spec.rb b/spec/ruby/core/time/getlocal_spec.rb
index ff3e3d8dd1..7e5334c303 100644
--- a/spec/ruby/core/time/getlocal_spec.rb
+++ b/spec/ruby/core/time/getlocal_spec.rb
@@ -14,6 +14,7 @@ describe "Time#getlocal" do
t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal(3630)
t.should == Time.new(2007, 1, 9, 13, 0, 30, 3630)
t.utc_offset.should == 3630
+ t.zone.should == nil
end
platform_is_not :windows do
@@ -40,7 +41,7 @@ describe "Time#getlocal" do
it "returns a Time with a UTC offset of the specified number of Rational seconds" do
t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal(Rational(7201, 2))
t.should == Time.new(2007, 1, 9, 13, 0, Rational(1, 2), Rational(7201, 2))
- t.utc_offset.should eql(Rational(7201, 2))
+ t.utc_offset.should.eql?(Rational(7201, 2))
end
describe "with an argument that responds to #to_r" do
@@ -49,7 +50,7 @@ describe "Time#getlocal" do
o.should_receive(:to_r).and_return(Rational(7201, 2))
t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal(o)
t.should == Time.new(2007, 1, 9, 13, 0, Rational(1, 2), Rational(7201, 2))
- t.utc_offset.should eql(Rational(7201, 2))
+ t.utc_offset.should.eql?(Rational(7201, 2))
end
end
@@ -89,69 +90,49 @@ describe "Time#getlocal" do
it "raises ArgumentError if the String argument is not of the form (+|-)HH:MM" do
t = Time.now
- -> { t.getlocal("3600") }.should raise_error(ArgumentError)
+ -> { t.getlocal("3600") }.should.raise(ArgumentError)
end
it "raises ArgumentError if the String argument is not in an ASCII-compatible encoding" do
t = Time.now
- -> { t.getlocal("-01:00".encode("UTF-16LE")) }.should raise_error(ArgumentError)
+ -> { t.getlocal("-01:00".encode("UTF-16LE")) }.should.raise(ArgumentError)
end
it "raises ArgumentError if the argument represents a value less than or equal to -86400 seconds" do
t = Time.new
t.getlocal(-86400 + 1).utc_offset.should == (-86400 + 1)
- -> { t.getlocal(-86400) }.should raise_error(ArgumentError)
+ -> { t.getlocal(-86400) }.should.raise(ArgumentError)
end
it "raises ArgumentError if the argument represents a value greater than or equal to 86400 seconds" do
t = Time.new
t.getlocal(86400 - 1).utc_offset.should == (86400 - 1)
- -> { t.getlocal(86400) }.should raise_error(ArgumentError)
+ -> { t.getlocal(86400) }.should.raise(ArgumentError)
end
it "raises ArgumentError if String argument and hours greater than 23" do
- ruby_version_is ""..."3.1" do
- -> { Time.now.getlocal("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range")
- -> { Time.now.getlocal("+2400") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
+ -> { Time.now.getlocal("+24:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.now.getlocal("+2400") }.should.raise(ArgumentError, "utc_offset out of range")
- -> { Time.now.getlocal("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range")
- -> { Time.now.getlocal("+9900") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
- end
-
- ruby_version_is "3.1" do
- -> { Time.now.getlocal("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range")
- -> { Time.now.getlocal("+2400") }.should raise_error(ArgumentError, "utc_offset out of range")
-
- -> { Time.now.getlocal("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range")
- -> { Time.now.getlocal("+9900") }.should raise_error(ArgumentError, "utc_offset out of range")
- end
+ -> { Time.now.getlocal("+99:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.now.getlocal("+9900") }.should.raise(ArgumentError, "utc_offset out of range")
end
it "raises ArgumentError if String argument and minutes greater than 59" do
- ruby_version_is ""..."3.1" do
- -> { Time.now.getlocal("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
- -> { Time.now.getlocal("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
+ -> { Time.now.getlocal("+00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
+ -> { Time.now.getlocal("+0060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')
- -> { Time.now.getlocal("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
- -> { Time.now.getlocal("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
- end
-
- ruby_version_is "3.1" do
- -> { Time.now.getlocal("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
- -> { Time.now.getlocal("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')
-
- -> { Time.now.getlocal("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
- -> { Time.now.getlocal("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
- end
+ -> { Time.now.getlocal("+00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
+ -> { Time.now.getlocal("+0099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
end
ruby_bug '#20797', ''...'3.4' do
it "raises ArgumentError if String argument and seconds greater than 59" do
- -> { Time.now.getlocal("+00:00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
- -> { Time.now.getlocal("+000060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')
+ -> { Time.now.getlocal("+00:00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
+ -> { Time.now.getlocal("+000060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')
- -> { Time.now.getlocal("+00:00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
- -> { Time.now.getlocal("+000099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
+ -> { Time.now.getlocal("+00:00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
+ -> { Time.now.getlocal("+000099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
end
end
@@ -174,8 +155,8 @@ describe "Time#getlocal" do
end
-> {
- Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should be_kind_of(Time)
- }.should_not raise_error
+ Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should.is_a?(Time)
+ }.should_not.raise
end
it "raises TypeError if timezone does not implement #utc_to_local method" do
@@ -186,7 +167,7 @@ describe "Time#getlocal" do
-> {
Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone)
- }.should raise_error(TypeError, /can't convert \w+ into an exact number/)
+ }.should.raise(TypeError, /can't convert \w+ into an exact number/)
end
it "does not raise exception if timezone does not implement #local_to_utc method" do
@@ -196,18 +177,18 @@ describe "Time#getlocal" do
end
-> {
- Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should be_kind_of(Time)
- }.should_not raise_error
+ Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should.is_a?(Time)
+ }.should_not.raise
end
context "subject's class implements .find_timezone method" do
it "calls .find_timezone to build a time object if passed zone name as a timezone argument" do
time = TimeSpecs::TimeWithFindTimezone.utc(2000, 1, 1, 12, 0, 0).getlocal("Asia/Colombo")
- time.zone.should be_kind_of TimeSpecs::TimezoneWithName
+ time.zone.should.is_a? TimeSpecs::TimezoneWithName
time.zone.name.should == "Asia/Colombo"
time = TimeSpecs::TimeWithFindTimezone.utc(2000, 1, 1, 12, 0, 0).getlocal("some invalid zone name")
- time.zone.should be_kind_of TimeSpecs::TimezoneWithName
+ time.zone.should.is_a? TimeSpecs::TimezoneWithName
time.zone.name.should == "some invalid zone name"
end
@@ -217,7 +198,7 @@ describe "Time#getlocal" do
-> {
time.getlocal(zone)
- }.should raise_error(TypeError, /can't convert \w+ into an exact number/)
+ }.should.raise(TypeError, /can't convert \w+ into an exact number/)
end
end
end