Skip to content

Commit

Permalink
Add specs: Time.new accepts in keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
ohbarye committed Oct 9, 2022
1 parent fe751cb commit 6b1c28a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions core/time/now_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,49 @@

describe "Time.now" do
it_behaves_like :time_now, :now

describe ":in keyword argument" do
it "could be UTC offset as a String in '+HH:MM or '-HH:MM' format" do
time = Time.now(in: "+05:00")

time.utc_offset.should == 5*60*60
time.zone.should == nil

time = Time.now(in: "-09:00")

time.utc_offset.should == -9*60*60
time.zone.should == nil
end

it "could be UTC offset as a number of seconds" do
time = Time.now(in: 5*60*60)

time.utc_offset.should == 5*60*60
time.zone.should == nil

time = Time.now(in: -9*60*60)

time.utc_offset.should == -9*60*60
time.zone.should == nil
end

it "could be a timezone object" do
zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo")
time = Time.now(in: zone)

time.utc_offset.should == 5*3600+30*60
time.zone.should == zone

zone = TimeSpecs::TimezoneWithName.new(name: "PST")
time = Time.now(in: zone)

time.utc_offset.should == -9*60*60
time.zone.should == zone
end

it "raises ArgumentError if format is invalid" do
-> { Time.now(in: "+09:99") }.should raise_error(ArgumentError)
-> { Time.now(in: "ABC") }.should raise_error(ArgumentError)
end
end
end

0 comments on commit 6b1c28a

Please sign in to comment.