Skip to content

Commit 22202bf

Browse files
authored
Merge pull request #196 from nobu/test-cd-and-chdir
Test directory changes and verify the `chdir` alias
2 parents 6c74655 + 8476509 commit 22202bf

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

test/fileutils/test_fileutils.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,30 +1946,44 @@ def test_uptodate?
19461946

19471947
def test_cd
19481948
check_singleton :cd
1949+
1950+
original = FileUtils.pwd
1951+
FileUtils.cd('tmp')
1952+
assert_equal(File.join(original, 'tmp'), FileUtils.pwd)
1953+
ensure
1954+
FileUtils.cd(original) if original
19491955
end
19501956

19511957
def test_cd_result
19521958
assert_equal 42, cd('.') { 42 }
1959+
1960+
original = FileUtils.pwd
1961+
assert_equal('tmp', FileUtils.cd('tmp') {|dir|
1962+
assert_equal(File.join(original, 'tmp'), Dir.pwd)
1963+
dir
1964+
})
1965+
assert_equal(original, FileUtils.pwd)
19531966
end
19541967

19551968
def test_chdir
19561969
check_singleton :chdir
1970+
assert_equal(FileUtils.method(:cd), FileUtils.method(:chdir))
19571971
end
19581972

1959-
def test_chdir_verbose
1973+
def test_cd_verbose
19601974
assert_output_lines(["cd .", "cd -"], FileUtils) do
1961-
FileUtils.chdir('.', verbose: true){}
1975+
FileUtils.cd('.', verbose: true){}
19621976
end
19631977
end
19641978

1965-
def test_chdir_verbose_frozen
1979+
def test_cd_verbose_frozen
19661980
o = Object.new
19671981
o.extend(FileUtils)
1968-
o.singleton_class.send(:public, :chdir)
1982+
o.singleton_class.send(:public, :cd)
19691983
o.freeze
19701984
orig_stdout = $stdout
19711985
$stdout = StringIO.new
1972-
o.chdir('.', verbose: true){}
1986+
o.cd('.', verbose: true){}
19731987
$stdout.rewind
19741988
assert_equal(<<-END, $stdout.read)
19751989
cd .

0 commit comments

Comments
 (0)