Read more

Rspec: Expecting a Rake task to be called

Emanuel
May 28, 2020Software engineer at makandra GmbH

This seems to be obvious, but you can expect Rake tasks to be called in RSpec.

it 'deletes all Users' do
   FactroyBot.create(:user)
   expect(Rake::Task['notify:critical_operation']).to receive(:invoke)
   
   expect { described_class.clean }.to change(User, :count).from(1).to(0) 
end

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Note: Try to avoid logic in rake tasks and prefer to just call classes in them.

Example:

desc 'Some task'
task :some_task do
  SomeClass.new.run
end
Posted by Emanuel to makandra dev (2020-05-28 13:58)