I'm guessing this has to do with Rake reading the file once and not rewinding 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
The Rake docs say invoke
will only run the task if it's "needed". The following was pulled from another SO answer and might help clarify:
Rake::Task["build"].execute always executes the task, but it doesn't execute its dependencies
Rake::Task["build"].invoke executes the dependencies, but it only executes the task if it has not already been invoked
Rake::Task["build"].reenable first resets the task's already_invoked state, allowing the task to then be executed again, dependencies and all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With