<commit_before>require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/methods', __FILE__)

describe "Time.at" do
  platform_is_not :windows do
    ruby_version_is '' ... '1.9' do
      it "converts to time object" do
        with_timezone "GMT" do
          # the #chomp calls are necessary because of RSpec
          t = Time.at(1184027924)
          t.inspect.chomp.should == "Tue Jul 10 00:38:44 +0000 2007"
        end
      end
    end

    ruby_version_is '1.9' do
      it "converts to time object" do
        with_timezone "GMT" do
          # the #chomp calls are necessary because of RSpec
          t = Time.at(1184027924)
          t.inspect.chomp.should == "2007-07-10 00:38:44 +0000"
        end
      end
    end
  end

  it "creates a new time object with the value given by time" do
    t = Time.now
    Time.at(t).inspect.should == t.inspect
  end

  it "creates a dup time object with the value given by time" do
    t1 = Time.new
    t2 = Time.at(t1)
    t1.object_id.should_not == t2.object_id
  end

  it "is able to create a time object with a float" do
    t = Time.at(10.5)
    t.usec.should == 500000.0
    t.should_not == Time.at(10)
  end

  it "is able to create a time object with a microseconds" do
    t = Time.at(10, 500000)
    t.usec.should == 500000.0
    t.should_not == Time.at(10)
  end

  it "returns a subclass instance on a Time subclass" do
    c = Class.new(Time)
    t = c.at(0)
    t.should be_kind_of(c)
  end

  it "returns a subclass instance when passed a Time object" do
    c = Class.new(Time)
    t = c.at(Time.now)
    t.should be_kind_of(c)
  end

end<commit_msg>Expand Time.at specs<commit_after>require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/methods', __FILE__)

describe "Time.at" do
  describe "passed Numeric" do
    it "returns a Time object representing the given number of Integer seconds since 1970-01-01 00:00:00 UTC" do
      Time.at(1184027924).getgm.asctime.should == "Tue Jul 10 00:38:44 2007"
    end

    it "returns a Time object representing the given number of Float seconds since 1970-01-01 00:00:00 UTC" do
      t = Time.at(10.5)
      t.usec.should == 500000.0
      t.should_not == Time.at(10)
    end

    it "returns a non-UTC Time" do
      Time.at(1184027924).utc?.should == false
    end

    it "returns a subclass instance on a Time subclass" do
      c = Class.new(Time)
      t = c.at(0)
      t.should be_kind_of(c)
    end
  end

  describe "passed Time" do
    it "creates a new time object with the value given by time" do
      t = Time.now
      Time.at(t).inspect.should == t.inspect
    end

    it "creates a dup time object with the value given by time" do
      t1 = Time.new
      t2 = Time.at(t1)
      t1.object_id.should_not == t2.object_id
    end

    it "returns a UTC time if the argument is UTC" do
      t = Time.now.getgm
      Time.at(t).utc?.should == true
    end

    it "returns a non-UTC time if the argument is non-UTC" do
      t = Time.now
      Time.at(t).utc?.should == false
    end

    it "returns a subclass instance" do
      c = Class.new(Time)
      t = c.at(Time.now)
      t.should be_kind_of(c)
    end
  end

  describe "passed non-Time, non-Numeric" do
    it "raises a TypeError with a String argument" do
      lambda { Time.at("0") }.should raise_error(TypeError)
    end

    it "raises a TypeError with a nil argument" do
      lambda { Time.at(nil) }.should raise_error(TypeError)
    end

    describe "with an argument that responds to #to_int" do
      ruby_version_is ""..."1.9" do
        it "raises a TypeError" do
          o = mock('integer')
          o.should_not_receive(:to_int)
          lambda { Time.at(o) }.should raise_error(TypeError)
        end
      end

      ruby_version_is "1.9" do
        it "coerces using #to_int" do
          o = mock('integer')
          o.should_receive(:to_int).and_return(0)
          Time.at(o).should == Time.at(0)
        end
      end
    end

    describe "with an argument that responds to #to_r" do
      ruby_version_is ""..."1.9" do
        it "raises a TypeError" do
          o = mock('rational')
          o.should_not_receive(:to_r)
          lambda { Time.at(o) }.should raise_error(TypeError)
        end
      end

      ruby_version_is "1.9" do
        it "coerces using #to_r" do
          o = mock('rational')
          o.should_receive(:to_r).and_return(Rational(5, 2))
          Time.at(o).should == Time.at(Rational(5, 2))
        end
      end
    end
  end

  describe "passed [Integer, Numeric]" do
    it "returns a Time object representing the given number of seconds and Integer microseconds since 1970-01-01 00:00:00 UTC" do
      t = Time.at(10, 500000)
      t.tv_sec.should == 10
      t.tv_usec.should == 500000
    end

    ruby_version_is "1.9" do
      it "returns a Time object representing the given number of seconds and Float microseconds since 1970-01-01 00:00:00 UTC" do
        t = Time.at(10, 500.500)
        t.tv_sec.should == 10
        t.tv_nsec.should == 500500
      end
    end
  end

  describe "with a second argument that responds to #to_int" do
    it "coerces using #to_int" do
      o = mock('integer')
      o.should_receive(:to_int).and_return(10)
      Time.at(0, o).should == Time.at(0, 10)
    end
  end

  describe "with a second argument that responds to #to_r" do
    ruby_version_is ""..."1.9" do
      it "raises a TypeError" do
        o = mock('rational')
        o.should_not_receive(:to_r)
        lambda { Time.at(0, o) }.should raise_error(TypeError)
      end
    end

    ruby_version_is "1.9" do
      it "coerces using #to_r" do
        o = mock('rational')
        o.should_receive(:to_r).and_return(Rational(5, 2))
        Time.at(0, o).should == Time.at(0, Rational(5, 2))
      end
    end
  end

  describe "passed [Integer, nil]" do
    it "raises a TypeError" do
      lambda { Time.at(0, nil) }.should raise_error(TypeError)
    end
  end

  describe "passed [Integer, String]" do
    it "raises a TypeError" do
      lambda { Time.at(0, "0") }.should raise_error(TypeError)
    end
  end

  describe "passed [Time, Integer]" do
    ruby_version_is ""..."1.9" do
      it "raises a TypeError" do
        lambda { Time.at(Time.now, 500000) }.should raise_error(TypeError)
      end
    end

    ruby_version_is "1.9" do
      it "returns a Time object equal to the specified time plus the number of microseconds" do
        t1 = Time.at(10)
        t2 = Time.at(t1, 500000)
        t2.tv_sec.should == 10
        t2.tv_usec.should == 500000
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10688979345695764, 'fraction_numerical': 0.04507764209256747, 'mean_word_length': 2.248775710088149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4601705', 'n_tokens_mistral': 2522, 'n_tokens_neox': 2264, 'n_words': 706}