Commit 1b857a51 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'pl-rspec-enable-verify-double-constant-names' into 'master'

RSpec: Verify doubled constant names

See merge request gitlab-org/gitlab!74630
parents 4dac986c 9c60343c
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Security::PipelineVulnerabilitiesFinder do RSpec.describe Security::PipelineVulnerabilitiesFinder do
def disable_deduplication def disable_deduplication
allow(::Security::MergeReportsService).to receive(:new) do |*args| allow(::Security::MergeReportsService).to receive(:new) do |*args|
instance_double('NoDeduplicationMergeReportsService', execute: args.last) double('no_deduplication_service', execute: args.last)
end end
end end
......
...@@ -14,7 +14,7 @@ RSpec.describe EE::Gitlab::GonHelper do ...@@ -14,7 +14,7 @@ RSpec.describe EE::Gitlab::GonHelper do
end end
describe '#add_gon_variables' do describe '#add_gon_variables' do
let(:gon) { instance_double('gon').as_null_object } let(:gon) { double('gon').as_null_object }
before do before do
allow(helper).to receive(:gon).and_return(gon) allow(helper).to receive(:gon).and_return(gon)
...@@ -45,7 +45,7 @@ RSpec.describe EE::Gitlab::GonHelper do ...@@ -45,7 +45,7 @@ RSpec.describe EE::Gitlab::GonHelper do
shared_examples 'sets the licensed features flag' do shared_examples 'sets the licensed features flag' do
it 'pushes the licensed feature flag to the frotnend' do it 'pushes the licensed feature flag to the frotnend' do
gon = instance_double('gon') gon = class_double('Gon')
stub_licensed_features(feature => true) stub_licensed_features(feature => true)
allow(helper) allow(helper)
......
...@@ -9,9 +9,6 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do ...@@ -9,9 +9,6 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do
let(:fake_cache) { instance_double("Rack::Attack::Cache") } let(:fake_cache) { instance_double("Rack::Attack::Cache") }
before do 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(:throttled_response=)
allow(fake_rack_attack).to receive(:throttle) allow(fake_rack_attack).to receive(:throttle)
allow(fake_rack_attack).to receive(:track) allow(fake_rack_attack).to receive(:track)
...@@ -19,6 +16,9 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do ...@@ -19,6 +16,9 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do
allow(fake_rack_attack).to receive(:blocklist) allow(fake_rack_attack).to receive(:blocklist)
allow(fake_rack_attack).to receive(:cache).and_return(fake_cache) allow(fake_rack_attack).to receive(:cache).and_return(fake_cache)
allow(fake_cache).to receive(:store=) allow(fake_cache).to receive(:store=)
fake_rack_attack.const_set('Request', fake_rack_attack_request)
stub_const("Rack::Attack", fake_rack_attack)
end end
it 'adds the incident management throttle' do it 'adds the incident management throttle' do
......
...@@ -15,7 +15,7 @@ RSpec.describe GroupSaml::GroupManagedAccounts::TransferMembershipService do ...@@ -15,7 +15,7 @@ RSpec.describe GroupSaml::GroupManagedAccounts::TransferMembershipService do
allow(Gitlab::Auth::GroupSaml::IdentityLinker) allow(Gitlab::Auth::GroupSaml::IdentityLinker)
.to receive(:new).with(current_user, oauth_data, session, group.saml_provider) .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 end
it 'removes the current password' do it 'removes the current password' do
......
...@@ -14,7 +14,7 @@ RSpec.describe Namespaces::CheckStorageSizeService, '#execute' do ...@@ -14,7 +14,7 @@ RSpec.describe Namespaces::CheckStorageSizeService, '#execute' do
before do before do
allow(namespace).to receive(:root_ancestor).and_return(namespace) 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, current_size: current_size,
limit: limit, limit: limit,
usage_ratio: limit == 0 ? 0 : current_size.to_f / limit.to_f, usage_ratio: limit == 0 ? 0 : current_size.to_f / limit.to_f,
......
...@@ -29,10 +29,10 @@ RSpec.describe Banzai::ReferenceParser::BaseParser do ...@@ -29,10 +29,10 @@ RSpec.describe Banzai::ReferenceParser::BaseParser do
describe '#project_for_node' do describe '#project_for_node' do
it 'returns the Project for a node' do it 'returns the Project for a node' do
document = instance_double('document', fragment?: false) document = double('document', fragment?: false)
project = instance_double('project') project = instance_double('Project')
object = instance_double('object', project: project) object = double('object', project: project)
node = instance_double('node', document: document) node = double('node', document: document)
context.associate_document(document, object) context.associate_document(document, object)
......
...@@ -7,15 +7,15 @@ RSpec.describe Banzai::RenderContext do ...@@ -7,15 +7,15 @@ RSpec.describe Banzai::RenderContext do
describe '#project_for_node' do describe '#project_for_node' do
it 'returns the default project if no associated project was found' 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) context = described_class.new(project)
expect(context.project_for_node(document)).to eq(project) expect(context.project_for_node(document)).to eq(project)
end end
it 'returns the associated project if one was associated explicitly' do it 'returns the associated project if one was associated explicitly' do
project = instance_double('project') project = instance_double('Project')
obj = instance_double('object', project: project) obj = double('object', project: project)
context = described_class.new context = described_class.new
context.associate_document(document, obj) context.associate_document(document, obj)
...@@ -24,8 +24,8 @@ RSpec.describe Banzai::RenderContext do ...@@ -24,8 +24,8 @@ RSpec.describe Banzai::RenderContext do
end end
it 'returns the project associated with a DocumentFragment when using a node' do it 'returns the project associated with a DocumentFragment when using a node' do
project = instance_double('project') project = instance_double('Project')
obj = instance_double('object', project: project) obj = double('object', project: project)
context = described_class.new context = described_class.new
node = document.children.first node = document.children.first
......
...@@ -97,7 +97,7 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do ...@@ -97,7 +97,7 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
describe '#push_frontend_experiment' do describe '#push_frontend_experiment' do
it 'pushes an experiment to the frontend' do it 'pushes an experiment to the frontend' do
gon = instance_double('gon') gon = class_double('Gon')
stub_experiment_for_subject(my_experiment: true) stub_experiment_for_subject(my_experiment: true)
allow(controller).to receive(:gon).and_return(gon) allow(controller).to receive(:gon).and_return(gon)
......
...@@ -110,7 +110,7 @@ RSpec.describe Gitlab::Git::RuggedImpl::UseRugged, :seed_helper do ...@@ -110,7 +110,7 @@ RSpec.describe Gitlab::Git::RuggedImpl::UseRugged, :seed_helper do
describe '#running_puma_with_multiple_threads?' do describe '#running_puma_with_multiple_threads?' do
context 'when using Puma' do context 'when using Puma' do
before do before do
stub_const('::Puma', class_double('Puma')) stub_const('::Puma', double('puma constant'))
allow(Gitlab::Runtime).to receive(:puma?).and_return(true) allow(Gitlab::Runtime).to receive(:puma?).and_return(true)
end end
......
...@@ -15,7 +15,7 @@ RSpec.describe Gitlab::GonHelper do ...@@ -15,7 +15,7 @@ RSpec.describe Gitlab::GonHelper do
end end
it 'pushes a feature flag to the frontend' do it 'pushes a feature flag to the frontend' do
gon = instance_double('gon') gon = class_double('Gon')
thing = stub_feature_flag_gate('thing') thing = stub_feature_flag_gate('thing')
stub_feature_flags(my_feature_flag: thing) stub_feature_flags(my_feature_flag: thing)
......
...@@ -73,7 +73,7 @@ RSpec.describe ::Gitlab::LetsEncrypt::Client do ...@@ -73,7 +73,7 @@ RSpec.describe ::Gitlab::LetsEncrypt::Client do
subject(:new_order) { client.new_order('example.com') } subject(:new_order) { client.new_order('example.com') }
before do before do
order_double = instance_double('Acme::Order') order_double = double('Acme::Order')
allow(stub_client).to receive(:new_order).and_return(order_double) allow(stub_client).to receive(:new_order).and_return(order_double)
end end
...@@ -107,7 +107,7 @@ RSpec.describe ::Gitlab::LetsEncrypt::Client do ...@@ -107,7 +107,7 @@ RSpec.describe ::Gitlab::LetsEncrypt::Client do
subject { client.load_challenge(url) } subject { client.load_challenge(url) }
before do 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) allow(stub_client).to receive(:challenge).with(url: url).and_return(acme_challenge)
end end
......
...@@ -5,8 +5,8 @@ require 'spec_helper' ...@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec.describe Gitlab::RackAttack, :aggregate_failures do RSpec.describe Gitlab::RackAttack, :aggregate_failures do
describe '.configure' do describe '.configure' do
let(:fake_rack_attack) { class_double("Rack::Attack") } let(:fake_rack_attack) { class_double("Rack::Attack") }
let(:fake_rack_attack_request) { class_double("Rack::Attack::Request") } let(:fake_rack_attack_request) { class_double(Rack::Attack::Request) }
let(:fake_cache) { instance_double("Rack::Attack::Cache") } let(:fake_cache) { instance_double(Rack::Attack::Cache) }
let(:throttles) do let(:throttles) do
{ {
...@@ -27,9 +27,6 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do ...@@ -27,9 +27,6 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do
end end
before do 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(:throttled_response=)
allow(fake_rack_attack).to receive(:throttle) allow(fake_rack_attack).to receive(:throttle)
allow(fake_rack_attack).to receive(:track) allow(fake_rack_attack).to receive(:track)
...@@ -37,6 +34,9 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do ...@@ -37,6 +34,9 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do
allow(fake_rack_attack).to receive(:blocklist) allow(fake_rack_attack).to receive(:blocklist)
allow(fake_rack_attack).to receive(:cache).and_return(fake_cache) allow(fake_rack_attack).to receive(:cache).and_return(fake_cache)
allow(fake_cache).to receive(:store=) allow(fake_cache).to receive(:store=)
fake_rack_attack.const_set('Request', fake_rack_attack_request)
stub_const("Rack::Attack", fake_rack_attack)
end end
it 'extends the request class' do it 'extends the request class' do
......
...@@ -111,7 +111,7 @@ RSpec.describe DeploymentMetrics do ...@@ -111,7 +111,7 @@ RSpec.describe DeploymentMetrics do
} }
end 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 before do
allow(deployment_metrics).to receive(:prometheus_adapter).and_return(prometheus_adapter) allow(deployment_metrics).to receive(:prometheus_adapter).and_return(prometheus_adapter)
......
...@@ -53,7 +53,7 @@ RSpec.describe "deleting designs" do ...@@ -53,7 +53,7 @@ RSpec.describe "deleting designs" do
context 'the designs list contains filenames we cannot find' do context 'the designs list contains filenames we cannot find' do
it_behaves_like 'a failed request' 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/ } let(:the_error) { a_string_matching %r/filenames were not found/ }
end end
end end
......
...@@ -58,7 +58,7 @@ RSpec.describe Clusters::Integrations::PrometheusHealthCheckService, '#execute' ...@@ -58,7 +58,7 @@ RSpec.describe Clusters::Integrations::PrometheusHealthCheckService, '#execute'
let(:prometheus_enabled) { true } let(:prometheus_enabled) { true }
before do 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) expect(prometheus).to receive(:prometheus_client).and_return(client)
end end
......
...@@ -151,7 +151,7 @@ RSpec.describe MergeRequests::MergeService do ...@@ -151,7 +151,7 @@ RSpec.describe MergeRequests::MergeService do
it 'closes GitLab issue tracker issues' do it 'closes GitLab issue tracker issues' do
issue = create :issue, project: project 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]) allow(merge_request).to receive(:commits).and_return([commit])
merge_request.cache_merge_request_closes_issues! merge_request.cache_merge_request_closes_issues!
......
...@@ -15,7 +15,10 @@ require 'rubocop' ...@@ -15,7 +15,10 @@ require 'rubocop'
require 'rubocop/rspec/support' require 'rubocop/rspec/support'
RSpec.configure do |config| 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.raise_errors_for_deprecations!
config.include StubConfiguration 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