<commit_before>require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/common'

describe "Dir.chdir" do
  before :all do
    DirSpecs.create_mock_dirs
  end

  after :all do
    DirSpecs.delete_mock_dirs
  end

  before :each do
    @original = Dir.pwd
  end

  after :each do
    Dir.chdir(@original)
  end

  it "defaults to $HOME with no arguments" do
    if ENV['HOME']
    Dir.chdir(ENV['HOME'])
    home = Dir.pwd

    Dir.chdir
    Dir.pwd.should == home
    end
  end

  it "changes to the specified directory" do
    Dir.chdir DirSpecs.mock_dir
    Dir.pwd.should == DirSpecs.mock_dir
  end

  it "returns 0 when successfully changing directory" do
    Dir.chdir(@original).should == 0
  end

  it "calls #to_str on the argument if it's not a String" do
    obj = mock('path')
    obj.should_receive(:to_str).and_return(Dir.pwd)
    Dir.chdir(obj)
  end<commit_msg>Add a test that chdir should call to_str on an object if a block is given<commit_after>require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/fixtures/common'

describe "Dir.chdir" do
  before :all do
    DirSpecs.create_mock_dirs
  end

  after :all do
    DirSpecs.delete_mock_dirs
  end

  before :each do
    @original = Dir.pwd
  end

  after :each do
    Dir.chdir(@original)
  end

  it "defaults to $HOME with no arguments" do
    if ENV['HOME']
    Dir.chdir(ENV['HOME'])
    home = Dir.pwd

    Dir.chdir
    Dir.pwd.should == home
    end
  end

  it "changes to the specified directory" do
    Dir.chdir DirSpecs.mock_dir
    Dir.pwd.should == DirSpecs.mock_dir
  end

  it "returns 0 when successfully changing directory" do
    Dir.chdir(@original).should == 0
  end

  it "calls #to_str on the argument if it's not a String" do
    obj = mock('path')
    obj.should_receive(:to_str).and_return(Dir.pwd)
    Dir.chdir(obj)
  end

  it "calls #to_str on the argument if it's not a String and a block is given" do
    obj = mock('path')
    obj.should_receive(:to_str).and_return(Dir.pwd)
    Dir.chdir(obj) { }
  end
{'fraction_non_alphanumeric': 0.10582010582010581, 'fraction_numerical': 0.001924001924001924, 'mean_word_length': 2.9543726235741445, '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': '7112145', 'n_tokens_mistral': 752, 'n_tokens_neox': 725, 'n_words': 212}