Testing Rake task with Rspec with Rails environment

前端 未结 4 1675
闹比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:52

    I think you should first load the tasks:

    require 'rake'
    MyRailsApp::Application.load_tasks
    

    and then invoke your task:

    Rake::Task['survey:send_report'].invoke
    

提交回复
热议问题