Skip to content
Snippets Groups Projects
Unverified Commit aacebd6e authored by Peter Leitzen's avatar Peter Leitzen
Browse files

Configure RSpec to fail on potential false positives

Previously RSpec only warned in the following cases:

   expect(foo).to raise_error

   expect(foo).not_to raise_error(SomeSpecifcError)

and suggested to correct potential false positives with:

   expect(foo).to raise_error(SomeSpecifcError)

   expect(foo).not_to raise_error

This commit corrects all warnings and make RSpec fail instead of warn in
such situations preventing future false positives.
parent 794bcbf6
No related branches found
No related tags found
No related merge requests found
Showing
with 51 additions and 48 deletions
Loading
Loading
@@ -73,11 +73,15 @@ def app
end
 
context 'unauthorized param' do
let(:exception) { Exception.new('Forbidden') }
before do
allow(subject).to receive(:authorize!).and_raise(Exception.new("Forbidden"))
allow(subject).to receive(:authorize!).and_raise(exception)
end
it 'throws exception if unauthorized param is present' do
expect { subject.authorize_change_param(project, :change_commit_committer_check) }.to raise_error
expect { subject.authorize_change_param(project, :change_commit_committer_check) }
.to raise_error(exception)
end
 
it 'does not throw exception is unauthorized param is not present' do
Loading
Loading
Loading
Loading
@@ -347,7 +347,7 @@ def create_data_for_end_event(issue, example_class)
subject { described_class.new(stage: stage, params: params) }
 
it 'does not raise query syntax error' do
expect { subject.records_fetcher.serialized_records }.not_to raise_error(ActiveRecord::StatementInvalid)
expect { subject.records_fetcher.serialized_records }.not_to raise_error
end
end
end
Loading
Loading
Loading
Loading
@@ -30,7 +30,7 @@
expect(::Gitlab::IpAddressState).to receive(:nullify_address)
expect(app).to receive(:call).and_raise('boom')
 
expect { middleware.call(env) }.to raise_error
expect { middleware.call(env) }.to raise_error('boom')
end
 
context 'when it is internal endpoint' do
Loading
Loading
Loading
Loading
@@ -417,8 +417,8 @@
 
it "does not raise an error on creation with a unique sequence number within a cadence", :aggregate_failures do
expect do
create(:iteration, :with_due_date, sequence: 2, iterations_cadence: iterations_cadence1, start_date: 2.weeks.from_now)
end.not_to raise_error(ActiveRecord::RecordNotUnique)
create(:iteration, :with_due_date, sequence: 2, iterations_cadence: iterations_cadence, start_date: 2.weeks.from_now)
end.not_to raise_error
end
end
 
Loading
Loading
@@ -481,7 +481,7 @@
iteration1.update_columns(dates2)
iteration2.update_columns(dates1)
end
end.not_to raise_exception(ActiveRecord::StatementInvalid, /PG::ExclusionViolation/)
end.not_to raise_exception
end
end
end
Loading
Loading
Loading
Loading
@@ -672,10 +672,8 @@ def disable_license_audit_features
 
context 'when the event is created within a transaction' do
it 'does not raise an error about a job being enqueued from within a transaction' do
RSpec::Expectations.configuration.on_potential_false_positives = :nothing
ApplicationRecord.transaction do
expect { event }.not_to raise_error(Sidekiq::Worker::EnqueueFromTransactionError)
expect { event }.not_to raise_error
end
end
end
Loading
Loading
Loading
Loading
@@ -56,7 +56,7 @@
it 'does not call the group wiki restorer' do
expect(::Gitlab::ImportExport::RepoRestorer).not_to receive(:new)
 
expect { import_service.execute }.not_to raise_error(Gitlab::ImportExport::Error)
expect { import_service.execute }.not_to raise_error
end
end
end
Loading
Loading
@@ -14,7 +14,7 @@
end
 
