# Running a rake test task within a specific directory

**URL:** <https://www.ruby-forum.com/t/running-a-rake-test-task-within-a-specific-directory/83369>\
**Category:** Ruby\
**Created:** [January 25, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/running-a-rake-test-task-within-a-specific-directory/83369 "2007-01-25T16:30:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [January 25, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/running-a-rake-test-task-within-a-specific-directory/83369/1 "2007-01-25T16:30:35Z")

</div>

Hi all,

I’m trying to figure out how to setup a task that temporarily changes  
to a specific directory, runs the tests, and returns to the current  
directory when finished. In case you’re wondering why, I have some test  
cases that create temporary files (in the setup method), use those temp  
files in the tests themselves, and then delete them (in the teardown  
method).

While I could jump through hoops to make sure the proper path of the  
temp files are found within each test case, I’d rather not. I was  
hoping to do something like this:

Rake::TestTask.new(‘test\_file’) do |test|  
Dir.chdir(‘test/core/File’) do  
test.test\_files = FileList[’_/_.rb’]  
end  
end

Unfortunately, that doesn’t seem to work, and I’m not sure why. Any  
ideas?

Thanks,

Dan

PS - On an unrelated note, I _hate_ this new google groups interface. I  
can’t see my subscribed groups on the same page (it’s an extra click  
away now), and there’s no more “preview” option in the compose window.  
Oh, and the color scheme is depressing. BARF!
