Testing Rake task with Rspec with Rails environment
问题 I'm trying to test a rake task and it uses an active record in it. require 'spec_helper' require 'rake' load File.join(Rails.root, 'lib', 'tasks', 'survey.rake') describe "survey rake tasks" do describe "survey:send_report" do it "should send a report" do Rake::Task['survey:send_report'].invoke end end end When I run this spec rspec spec/lib/survey_spec.rb , I get this error " RuntimeError: Don't know how to build task 'environment' How do I load the :enviroment task inside by example spec?