Commit 68c6fea8 authored by Ryan Cobb's avatar Ryan Cobb

Fixes for RSpec/LeakyConstantDeclaration

Additional fixes for RSpec/LeakyConstantDeclaration cop.
parent c4c22b06
...@@ -330,13 +330,6 @@ RSpec/LeakyConstantDeclaration: ...@@ -330,13 +330,6 @@ RSpec/LeakyConstantDeclaration:
Exclude: Exclude:
- 'spec/**/*.rb' - 'spec/**/*.rb'
- 'qa/spec/**/*.rb' - 'qa/spec/**/*.rb'
- 'ee/spec/lib/gitlab/geo/log_cursor/logger_spec.rb'
- 'ee/spec/lib/gitlab/geo/log_helpers_spec.rb'
- 'ee/spec/lib/gitlab/geo/replicator_spec.rb'
- 'ee/spec/mailers/emails/service_desk_spec.rb'
- 'ee/spec/migrations/remove_creations_in_gitlab_subscription_histories_spec.rb'
- 'ee/spec/migrations/set_resolved_state_on_vulnerabilities_spec.rb'
- 'ee/spec/models/repository_spec.rb'
- 'ee/spec/presenters/security/vulnerable_project_presenter_spec.rb' - 'ee/spec/presenters/security/vulnerable_project_presenter_spec.rb'
- 'ee/spec/serializers/vulnerable_project_entity_spec.rb' - 'ee/spec/serializers/vulnerable_project_entity_spec.rb'
- 'ee/spec/services/clusters/applications/check_upgrade_progress_service_spec.rb' - 'ee/spec/services/clusters/applications/check_upgrade_progress_service_spec.rb'
......
...@@ -3,13 +3,12 @@ ...@@ -3,13 +3,12 @@
require 'spec_helper' require 'spec_helper'
describe Gitlab::Geo::LogCursor::Logger, :geo do describe Gitlab::Geo::LogCursor::Logger, :geo do
class LoggerSpec; end
subject(:logger) { described_class.new(LoggerSpec) } subject(:logger) { described_class.new(LoggerSpec) }
let(:data) { { pid: 111, class: 'LoggerSpec', host: 'localhost', message: 'Test' } } let(:data) { { pid: 111, class: 'LoggerSpec', host: 'localhost', message: 'Test' } }
before do before do
stub_const('LoggerSpec', Class.new)
stub_const("#{described_class.name}::PID", 111) stub_const("#{described_class.name}::PID", 111)
end end
......
...@@ -3,11 +3,15 @@ ...@@ -3,11 +3,15 @@
require 'spec_helper' require 'spec_helper'
describe Gitlab::Geo::LogHelpers do describe Gitlab::Geo::LogHelpers do
class FakeLogHelpersConsumer before do
include Gitlab::Geo::LogHelpers stub_const('FakeLogHelpersConsumer', Class.new)
def execute FakeLogHelpersConsumer.class_eval do
log_error('Test message') include Gitlab::Geo::LogHelpers
def execute
log_error('Test message')
end
end end
end end
......
...@@ -4,14 +4,18 @@ require 'spec_helper' ...@@ -4,14 +4,18 @@ require 'spec_helper'
describe Gitlab::Geo::Replicator do describe Gitlab::Geo::Replicator do
context 'with defined events' do context 'with defined events' do
class DummyReplicator < Gitlab::Geo::Replicator before do
event :test stub_const('DummyReplicator', Class.new(Gitlab::Geo::Replicator))
event :another_test
protected DummyReplicator.class_eval do
event :test
event :another_test
def publish_test(other:) protected
true
def publish_test(other:)
true
end
end end
end end
...@@ -36,15 +40,19 @@ describe Gitlab::Geo::Replicator do ...@@ -36,15 +40,19 @@ describe Gitlab::Geo::Replicator do
end end
context 'model DSL' do context 'model DSL' do
class DummyModel before do
include ActiveModel::Model stub_const('DummyModel', Class.new)
def self.after_create_commit(*args) DummyModel.class_eval do
end include ActiveModel::Model
include Gitlab::Geo::ReplicableModel def self.after_create_commit(*args)
end
with_replicator DummyReplicator include Gitlab::Geo::ReplicableModel
with_replicator DummyReplicator
end
end end
subject { DummyModel.new } subject { DummyModel.new }
......
...@@ -15,39 +15,43 @@ describe Emails::ServiceDesk do ...@@ -15,39 +15,43 @@ describe Emails::ServiceDesk do
let_it_be(:issue) { create(:issue, project: project) } let_it_be(:issue) { create(:issue, project: project) }
let(:template) { double(content: template_content) } let(:template) { double(content: template_content) }
class ServiceEmailClass < ApplicationMailer before do
include GitlabRoutingHelper stub_const('ServiceEmailClass', Class.new(ApplicationMailer))
include EmailsHelper
include Emails::ServiceDesk
helper GitlabRoutingHelper ServiceEmailClass.class_eval do
helper EmailsHelper include GitlabRoutingHelper
include EmailsHelper
include Emails::ServiceDesk
append_view_path Rails.root.join('ee', 'app', 'views', 'notify') helper GitlabRoutingHelper
helper EmailsHelper
# this method is implemented in Notify class, we don't need to test it append_view_path Rails.root.join('ee', 'app', 'views', 'notify')
def reply_key
'test-key'
end
# this method is implemented in Notify class, we don't need to test it # this method is implemented in Notify class, we don't need to test it
def sender(author_id, params = {}) def reply_key
author_id 'test-key'
end end
# this method is implemented in Notify class # this method is implemented in Notify class, we don't need to test it
# def sender(author_id, params = {})
# We do not need to test the Notify method, it is already tested in notify_spec author_id
def mail_new_thread(issue, options) end
# we need to rewrite this in order to look up templates in the correct directory
self.class.mailer_name = 'notify' # this method is implemented in Notify class
#
# We do not need to test the Notify method, it is already tested in notify_spec
def mail_new_thread(issue, options)
# we need to rewrite this in order to look up templates in the correct directory
self.class.mailer_name = 'notify'
# this is needed for default layout # this is needed for default layout
@unsubscribe_url = 'http://unsubscribe.example.com' @unsubscribe_url = 'http://unsubscribe.example.com'
mail(options) mail(options)
end
alias_method :mail_answer_thread, :mail_new_thread
end end
alias_method :mail_answer_thread, :mail_new_thread
end end
shared_examples 'handle template content' do |template_key| shared_examples 'handle template content' do |template_key|
......
...@@ -4,9 +4,11 @@ require 'spec_helper' ...@@ -4,9 +4,11 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200113151354_remove_creations_in_gitlab_subscription_histories.rb') require Rails.root.join('db', 'post_migrate', '20200113151354_remove_creations_in_gitlab_subscription_histories.rb')
describe RemoveCreationsInGitlabSubscriptionHistories do describe RemoveCreationsInGitlabSubscriptionHistories do
GITLAB_SUBSCRIPTION_CREATED = 0 before do
GITLAB_SUBSCRIPTION_UPDATED = 1 stub_const('GITLAB_SUBSCRIPTION_CREATED', 0)
GITLAB_SUBSCRIPTION_DESTROYED = 2 stub_const('GITLAB_SUBSCRIPTION_UPDATED', 1)
stub_const('GITLAB_SUBSCRIPTION_DESTROYED', 2)
end
let(:gitlab_subscriptions) { table(:gitlab_subscriptions) } let(:gitlab_subscriptions) { table(:gitlab_subscriptions) }
let(:gitlab_subscription_histories) { table(:gitlab_subscription_histories) } let(:gitlab_subscription_histories) { table(:gitlab_subscription_histories) }
......
...@@ -4,8 +4,6 @@ require 'spec_helper' ...@@ -4,8 +4,6 @@ require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20191114173624_set_resolved_state_on_vulnerabilities.rb') require Rails.root.join('db', 'post_migrate', '20191114173624_set_resolved_state_on_vulnerabilities.rb')
describe SetResolvedStateOnVulnerabilities do describe SetResolvedStateOnVulnerabilities do
PACK_FORMAT = 'H*'
let(:confidence_levels) do let(:confidence_levels) do
{ undefined: 0, ignore: 1, unknown: 2, experimental: 3, low: 4, medium: 5, high: 6, confirmed: 7 } { undefined: 0, ignore: 1, unknown: 2, experimental: 3, low: 4, medium: 5, high: 6, confirmed: 7 }
end end
...@@ -47,6 +45,8 @@ describe SetResolvedStateOnVulnerabilities do ...@@ -47,6 +45,8 @@ describe SetResolvedStateOnVulnerabilities do
end end
before do before do
stub_const('PACK_FORMAT', 'H*')
author = users.create!(id: 1, email: 'author@example.com', projects_limit: 10) author = users.create!(id: 1, email: 'author@example.com', projects_limit: 10)
closer = users.create!(id: closer_id, email: 'closer@example.com', projects_limit: 10) closer = users.create!(id: closer_id, email: 'closer@example.com', projects_limit: 10)
namespace = namespaces.create!(id: 1, name: 'namespace_1', path: 'namespace_1', owner_id: author.id) namespace = namespaces.create!(id: 1, name: 'namespace_1', path: 'namespace_1', owner_id: author.id)
......
...@@ -7,7 +7,9 @@ describe Repository do ...@@ -7,7 +7,9 @@ describe Repository do
include ::EE::GeoHelpers include ::EE::GeoHelpers
include GitHelpers include GitHelpers
TestBlob = Struct.new(:path) before do
stub_const('TestBlob', Struct.new(:path))
end
let_it_be(:primary_node) { create(:geo_node, :primary) } let_it_be(:primary_node) { create(:geo_node, :primary) }
let_it_be(:secondary_node) { create(:geo_node) } let_it_be(:secondary_node) { create(:geo_node) }
......
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