Commit 9c60343c authored by Peter Leitzen's avatar Peter Leitzen

RSpec: Verify doubled constant names by default

See https://bit.ly/3CyeyNP

This commit also fixes cases where verification of constants failed by
either using `double` or fixing the stubbed constant name.
parent 45ab9d9b
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Security::PipelineVulnerabilitiesFinder do
def disable_deduplication
allow(::Security::MergeReportsService).to receive(:new) do |*args|
instance_double('NoDeduplicationMergeReportsService', execute: args.last)
double('no_deduplication_service', execute: args.last)
end
end
......
......@@ -14,7 +14,7 @@ RSpec.describe EE::Gitlab::GonHelper do
end
describe '#add_gon_variables' do
let(:gon) { instance_double('gon').as_null_object }
let(:gon) { double('gon').as_null_object }
before do
allow(helper).to receive(:gon).and_return(gon)
......@@ -45,7 +45,7 @@ RSpec.describe EE::Gitlab::GonHelper do
shared_examples 'sets the licensed features flag' do
it 'pushes the licensed feature flag to the frotnend' do
gon = instance_double('gon')
gon = class_double('Gon')
stub_licensed_features(feature => true)
allow(helper)
......
......@@ -9,9 +9,6 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do
let(:fake_cache) { instance_double("Rack::Attack::Cache") }
before do
stub_const("Rack::Attack", fake_rack_attack)
stub_const("Rack::Attack::Request", fake_rack_attack_request)
allow(fake_rack_attack).to receive(:throttled_response=)
allow(fake_rack_attack).to receive(:throttle)
allow(fake_rack_attack).to receive(:track)
......@@ -19,6 +16,9 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do
allow(fake_rack_attack).to receive(:blocklist)
allow(fake_rack_attack).to receive(:cache).and_return(fake_cache)
allow(fake_cache).to receive(:store=)
fake_rack_attack.const_set('Request', fake_rack_attack_request)
stub_const("Rack::Attack", fake_rack_attack)
end
it 'adds the incident management throttle' do
......
......@@ -15,7 +15,7 @@ RSpec.describe GroupSaml::GroupManagedAccounts::TransferMembershipService do
allow(Gitlab::Auth::GroupSaml::IdentityLinker)
.to receive(:new).with(current_user, oauth_data, session, group.saml_provider)
.and_return(instance_double('GitLab::Auth::GroupSaml::IdentityLinker', link: '', failed?: false))
.and_return(instance_double('Gitlab::Auth::GroupSaml::IdentityLinker', link: '', failed?: false))
end
it 'removes the current password' do
......
......@@ -14,7 +14,7 @@ RSpec.describe Namespaces::CheckStorageSizeService, '#execute' do
before do
allow(namespace).to receive(:root_ancestor).and_return(namespace)
root_storage_size = instance_double("RootStorageSize",
root_storage_size = instance_double(EE::Namespace::RootStorageSize,
current_size: current_size,
limit: limit,
usage_ratio: limit == 0 ? 0 : current_size.to_f / limit.to_f,
......
......@@ -29,10 +29,10 @@ RSpec.describe Banzai::ReferenceParser::BaseParser do
describe '#project_for_node' do
it 'returns the Project for a node' do
document = instance_double('document', fragment?: false)
project = instance_double('project')
object = instance_double('object', project: project)
node = instance_double('node', document: document)
document = double('document', fragment?: false)
project = instance_double('Project')
object = double('object', project: project)
node = double('node', document: document)
context.associate_document(document, object)
......
......@@ -7,15 +7,15 @@ RSpec.describe Banzai::RenderContext do
describe '#project_for_node' do
it 'returns the default project if no associated project was found' do
project = instance_double('project')
project = instance_double('Project')
context = described_class.new(project)
expect(context.project_for_node(document)).to eq(project)
end
it 'returns the associated project if one was associated explicitly' do
project = instance_double('project')
obj = instance_double('object', project: project)
project = instance_double('Project')
obj = double('object', project: project)
context = described_class.new
context.associate_document(document, obj)
......@@ -24,8 +24,8 @@ RSpec.describe Banzai::RenderContext do
end
it 'returns the project associated with a DocumentFragment when using a node' do
project = instance_double('project')
obj = instance_double('object', project: project)
project = instance_double('Project')
obj = double('object', project: project)
context = described_class.new
node = document.children.first
......
......@@ -97,7 +97,7 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
describe '#push_frontend_experiment' do
it 'pushes an experiment to the frontend' do
gon = instance_double('gon')
gon = class_double('Gon')
stub_experiment_for_subject(my_experiment: true)
allow(controller).to receive(:gon).and_return(gon)
......
......@@ -110,7 +110,7 @@ RSpec.describe Gitlab::Git::RuggedImpl::UseRugged, :seed_helper do
describe '#running_puma_with_multiple_threads?' do
context 'when using Puma' do
before do
stub_const('::Puma', class_double('Puma'))
stub_const('::Puma', double('puma constant'))
allow(Gitlab::Runtime).to receive(:puma?).and_return(true)
end
......
......@@ -15,7 +15,7 @@ RSpec.describe Gitlab::GonHelper do
end
it 'pushes a feature flag to the frontend' do
gon = instance_double('gon')
gon = class_double('Gon')
thing = stub_feature_flag_gate('thing')
stub_feature_flags(my_feature_flag: thing)
......
......@@ -73,7 +73,7 @@ RSpec.describe ::Gitlab::LetsEncrypt::Client do
subject(:new_order) { client.new_order('example.com') }
before do
order_double = instance_double('Acme::Order')
order_double = double('Acme::Order')
allow(stub_client).to receive(:new_order).and_return(order_double)
end
......@@ -107,7 +107,7 @@ RSpec.describe ::Gitlab::LetsEncrypt::Client do
subject { client.load_challenge(url) }
before do
acme_challenge = instance_double('Acme::Client::Resources::Challenge')
acme_challenge = double('Acme::Client::Resources::Challenge')
allow(stub_client).to receive(:challenge).with(url: url).and_return(acme_challenge)
end
......
......@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec.describe Gitlab::RackAttack, :aggregate_failures do
describe '.configure' do
let(:fake_rack_attack) { class_double("Rack::Attack") }
let(:fake_rack_attack_request) { class_double("Rack::Attack::Request") }
let(:fake_cache) { instance_double("Rack::Attack::Cache") }
let(:fake_rack_attack_request) { class_double(Rack::Attack::Request) }
let(:fake_cache) { instance_double(Rack::Attack::Cache) }
let(:throttles) do
{
......@@ -27,9 +27,6 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do
end
before do
stub_const("Rack::Attack", fake_rack_attack)
stub_const("Rack::Attack::Request", fake_rack_attack_request)
allow(fake_rack_attack).to receive(:throttled_response=)
allow(fake_rack_attack).to receive(:throttle)
allow(fake_rack_attack).to receive(:track)
......@@ -37,6 +34,9 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do
allow(fake_rack_attack).to receive(:blocklist)
allow(fake_rack_attack).to receive(:cache).and_return(fake_cache)
allow(fake_cache).to receive(:store=)
fake_rack_attack.const_set('Request', fake_rack_attack_request)
stub_const("Rack::Attack", fake_rack_attack)
end
it 'extends the request class' do
......
......@@ -111,7 +111,7 @@ RSpec.describe DeploymentMetrics do
}
end
let(:prometheus_adapter) { instance_double('prometheus_adapter', can_query?: true, configured?: true) }
let(:prometheus_adapter) { instance_double(::Integrations::Prometheus, can_query?: true, configured?: true) }
before do
allow(deployment_metrics).to receive(:prometheus_adapter).and_return(prometheus_adapter)
......
......@@ -53,7 +53,7 @@ RSpec.describe "deleting designs" do
context 'the designs list contains filenames we cannot find' do
it_behaves_like 'a failed request' do
let(:designs) { %w/foo bar baz/.map { |fn| instance_double('file', filename: fn) } }
let(:designs) { %w/foo bar baz/.map { |fn| double('file', filename: fn) } }
let(:the_error) { a_string_matching %r/filenames were not found/ }
end
end
......
......@@ -58,7 +58,7 @@ RSpec.describe Clusters::Integrations::PrometheusHealthCheckService, '#execute'
let(:prometheus_enabled) { true }
before do
client = instance_double('PrometheusClient', healthy?: client_healthy)
client = instance_double('Gitlab::PrometheusClient', healthy?: client_healthy)
expect(prometheus).to receive(:prometheus_client).and_return(client)
end
......
......@@ -151,7 +151,7 @@ RSpec.describe MergeRequests::MergeService do
it 'closes GitLab issue tracker issues' do
issue = create :issue, project: project
commit = instance_double('commit', safe_message: "Fixes #{issue.to_reference}", date: Time.current, authored_date: Time.current)
commit = double('commit', safe_message: "Fixes #{issue.to_reference}", date: Time.current, authored_date: Time.current)
allow(merge_request).to receive(:commits).and_return([commit])
merge_request.cache_merge_request_closes_issues!
......
......@@ -15,7 +15,10 @@ require 'rubocop'
require 'rubocop/rspec/support'
RSpec.configure do |config|
config.mock_with :rspec
config.mock_with :rspec do |mocks|
mocks.verify_doubled_constant_names = true
end
config.raise_errors_for_deprecations!
config.include StubConfiguration
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment