summaryrefslogtreecommitdiff
path: root/spec/ruby/core/time/getlocal_spec.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2021-07-29 22:11:21 +0200
committerBenoit Daloze <eregontp@gmail.com>2021-07-29 22:11:21 +0200
commit6998d758248d778fa95b008c78d05473e48b8428 (patch)
tree8abc6926f647ea5f374a5b34c3a4820c5861e32e /spec/ruby/core/time/getlocal_spec.rb
parent15d05f8120745a121b93fab9fd2addf5f094e8d2 (diff)
Update to ruby/spec@b65d01f
Diffstat (limited to 'spec/ruby/core/time/getlocal_spec.rb')
-rw-r--r--spec/ruby/core/time/getlocal_spec.rb102
1 files changed, 50 insertions, 52 deletions
diff --git a/spec/ruby/core/time/getlocal_spec.rb b/spec/ruby/core/time/getlocal_spec.rb
index 7196577dab..926a6dbf45 100644
--- a/spec/ruby/core/time/getlocal_spec.rb
+++ b/spec/ruby/core/time/getlocal_spec.rb
@@ -97,71 +97,69 @@ describe "Time#getlocal" do
-> { t.getlocal(86400) }.should raise_error(ArgumentError)
end
- ruby_version_is "2.6" do
- describe "with a timezone argument" do
- it "returns a Time in the timezone" do
- zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
- time = Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone)
-
- time.zone.should == zone
- time.utc_offset.should == 5*3600+30*60
- end
+ describe "with a timezone argument" do
+ it "returns a Time in the timezone" do
+ zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
+ time = Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone)
- it "accepts timezone argument that must have #local_to_utc and #utc_to_local methods" do
- zone = Object.new
- def zone.utc_to_local(time)
- time
- end
- def zone.local_to_utc(time)
- time
- end
+ time.zone.should == zone
+ time.utc_offset.should == 5*3600+30*60
+ end
- -> {
- Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should be_kind_of(Time)
- }.should_not raise_error
+ it "accepts timezone argument that must have #local_to_utc and #utc_to_local methods" do
+ zone = Object.new
+ def zone.utc_to_local(time)
+ time
+ end
+ def zone.local_to_utc(time)
+ time
end
- it "raises TypeError if timezone does not implement #utc_to_local method" do
- zone = Object.new
- def zone.local_to_utc(time)
- time
- end
+ -> {
+ Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should be_kind_of(Time)
+ }.should_not raise_error
+ end
- -> {
- Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone)
- }.should raise_error(TypeError, /can't convert \w+ into an exact number/)
+ it "raises TypeError if timezone does not implement #utc_to_local method" do
+ zone = Object.new
+ def zone.local_to_utc(time)
+ time
end
- it "does not raise exception if timezone does not implement #local_to_utc method" do
- zone = Object.new
- def zone.utc_to_local(time)
- time
- end
+ -> {
+ Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone)
+ }.should raise_error(TypeError, /can't convert \w+ into an exact number/)
+ end
- -> {
- Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should be_kind_of(Time)
- }.should_not raise_error
+ it "does not raise exception if timezone does not implement #local_to_utc method" do
+ zone = Object.new
+ def zone.utc_to_local(time)
+ time
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.name.should == "Asia/Colombo"
+ -> {
+ Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should be_kind_of(Time)
+ }.should_not raise_error
+ 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.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.name.should == "some invalid zone name"
- end
+ 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.name.should == "some invalid zone name"
+ end
- it "does not call .find_timezone if passed any not string/numeric/timezone timezone argument" do
- [Object.new, [], {}, :"some zone"].each do |zone|
- time = TimeSpecs::TimeWithFindTimezone.utc(2000, 1, 1, 12, 0, 0)
+ it "does not call .find_timezone if passed any not string/numeric/timezone timezone argument" do
+ [Object.new, [], {}, :"some zone"].each do |zone|
+ time = TimeSpecs::TimeWithFindTimezone.utc(2000, 1, 1, 12, 0, 0)
- -> {
- time.getlocal(zone)
- }.should raise_error(TypeError, /can't convert \w+ into an exact number/)
- end
+ -> {
+ time.getlocal(zone)
+ }.should raise_error(TypeError, /can't convert \w+ into an exact number/)
end
end
end