I have the following rake task defined in my lib/tasks
folder:
namespace :db do
namespace :test do
task :prepare => :environment do
I was having this problem too; in my db/seeds.rb
file I have a block that creates user accounts in the development environment, but they were also being created when preparing the test environment to run rake
for RSpec or Cucumber testing, which resulted in a wall of red.
Updated: I've found that the best way to specify the environment for rake tasks is to specify the environment within the task, above all statements that need the environment to be set. So in this case:
Rails.env = 'test'
Rake::Task["db:seed"].invoke
does the job.