Running Rake tasks in RSpec several times returns nil?

I assume this is due to the fact that Rake reads the file once and does not rewind it? But I'm not sure. Any ideas?

require 'rake' require 'rails_helper' describe 'MyRakeTask' do before(:all) do Rails.application.load_tasks end it 'does something sweet' do Rake::Task["namespace:my_task"].invoke # runs task end it 'but it doesnt do it again' do Rake::Task["namespace:my_task"].invoke # returns nil end end 
+5
source share
1 answer

Rake docs say invoke will only complete the task if necessary. The following was extracted from another SO and could help clarify:

  • Rake :: Task ["build"]. execute always executes a task, but does not execute its dependencies

  • Rake :: Task ["build"]. invoke executes dependencies, but only performs this task if it has not already been called

  • Rake :: Task ["build"]. reenable first resets the task already in the inv_invoked state, allowing it to then complete the task again, dependencies and all.

+10
source

All Articles