<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -8,18 +8,28 @@ class Sandbox
 
   # Executes the block and yields the path to the sandbox directory.
   # Cleans up the sandbox after the block is complete.
-  def self.play(path = nil, &amp;block)
-    sandbox = Sandbox.new(path)
-    
+  # == Options
+  # [+:path+] the path to use. default:  generate one in Dir.tmpdir
+  # [+:cd+] change directory with Dir.chdir to the temp directory
+  def self.play(options = {}, &amp;block)
+    sandbox = Sandbox.new(options[:path])
+
     begin
-      yield sandbox.path
+      if options[:cd]
+        Dir.chdir(sandbox.path) do
+          yield sandbox.path
+        end
+      else
+        yield sandbox.path
+      end
     ensure
       sandbox.close
     end
   end
 
-  # Creates a new Sandbox with an optional path.  Generates a random
-  # path in Dir.tmpdir if path is unspecified.
+  # Creates a new Sandbox with an optional path.
+  # == Parameters
+  # [+path+] The path to use.  default:  generate one in Dir.tmpdir
   def initialize(path = nil)
     self.path = path || generate_path
     </diff>
      <filename>lib/sandbox.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 require File.dirname(__FILE__) + '/spec_helper'
 
 describe &quot;Sandbox&quot; do
-  context &quot;no errors&quot; do
+  context &quot;when there are no errors in the block&quot; do
     it &quot;cleans up after itself&quot; do
       path = Sandbox.play do |p|
         File.exist?(p).should be_true
@@ -11,9 +11,29 @@ describe &quot;Sandbox&quot; do
 
       File.exist?(path).should be_false
     end
+
+    it &quot;changes directories when :cd =&gt; true is specified&quot; do
+      path = Sandbox.play(:cd =&gt; true) do |p|
+        File.exist?(p).should be_true
+        File.ftype(p).should == 'directory'
+        File::Stat.new(Dir.pwd).ino.should == File::Stat.new(p).ino
+        p
+      end
+
+      File.exist?(path).should be_false
+    end
+
+    it &quot;uses the specified path when :path is specified&quot; do
+      tmp = Dir.tmpdir
+      path = File.join(tmp, 'sandbox-test')
+      
+      Sandbox.play(:path =&gt; path) do |p|
+        p.should == path
+      end
+    end
   end
   
-  context &quot;exception raised&quot; do
+  context &quot;when an exception is raised&quot; do
     it &quot;cleans up after itself&quot; do
       lambda {
         Sandbox.play do |p|
@@ -26,15 +46,4 @@ describe &quot;Sandbox&quot; do
       File.exist?(@path).should be_false
     end
   end
-
-  context &quot;optional path supplied&quot; do
-    it &quot;uses the specified path&quot; do
-      tmp = Dir.tmpdir
-      path = File.join(tmp, 'sandbox-test')
-      
-      Sandbox.play(path) do |p|
-        p.should == path
-      end
-    end
-  end
 end</diff>
      <filename>spec/sandbox_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f0ce286fc7f0e91cb68f4c5def63e4cb35716794</id>
    </parent>
  </parents>
  <author>
    <name>Brandon Dimcheff</name>
    <email>bdimchef-git@wieldim.com</email>
  </author>
  <url>http://github.com/bdimcheff/sandbox/commit/a819b90852b81c1ef61893e54a08bf19ec4d9a51</url>
  <id>a819b90852b81c1ef61893e54a08bf19ec4d9a51</id>
  <committed-date>2009-03-04T18:45:28-08:00</committed-date>
  <authored-date>2009-03-04T18:45:28-08:00</authored-date>
  <message>automatic directory changing option</message>
  <tree>817158bf8474cf50b3b43032d154343865b98fad</tree>
  <committer>
    <name>Brandon Dimcheff</name>
    <email>bdimchef-git@wieldim.com</email>
  </committer>
</commit>
