Update rubocop-rspec to version 3.6.0 (#34497)

This commit is contained in:
Matt Jankowski 2025-04-24 10:56:13 -04:00 committed by GitHub
parent 22ec828951
commit 6463415e06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 223 additions and 228 deletions

View file

@ -8,95 +8,82 @@ RSpec.describe Import::RowWorker do
let(:row) { Fabricate(:bulk_import_row, bulk_import: import) }
describe '#perform' do
before do
allow(BulkImportRowService).to receive(:new).and_return(service_double)
before { allow(BulkImportRowService).to receive(:new).and_return(service_double) }
shared_context 'when service succeeds' do
let(:service_double) { instance_double(BulkImportRowService, call: true) }
end
shared_context 'when service fails' do
let(:service_double) { instance_double(BulkImportRowService, call: false) }
end
shared_context 'when service errors' do
let(:service_double) { instance_double(BulkImportRowService) }
before { allow(service_double).to receive(:call).and_raise('dummy error') }
end
shared_examples 'clean failure' do
let(:service_double) { instance_double(BulkImportRowService, call: false) }
it 'calls BulkImportRowService' do
subject.perform(row.id)
expect(service_double).to have_received(:call).with(row)
end
it 'increases the number of processed items' do
expect { subject.perform(row.id) }.to(change { import.reload.processed_items }.by(+1))
end
it 'does not increase the number of imported items' do
expect { subject.perform(row.id) }.to_not(change { import.reload.imported_items })
end
it 'does not delete the row' do
subject.perform(row.id)
expect(BulkImportRow.exists?(row.id)).to be true
it 'calls service, increases processed items, preserves imported items, and keeps row' do
expect { subject.perform(row.id) }
.to change { import.reload.processed_items }.by(+1)
.and not_change { import.reload.imported_items }
.and(not_change { BulkImportRow.exists?(row.id) }.from(true))
expect(service_double)
.to have_received(:call).with(row)
end
end
shared_examples 'unclean failure' do
let(:service_double) { instance_double(BulkImportRowService) }
before do
allow(service_double).to receive(:call) do
raise 'dummy error'
end
end
it 'raises an error and does not change processed items count' do
expect { subject.perform(row.id) }.to raise_error(StandardError, 'dummy error').and(not_change { import.reload.processed_items })
end
it 'does not delete the row' do
expect { subject.perform(row.id) }.to raise_error(StandardError, 'dummy error').and(not_change { BulkImportRow.exists?(row.id) })
it 'raises an error, preserves processed items, and keeps row' do
expect { subject.perform(row.id) }
.to raise_error(StandardError, 'dummy error')
.and(not_change { import.reload.processed_items })
.and(not_change { BulkImportRow.exists?(row.id) }.from(true))
end
end
shared_examples 'clean success' do
let(:service_double) { instance_double(BulkImportRowService, call: true) }
it 'calls BulkImportRowService' do
subject.perform(row.id)
it 'calls service, increases processed items, increases imported items, and deletes row' do
expect { subject.perform(row.id) }
.to change { import.reload.processed_items }.by(+1)
.and change { import.reload.imported_items }.by(+1)
.and(change { BulkImportRow.exists?(row.id) }.from(true).to(false))
expect(service_double).to have_received(:call).with(row)
end
it 'increases the number of processed items' do
expect { subject.perform(row.id) }.to(change { import.reload.processed_items }.by(+1))
end
it 'increases the number of imported items' do
expect { subject.perform(row.id) }.to(change { import.reload.imported_items }.by(+1))
end
it 'deletes the row' do
expect { subject.perform(row.id) }.to change { BulkImportRow.exists?(row.id) }.from(true).to(false)
end
end
context 'when there are multiple rows to process' do
let(:import) { Fabricate(:bulk_import, total_items: 2, processed_items: 0, imported_items: 0, state: :in_progress) }
context 'with a clean failure' do
include_examples 'clean failure'
include_context 'when service fails'
it_behaves_like 'clean failure'
it 'does not mark the import as finished' do
expect { subject.perform(row.id) }.to_not(change { import.reload.state.to_sym })
expect { subject.perform(row.id) }
.to_not(change { import.reload.state.to_sym })
end
end
context 'with an unclean failure' do
include_examples 'unclean failure'
include_context 'when service errors'
it_behaves_like 'unclean failure'
it 'does not mark the import as finished' do
expect { subject.perform(row.id) }.to raise_error(StandardError).and(not_change { import.reload.state.to_sym })
expect { subject.perform(row.id) }
.to raise_error(StandardError)
.and(not_change { import.reload.state.to_sym })
end
end
context 'with a clean success' do
include_examples 'clean success'
include_context 'when service succeeds'
it_behaves_like 'clean success'
it 'does not mark the import as finished' do
expect { subject.perform(row.id) }.to_not(change { import.reload.state.to_sym })
expect { subject.perform(row.id) }
.to_not(change { import.reload.state.to_sym })
end
end
end
@ -105,21 +92,28 @@ RSpec.describe Import::RowWorker do
let(:import) { Fabricate(:bulk_import, total_items: 2, processed_items: 1, imported_items: 0, state: :in_progress) }
context 'with a clean failure' do
include_examples 'clean failure'
include_context 'when service fails'
it_behaves_like 'clean failure'
it 'marks the import as finished' do
expect { subject.perform(row.id) }.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished)
expect { subject.perform(row.id) }
.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished)
end
end
# NOTE: sidekiq retry logic may be a bit too difficult to test, so leaving this blind spot for now
it_behaves_like 'unclean failure'
context 'with an unclean failure' do
# NOTE: sidekiq retry logic may be a bit too difficult to test, so leaving this blind spot for now
include_context 'when service errors'
it_behaves_like 'unclean failure'
end
context 'with a clean success' do
include_examples 'clean success'
include_context 'when service succeeds'
it_behaves_like 'clean success'
it 'marks the import as finished' do
expect { subject.perform(row.id) }.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished)
expect { subject.perform(row.id) }
.to change { import.reload.state.to_sym }.from(:in_progress).to(:finished)
end
end
end