Testing Rake task with Rspec with Rails environment

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

    Sounds like your take task may need the Rails environment to be loaded. You can stub this out by adding this line to your before(:all) hook:

    Rake::Task.define_task(:environment)
    

提交回复
热议问题