Why is my rake task running twice in my test?

后端 未结 4 1559
悲&欢浪女
悲&欢浪女 2021-01-12 17:23

I have a rake task test that I setup following the only examples I could find online.

It looks like this:

require \'test_helper\'
require \'minitest/         


        
4条回答
  •  一整个雨季
    2021-01-12 17:38

    Updated answer for rails 5.1 (using minitest):

    I found I needed the following to load tasks once and only once:

    MyAppName::Application.load_tasks if Rake::Task.tasks.empty?
    

    Alternatively add MyAppName::Application.load_tasks to your test_helper, if you don't mind tasks being loaded even when running individual tests that don't need them.

    (Replace MyAppName with your application name)

提交回复
热议问题