1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-12-15 17:44:37 +00:00
parent f941bdf263
commit 30ed82e772
39 changed files with 1078 additions and 105 deletions

View file

@ -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