I had a similar issue and despite having replaced ENV["RAILS_ENV"] = 'test' with Rails.env = 'test' in spec_helper.rb, I just have to manually specify RAILS_ENV=test when I run the command for it to work. Look here, but do try the Rails.env thing first: