Why is my rake task running twice in my test?

后端 未结 4 1643
悲&欢浪女
悲&欢浪女 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 17:56

    I've tried @iheggie answer but it worked in a way that indeed tests were run once but any other task was breaking with Don't know how to build task ''.

    I'm on Rails 3.2 still. It turned out that there were couple tasks loaded beforehand so the Rake::Task.tasks.empty? was never true and all other useful tasks were not loaded. I've fiddled with it and this version of it works for me right now:

    Rake::Task.clear if Rails.env.test?
    MyAppName::Application.load_tasks
    

    Hope this helps anyone.

提交回复
热议问题