Testing Rake task with Rspec with Rails environment

前端 未结 4 1688
闹比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

    I suspect the problem is that your survey:send_report task depends on :environment but you haven't loaded the file that defines the :environment task. That'll be in rails somewhere, and your main Rakefile loads it.

    So, I think if you change

    load File.join(Rails.root, 'lib', 'tasks', 'survey.rake')
    

    to

    load File.join(Rails.root, 'Rakefile')
    

    it'll work.

提交回复
热议问题