From 8dce49ef455895a06e638cc339779839ca6d06b7 Mon Sep 17 00:00:00 2001
From: Johan Holmberg <holmberg556@gmail.com>
Date: Mon, 15 Jun 2015 21:22:17 +0200
Subject: [PATCH] pass new "chdir" tests

---
 lib/cmdtest/testcase.rb | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/lib/cmdtest/testcase.rb b/lib/cmdtest/testcase.rb
index ea989b9..344eaf4 100644
--- a/lib/cmdtest/testcase.rb
+++ b/lib/cmdtest/testcase.rb
@@ -55,10 +55,10 @@ module Cmdtest
 
     def setup
     end
-    
+
     def teardown
     end
-    
+
     #------------------------------
 
     ORIG_CWD = Dir.pwd
@@ -202,26 +202,39 @@ module Cmdtest
     #------------------------------
 
     def current_directory
-      @_cwd
+      self._cwd
+    end
+
+    def _cwd
+      if @_runner.opts.parallel == 1
+        Dir.pwd
+      else
+        @_cwd
+      end
+    end
+
+    def _cwd=(dir)
+      if @_runner.opts.parallel == 1
+        Dir.chdir(dir)
+      else
+        @_cwd = dir
+      end
     end
 
     #------------------------------
 
     def chdir(dir, &block)
-      dir_path = File.expand_path(dir, @_cwd)
+      dir_path = File.expand_path(dir, self._cwd)
       if block_given?
-        saved_cwd = @_cwd
-        @_cwd = dir_path
-        Dir.chdir(@_cwd) if @_runner.opts.parallel == 1
+        saved_cwd = self._cwd
+        self._cwd = dir_path
         begin
           yield
         ensure
-          @_cwd = saved_cwd
-          Dir.chdir(@_cwd) if @_runner.opts.parallel == 1
+          self._cwd = saved_cwd
         end
       else
-        @_cwd = dir_path
-        Dir.chdir(@_cwd) if @_runner.opts.parallel == 1
+        self._cwd = dir_path
       end
     end
 
@@ -258,7 +271,7 @@ module Cmdtest
     # of the call was started.
 
     def prepend_local_path(dir)
-      @_env_path.unshift(File.expand_path(dir, @_cwd))
+      @_env_path.unshift(File.expand_path(dir, self._cwd))
     end
 
     #------------------------------
@@ -422,7 +435,7 @@ module Cmdtest
     #------------------------------
 
     def _cwd_path(path)
-      File.expand_path(path, @_cwd)
+      File.expand_path(path, self._cwd)
     end
 
     #------------------------------