Why when I use Queue Mode for RSpec then my rake tasks are run twice?
Why rake tasks are being ran twice in Queue Mode? If you have tests for your rake task then you want to ensure you clear the rake task before loading it inside of test file. In Queue Mode the rake task could be already loaded and loading it again in test file may result in running the task twice.
before do
# Clear rake task from memory if it was already loaded.
# This ensures rake task is loaded only once in knapsack_pro Queue Mode.
Rake::Task[task_name].clear if Rake::Task.task_defined?(task_name)
# loaad rake task only once here
Rake.application.rake_require("tasks/dummy")
Rake::Task.define_task(:environment)
end
Here is the full example how to test rake task along with dummy rake task from our example rails project.