My spec provides coverage like I had hoped, however, the following 2 messages are displaying in the rspec output:
rake resque:scheduler
rake environment resque:work
How do I swallow these during spec runs so they do not screw up my nyancat formatter?
Spec
describe 'database rake task' do
include_context 'rake'
let(:task_paths) { ['tasks/heroku'] }
before do
invoke_task.reenable
end
# rubocop:disable all
describe 'myapp:heroku' do
context ':setup' do
context ':secrets' do
let(:task_name) { 'myapp:heroku:setup:secrets' }
context 'with env' do
it 'works' do
expect(File).to receive(:exist?).with('.env').and_return(true)
expect_any_instance_of(Object).to receive(:system).with('heroku config:push --remote production').and_return(true)
expect { invoke_task.invoke }.to output(
"\nUpdating Secrets for production\n"
).to_stdout
end
end
context 'without env' do
it 'works' do
expect(File).to receive(:exist?).with('.env').and_return(false)
expect { invoke_task.invoke }.to raise_error("\nYou are missing the .env file\n").and(output(
"\nUpdating Secrets for production\n"
).to_stdout)
end
end
end
end
end
describe 'schedule_and_work' do
let(:task_name) { 'schedule_and_work' }
context 'with process fork' do
it 'works' do
expect(Process).to receive(:fork).and_return(true)
expect_any_instance_of(Object).to receive(:system).with('rake environment resque:work', {}).and_return(true)
expect(invoke_task.invoke).to be
end
end
context 'without process fork' do
it 'works' do
expect(Process).to receive(:fork).and_return(false)
expect(Process).to receive(:wait).and_return(true)
expect_any_instance_of(Object).to receive(:system).with('rake resque:scheduler', {}).and_return(true)
expect(invoke_task.invoke).to be
end
end
end
# rubocop:enable all
end
Rake Task
namespace :myapp do
namespace :heroku do
namespace :setup do
desc 'modify secrets'
task :secrets do
puts "\nUpdating Secrets for production\n"
raise "\nYou are missing the .env file\n" unless File.exist?('.env')
system('heroku config:push --remote production')
end
end
end
end
# Run resque scheduler on 2 free dynos
# https://grosser.it/2012/04/14/resque-scheduler-on-heroku-without-extra-workers/
task :schedule_and_work do
if Process.fork
sh 'rake environment resque:work'
else
sh 'rake resque:scheduler'
Process.wait
end
end