diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-15 17:44:37 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-15 17:44:37 +0000 |
commit | 30ed82e7724093bb3c2015a818c28c3592134bba (patch) | |
tree | 5445b9e26d9ee173fa3735007f3e2b42791d2ec5 /spec/ruby/core/time/at_spec.rb | |
parent | f941bdf263dcc16ea4e6b4576341882b89567c0b (diff) |
Update to ruby/spec@595645f
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/time/at_spec.rb')
-rw-r--r-- | spec/ruby/core/time/at_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/ruby/core/time/at_spec.rb b/spec/ruby/core/time/at_spec.rb index 40c729316e..6883a8d074 100644 --- a/spec/ruby/core/time/at_spec.rb +++ b/spec/ruby/core/time/at_spec.rb @@ -142,4 +142,60 @@ describe "Time.at" do lambda { Time.at(Time.now, 500000) }.should raise_error(TypeError) end end + + ruby_version_is "2.5" do + describe "passed [Time, Numeric, format]" do + context ":nanosecond format" do + it "traits second argument as nanoseconds" do + Time.at(0, 123456789, :nanosecond).nsec.should == 123456789 + end + end + + context ":nsec format" do + it "traits second argument as nanoseconds" do + Time.at(0, 123456789, :nsec).nsec.should == 123456789 + end + end + + context ":microsecond format" do + it "traits second argument as microseconds" do + Time.at(0, 123456, :microsecond).nsec.should == 123456000 + end + end + + context ":usec format" do + it "traits second argument as microseconds" do + Time.at(0, 123456, :usec).nsec.should == 123456000 + end + end + + context ":millisecond format" do + it "traits second argument as milliseconds" do + Time.at(0, 123, :millisecond).nsec.should == 123000000 + end + end + + context "not supported format" do + it "raises ArgumentError" do + ->() { Time.at(0, 123456, 2) }.should raise_error(ArgumentError) + ->() { Time.at(0, 123456, nil) }.should raise_error(ArgumentError) + ->() { Time.at(0, 123456, :invalid) }.should raise_error(ArgumentError) + end + + it "does not try to convert format to Symbol with #to_sym" do + format = "usec" + format.should_not_receive(:to_sym) + -> () { Time.at(0, 123456, format) }.should raise_error(ArgumentError) + end + end + + it "supports Float second argument" do + Time.at(0, 123456789.500, :nanosecond).nsec.should == 123456789 + Time.at(0, 123456789.500, :nsec).nsec.should == 123456789 + Time.at(0, 123456.500, :microsecond).nsec.should == 123456500 + Time.at(0, 123456.500, :usec).nsec.should == 123456500 + Time.at(0, 123.500, :millisecond).nsec.should == 123500000 + end + end + end end |