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

describe "Time#-" do
  it "decrements the time by the specified amount" do
    (Time.at(100) - 100).should == Time.at(0)
    (Time.at(100) - Time.at(99)).should == 1.0
  end

  it "understands negative subtractions" do
    t = Time.at(100) - -1.3
    t.usec.should == 300000
    t.to_i.should == 101
  end

  ruby_version_is ""..."1.9" do
    it "accepts arguments that can be coerced into Float" do
      (obj = mock('9.5')).should_receive(:to_f).and_return(9.5)
      (Time.at(100) - obj).should == Time.at(90.5)
    end
  end

  ruby_version_is "1.9" do
    #see [ruby-dev:38446]
    it "accepts arguments that can be coerced into Rational" do
      (obj = mock_numeric('10')).should_receive(:to_r).and_return(Rational(10))
      (Time.at(100) - obj).should == Time.at(90)
    end
  end
<commit_msg>Add a Time#- spec for String arguments<commit_after>require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/methods', __FILE__)

describe "Time#-" do
  it "decrements the time by the specified amount" do
    (Time.at(100) - 100).should == Time.at(0)
    (Time.at(100) - Time.at(99)).should == 1.0
  end

  it "understands negative subtractions" do
    t = Time.at(100) - -1.3
    t.usec.should == 300000
    t.to_i.should == 101
  end

  ruby_version_is ""..."1.9" do
    it "accepts arguments that can be coerced into Float" do
      (obj = mock('9.5')).should_receive(:to_f).and_return(9.5)
      (Time.at(100) - obj).should == Time.at(90.5)
    end
  end

  ruby_version_is "1.9" do
    #see [ruby-dev:38446]
    it "accepts arguments that can be coerced into Rational" do
      (obj = mock_numeric('10')).should_receive(:to_r).and_return(Rational(10))
      (Time.at(100) - obj).should == Time.at(90)
    end
  end

  it "raises a TypeError if given argument is a coercible String" do
    lambda { Time.now - "1" }.should raise_error(TypeError)
    lambda { Time.now - "0.1" }.should raise_error(TypeError)
    lambda { Time.now - "1/3" }.should raise_error(TypeError)
  end

{'fraction_non_alphanumeric': 0.15730858468677494, 'fraction_numerical': 0.054292343387471, 'mean_word_length': 3.0374531835205993, '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': '3589629', 'n_tokens_mistral': 870, 'n_tokens_neox': 787, 'n_words': 194}