Testing Rake task with Rspec with Rails environment

前端 未结 4 1672
闹比i
闹比i 2021-02-07 03:02

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\', \'su         


        
4条回答
  •  死守一世寂寞
    2021-02-07 03:38

    Is your task adding the :enviroment to do it before? In your .rake file you should have something like this:

    namespace :survey do
    # ...
    
    task :send_report => :enviroment do
    # ... stuff
    end
    

    This is because you need to load the full enviroment to do that task. You can check this railcast to get more information http://railscasts.com/episodes/66-custom-rake-tasks

提交回复
热议问题