Posted about 1 month ago. Visible to the public.

Rspec: Expecting a Rake task to be called

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

Copy
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

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

Example:

Copy
desc 'Some task' task :some_task do SomeClass.new.run end

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Avatar
Emanuel De
Last edit:
about 1 month ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Emanuel De to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more