it 'does not raise any exception' do
expect { subject }.not_to raise_error(::Gitlab::Access::AccessDeniedError)
expect { subject }.not_to raise_error
end
end
 
Loading
Loading
Loading
Loading
@@ -929,13 +929,13 @@ def post_play
context 'when continue url is present' do
let(:job) { create(:ci_build, :cancelable, pipeline: pipeline) }
 
before do
post_cancel(continue: { to: url })
end
context 'when continue to is a safe url' do
let(:url) { '/test' }
 
before do
post_cancel(continue: { to: url })
end
it 'redirects to the continue url' do
expect(response).to have_gitlab_http_status(:found)
expect(response).to redirect_to(url)
Loading
Loading
@@ -949,8 +949,9 @@ def post_play
context 'when continue to is not a safe url' do
let(:url) { 'http://example.com' }
 
it 'raises an error' do
expect { cancel_with_redirect(url) }.to raise_error
it 'redirects to the builds page' do
expect(response).to have_gitlab_http_status(:found)
expect(response).to redirect_to(builds_namespace_project_pipeline_path(id: pipeline.id))
end
end
end
Loading
Loading
Loading
Loading
@@ -29,7 +29,7 @@
# Tagging records
expect { tagging_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { tagging_2.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { other_tagging.reload }.not_to raise_error(ActiveRecord::RecordNotFound)
expect { other_tagging.reload }.not_to raise_error
expect { tagging_3.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { tagging_4.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { tagging_5.reload }.to raise_error(ActiveRecord::RecordNotFound)
Loading
Loading
Loading
Loading
@@ -103,7 +103,7 @@
it 'prevents force push' do
expect(Gitlab::Checks::ForcePush).to receive(:force_push?).and_return(true)
 
expect { subject.validate! }.to raise_error
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError)
end
end
end
Loading
Loading
@@ -126,7 +126,7 @@
it 'prevents force push' do
expect(Gitlab::Checks::ForcePush).to receive(:force_push?).and_return(true)
 
expect { subject.validate! }.to raise_error
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError)
end
end
 
Loading
Loading
@@ -141,7 +141,7 @@
it 'prevents force push' do
expect(Gitlab::Checks::ForcePush).to receive(:force_push?).and_return(true)
 
expect { subject.validate! }.to raise_error
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError)
end
end
end
Loading
Loading
Loading
Loading
@@ -3180,15 +3180,15 @@ def setup
 
context 'without proper permissions' do
before do
allow(model).to receive(:execute).with(/CREATE EXTENSION IF NOT EXISTS #{extension}/).and_raise(ActiveRecord::StatementInvalid, 'InsufficientPrivilege: permission denied')
allow(model).to receive(:execute)
.with(/CREATE EXTENSION IF NOT EXISTS #{extension}/)
.and_raise(ActiveRecord::StatementInvalid, 'InsufficientPrivilege: permission denied')
end
 
it 'raises the exception' do
expect { subject }.to raise_error(ActiveRecord::StatementInvalid, /InsufficientPrivilege/)
end
it 'prints an error message' do
expect { subject }.to output(/user is not allowed/).to_stderr.and raise_error
it 'raises an exception and prints an error message' do
expect { subject }
.to output(/user is not allowed/).to_stderr
.and raise_error(ActiveRecord::StatementInvalid, /InsufficientPrivilege/)
end
end
end
Loading
Loading
@@ -3206,15 +3206,15 @@ def setup
 
context 'without proper permissions' do
before do
allow(model).to receive(:execute).with(/DROP EXTENSION IF EXISTS #{extension}/).and_raise(ActiveRecord::StatementInvalid, 'InsufficientPrivilege: permission denied')
end
it 'raises the exception' do
expect { subject }.to raise_error(ActiveRecord::StatementInvalid, /InsufficientPrivilege/)
allow(model).to receive(:execute)
.with(/DROP EXTENSION IF EXISTS #{extension}/)
.and_raise(ActiveRecord::StatementInvalid, 'InsufficientPrivilege: permission denied')
end
 
it 'prints an error message' do
expect { subject }.to output(/user is not allowed/).to_stderr.and raise_error
it 'raises an exception and prints an error message' do
expect { subject }
.to output(/user is not allowed/).to_stderr
.and raise_error(ActiveRecord::StatementInvalid, /InsufficientPrivilege/)
end
end
end
Loading
Loading
Loading
Loading
@@ -62,7 +62,7 @@
end
 
it 'does not raise a UserNotFoundError' do
expect { receiver.execute }.not_to raise_error(Gitlab::Email::UserNotFoundError)
expect { receiver.execute }.not_to raise_error
end
end
end
Loading
Loading
@@ -71,7 +71,7 @@
let(:original_recipient) { User.support_bot }
 
it 'does not raise a UserNotFoundError' do
expect { receiver.execute }.not_to raise_error(Gitlab::Email::UserNotFoundError)
expect { receiver.execute }.not_to raise_error
end
end
end
Loading
Loading
Loading
Loading
@@ -24,7 +24,7 @@
let(:series) { 0 }
 
it 'does not raise error' do
expect { subject }.not_to raise_error(ArgumentError)
expect { subject }.not_to raise_error
end
end
end
Loading
Loading
Loading
Loading
@@ -177,9 +177,9 @@
expect(diff_two.diff).to include(Gitlab::EncodingHelper::UNICODE_REPLACEMENT_CHARACTER)
expect(diff_three.diff).to include(Gitlab::EncodingHelper::UNICODE_REPLACEMENT_CHARACTER)
 
expect { Oj.dump(diff) }.not_to raise_error(EncodingError)
expect { Oj.dump(diff_two) }.not_to raise_error(EncodingError)
expect { Oj.dump(diff_three) }.not_to raise_error(EncodingError)
expect { Oj.dump(diff) }.not_to raise_error
expect { Oj.dump(diff_two) }.not_to raise_error
expect { Oj.dump(diff_three) }.not_to raise_error
end
 
context 'when the diff is binary' do
Loading
Loading
Loading
Loading
@@ -103,7 +103,7 @@
it 'raises error' do
expect do
@klass.new.popen(%w[foobar])
end.to raise_error
end.to raise_error(Errno::ENOENT)
end
end
end
Loading
Loading
@@ -33,7 +33,7 @@ def write_metric(metric, path, content)
end
 
it 'has all definitions valid' do
expect { described_class.definitions }.not_to raise_error(Gitlab::Tracking::InvalidEventError)
expect { described_class.definitions }.not_to raise_error
end
 
describe '#validate' do
Loading
Loading
Loading
Loading
@@ -42,7 +42,7 @@
 
context 'when project namespace backfilling migration finished successfully' do
it 'does not raise exception' do
expect { migrate! }.not_to raise_error(/Expected batched background migration for the given configuration to be marked as 'finished'/)
expect { migrate! }.not_to raise_error
end
end
 
Loading
Loading
Loading
Loading
@@ -494,7 +494,7 @@
end
 
it 'does not raise kubeclient http error' do
expect { subject }.not_to raise_error(Kubeclient::HttpError)
expect { subject }.not_to raise_error
end
end
 
Loading
Loading
Loading
Loading
@@ -237,7 +237,7 @@ def self.from_cache(*args); end
end
 
it 'does not raise the exception' do
expect { go! }.not_to raise_exception(ReactiveCaching::ExceededReactiveCacheLimit)
expect { go! }.not_to raise_exception
end
end
 
Loading
Loading
Loading
Loading
@@ -621,7 +621,7 @@
expect(close_action.processed).to be_falsey
 
# it encounters the StaleObjectError at first, but reloads the object and runs `build.play`
expect { subject }.not_to raise_error(ActiveRecord::StaleObjectError)
expect { subject }.not_to raise_error
 
# Now the build should be processed.
expect(close_action.reload.processed).to be_truthy
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment