我試圖測試一個rake任務,並且它使用一個活動記錄。使用Rspec與Rails環境測試Rake任務
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
當我運行該規範rspec spec/lib/survey_spec.rb
,我得到這個錯誤「
RuntimeError:
Don't know how to build task 'environment'
如何加載:通過實例規範內部環境的任務
本指南看起來像它可以幫助:http://www.philsergi.com/2009/02/testing-rake-可以通過添加此行到您之前存根這一點tasks-with-rspec.html –