test current directory in "teardown" method

even when current directory is changed within a test method
the "teardown" method should have same current directory
as "setup" and as the the original value in the test method.
This commit is contained in:
Johan Holmberg 2016-06-04 20:53:49 +02:00
parent dc4ab527de
commit 4cbbac7ec1

42
t/CMDTEST_teardown.rb Normal file
View File

@ -0,0 +1,42 @@
require "selftest_utils"
class CMDTEST_teardown < Cmdtest::Testcase
include SelftestUtils
def test_teardown
create_file "CMDTEST_foo.rb", [
"class CMDTEST_foo < Cmdtest::Testcase",
" def setup",
" puts 'setup: ' + Dir.pwd",
" end",
"",
" def teardown",
" puts 'teardown: ' + Dir.pwd",
" end",
"",
" def test_foo",
" puts 'test: ' + Dir.pwd",
" Dir.mkdir('subdir')",
" Dir.chdir('subdir') do",
" puts 'test_subdir: ' + Dir.pwd",
" end",
" end",
"end",
]
cwd = Dir.pwd
cmdtest = "#{TOP}/bin/cmdtest.rb"
command = "ruby %s --quiet" % _quote(cmdtest)
cmd(command) do
stdout_equal [
"setup: #{cwd}/tmp-cmdtest-2/top/work",
"test: #{cwd}/tmp-cmdtest-2/top/work",
"test_subdir: #{cwd}/tmp-cmdtest-2/top/work/subdir",
"teardown: #{cwd}/tmp-cmdtest-2/top/work",
]
end
end
end