require_relative '../../spec_helper'
require_relative 'shared/inspect'

describe "Time#inspect" do
  it_behaves_like :inspect, :inspect

  ruby_version_is "2.7" do
    it "preserves microseconds" do
      t = Time.utc(2007, 11, 1, 15, 25, 0, 123456)
      t.inspect.should == "2007-11-01 15:25:00.123456 UTC"
    end

    it "preserves nanoseconds" do
      t = Time.utc(2007, 11, 1, 15, 25, 0, 123456.789r)
      t.inspect.should == "2007-11-01 15:25:00.123456789 UTC"
    end

    it "formats nanoseconds as a Rational" do
      t = Time.utc(2007, 11, 1, 15, 25, 0, 123456.789)
      t.nsec.should == 123456789
      t.strftime("%N").should == "123456789"

      t.inspect.should == "2007-11-01 15:25:00 8483885939586761/68719476736000000 UTC"
    end
  end
end

require_relative '../../spec_helper'
require_relative 'shared/inspect'

describe "Time#inspect" do
  it_behaves_like :inspect, :inspect

  ruby_version_is "2.7" do
    it "preserves microseconds" do
      t = Time.utc(2007, 11, 1, 15, 25, 0, 123456)
      t.inspect.should == "2007-11-01 15:25:00.123456 UTC"
    end

    it "preserves nanoseconds" do
      t = Time.utc(2007, 11, 1, 15, 25, 0, 123456.789r)
      t.inspect.should == "2007-11-01 15:25:00.123456789 UTC"
    end
  end
end

Remove implementation-specific test for inspecting sub-nanosecond times
Remove implementation-specific test for inspecting sub-nanosecond times

This doesn’t look like a sub-nanosecond time (123456.789 milliseconds is
exactly 123456789 nanoseconds) but the representation error in the IEEE
754 double-precision float used by MRI means that the fractional part of
the time is actually 0.123456789000000004307366907596588134765625
seconds, which then gets displayed as the rational number
8483885939586761/68719476736000000.

In a related Redmine discussion [0], Jeremy Evans said:

> Note that sub-nanosecond resolution should be considered
> Ruby-implementation-specific behavior, since JRuby and TruffleRuby
> support nanosecond, and mruby supports microsecond.

ruby/spec doesn’t cover implementation-specific behaviour, so this test
should be removed.

[0] https://bugs.ruby-lang.org/issues/16470
