override RAILS_ENV from rake task

You could do

rake RAILS_ENV=“test” taskname

or are you looking for something more programmable?