Test Rake Tasks

后端 未结 6 1029
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 18:28

I am developing a ROR app that relies on many custom Rake tasks.

What is the best way to test them?

6条回答
  •  眼角桃花
    2021-01-31 19:22

    Something like:

      def execute_rake(file,task)
        require 'rake'
        rake = Rake::Application.new
        Rake.application = rake
        Rake::Task.define_task(:environment)
        load "#{Rails.root}/lib/tasks/#{file}"
        rake[task].invoke
      end
    

    At your spec:

    execute_rake("tags.rake","tags:popular")
    

提交回复
热议问题