Rake TestTask running its block anytime rake is invoked


require ‘rake/testtask’

Rake::TestTask.new do |t|
chdir ‘./…/’
puts pwd
end

desc “print working directory”
task :pwd do
puts “Working Directory #{pwd}”
end

$ rake -T
cd ./…/
/Users/scudco/projects
rake chdir # change directory
rake test # Run tests

$ rake chdir
cd ./…/
/Users/scudco/projects
Working Directory /Users/scudco/projects

So the question is why does the chdir in the TestTask get executed every
time no matter what? It is quite frustrating when code specific to a
block is being executed for every other task. Any ideas?


require ‘rake/testtask’

Rake::TestTask.new do |t|
chdir ‘./…/’
puts pwd
end

desc “print working directory”
task :pwd do
puts “Working Directory #{pwd}”
end

$ rake -T
cd ./…/
/Users/scudco/projects
rake pwd # print working directory
rake test # Run tests

$ rake pwd
cd ./…/
/Users/scudco/projects
Working Directory /Users/scudco/projects