summaryrefslogtreecommitdiff
path: root/spec/rubocop
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/rubocop
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
downloadgitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/gitlab/bulk_insert_spec.rb12
-rw-r--r--spec/rubocop/cop/gitlab/json_spec.rb15
-rw-r--r--spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb6
-rw-r--r--spec/rubocop/cop/graphql/descriptions_spec.rb118
-rw-r--r--spec/rubocop/cop/graphql/id_type_spec.rb10
-rw-r--r--spec/rubocop/cop/graphql/json_type_spec.rb4
-rw-r--r--spec/rubocop/cop/graphql/old_types_spec.rb84
-rw-r--r--spec/rubocop/cop/ignored_columns_spec.rb78
-rw-r--r--spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb1
-rw-r--r--spec/rubocop/cop/qa/selector_usage_spec.rb49
10 files changed, 341 insertions, 36 deletions
diff --git a/spec/rubocop/cop/gitlab/bulk_insert_spec.rb b/spec/rubocop/cop/gitlab/bulk_insert_spec.rb
index 7c60518f890..bbc8f381d01 100644
--- a/spec/rubocop/cop/gitlab/bulk_insert_spec.rb
+++ b/spec/rubocop/cop/gitlab/bulk_insert_spec.rb
@@ -6,17 +6,17 @@ require_relative '../../../../rubocop/cop/gitlab/bulk_insert'
RSpec.describe RuboCop::Cop::Gitlab::BulkInsert do
subject(:cop) { described_class.new }
- it 'flags the use of Gitlab::Database.bulk_insert' do
+ it 'flags the use of Gitlab::Database.main.bulk_insert' do
expect_offense(<<~SOURCE)
- Gitlab::Database.bulk_insert('merge_request_diff_files', rows)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use the `BulkInsertSafe` concern, [...]
+ Gitlab::Database.main.bulk_insert('merge_request_diff_files', rows)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use the `BulkInsertSafe` concern, [...]
SOURCE
end
- it 'flags the use of ::Gitlab::Database.bulk_insert' do
+ it 'flags the use of ::Gitlab::Database.main.bulk_insert' do
expect_offense(<<~SOURCE)
- ::Gitlab::Database.bulk_insert('merge_request_diff_files', rows)
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use the `BulkInsertSafe` concern, [...]
+ ::Gitlab::Database.main.bulk_insert('merge_request_diff_files', rows)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use the `BulkInsertSafe` concern, [...]
SOURCE
end
end
diff --git a/spec/rubocop/cop/gitlab/json_spec.rb b/spec/rubocop/cop/gitlab/json_spec.rb
index 66b2c675e80..7998f26da4e 100644
--- a/spec/rubocop/cop/gitlab/json_spec.rb
+++ b/spec/rubocop/cop/gitlab/json_spec.rb
@@ -6,7 +6,7 @@ require_relative '../../../../rubocop/cop/gitlab/json'
RSpec.describe RuboCop::Cop::Gitlab::Json do
subject(:cop) { described_class.new }
- context 'when JSON is called' do
+ context 'when ::JSON is called' do
it 'registers an offense' do
expect_offense(<<~RUBY)
class Foo
@@ -18,4 +18,17 @@ RSpec.describe RuboCop::Cop::Gitlab::Json do
RUBY
end
end
+
+ context 'when ActiveSupport::JSON is called' do
+ it 'registers an offense' do
+ expect_offense(<<~RUBY)
+ class Foo
+ def bar
+ ActiveSupport::JSON.parse('{ "foo": "bar" }')
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `JSON` directly. [...]
+ end
+ end
+ RUBY
+ end
+ end
end
diff --git a/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb b/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb
index 968cafc57d4..35b21477d80 100644
--- a/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb
+++ b/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb
@@ -194,6 +194,10 @@ RSpec.describe RuboCop::Cop::Gitlab::MarkUsedFeatureFlags do
include_examples 'sets flag as used', 'self.limit_feature_flag = :foo', 'foo'
end
+ describe 'self.limit_feature_flag_for_override = :foo' do
+ include_examples 'sets flag as used', 'self.limit_feature_flag_for_override = :foo', 'foo'
+ end
+
describe 'FEATURE_FLAG = :foo' do
include_examples 'sets flag as used', 'FEATURE_FLAG = :foo', 'foo'
end
@@ -218,7 +222,7 @@ RSpec.describe RuboCop::Cop::Gitlab::MarkUsedFeatureFlags do
include_examples 'does not set any flags as used', 'field :solution'
include_examples 'does not set any flags as used', 'field :runners, Types::Ci::RunnerType.connection_type'
include_examples 'does not set any flags as used', 'field :runners, Types::Ci::RunnerType.connection_type, null: true, description: "hello world"'
- include_examples 'does not set any flags as used', 'field :solution, type: GraphQL::STRING_TYPE, null: true, description: "URL to the vulnerabilitys details page."'
+ include_examples 'does not set any flags as used', 'field :solution, type: GraphQL::Types::String, null: true, description: "URL to the vulnerabilitys details page."'
end
describe "tracking of usage data metrics known events happens at the beginning of inspection" do
diff --git a/spec/rubocop/cop/graphql/descriptions_spec.rb b/spec/rubocop/cop/graphql/descriptions_spec.rb
index 9709a253bdc..84520a89b08 100644
--- a/spec/rubocop/cop/graphql/descriptions_spec.rb
+++ b/spec/rubocop/cop/graphql/descriptions_spec.rb
@@ -12,8 +12,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
field :a_thing,
- ^^^^^^^^^^^^^^^ Please add a `description` property.
- GraphQL::STRING_TYPE,
+ ^^^^^^^^^^^^^^^ #{described_class::MSG_NO_DESCRIPTION}
+ GraphQL::Types::String,
null: false
end
end
@@ -25,10 +25,38 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
field :a_thing,
- ^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
- GraphQL::STRING_TYPE,
+ ^^^^^^^^^^^^^^^ #{described_class::MSG_NO_PERIOD}
+ GraphQL::Types::String,
null: false,
- description: 'A descriptive description'
+ description: 'Description of a thing'
+ end
+ end
+ TYPE
+ end
+
+ it 'adds an offense when description begins with "A"' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ ^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START}
+ GraphQL::Types::String,
+ null: false,
+ description: 'A description of the thing.'
+ end
+ end
+ TYPE
+ end
+
+ it 'adds an offense when description begins with "The"' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ ^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START}
+ GraphQL::Types::String,
+ null: false,
+ description: 'The description of the thing.'
end
end
TYPE
@@ -39,9 +67,9 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
field :a_thing,
- GraphQL::STRING_TYPE,
+ GraphQL::Types::String,
null: false,
- description: 'A descriptive description.'
+ description: 'Description of a thing.'
end
end
TYPE
@@ -64,8 +92,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
argument :a_thing,
- ^^^^^^^^^^^^^^^^^^ Please add a `description` property.
- GraphQL::STRING_TYPE,
+ ^^^^^^^^^^^^^^^^^^ #{described_class::MSG_NO_DESCRIPTION}
+ GraphQL::Types::String,
null: false
end
end
@@ -77,8 +105,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
argument :a_thing,
- ^^^^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
- GraphQL::STRING_TYPE,
+ ^^^^^^^^^^^^^^^^^^ #{described_class::MSG_NO_PERIOD}
+ GraphQL::Types::String,
null: false,
description: 'Behold! A description'
end
@@ -86,12 +114,40 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
TYPE
end
+ it 'adds an offense when description begins with "A"' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ argument :a_thing,
+ ^^^^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START}
+ GraphQL::Types::String,
+ null: false,
+ description: 'A description.'
+ end
+ end
+ TYPE
+ end
+
+ it 'adds an offense when description begins with "The"' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ argument :a_thing,
+ ^^^^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START}
+ GraphQL::Types::String,
+ null: false,
+ description: 'The description.'
+ end
+ end
+ TYPE
+ end
+
it 'does not add an offense when description is correct' do
expect_no_offenses(<<~TYPE.strip)
module Types
class FakeType < BaseObject
argument :a_thing,
- GraphQL::STRING_TYPE,
+ GraphQL::Types::String,
null: false,
description: 'Behold! A description.'
end
@@ -106,7 +162,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeEnum < BaseEnum
value 'FOO', value: 'foo'
- ^^^^^^^^^^^^^^^^^^^^^^^^^ Please add a `description` property.
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG_NO_DESCRIPTION}
end
end
TYPE
@@ -117,7 +173,29 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeEnum < BaseEnum
value 'FOO', value: 'foo', description: 'bar'
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG_NO_PERIOD}
+ end
+ end
+ TYPE
+ end
+
+ it 'adds an offense when description begins with "The"' do
+ expect_offense(<<~TYPE.strip)
+ module Types
+ class FakeEnum < BaseEnum
+ value 'FOO', value: 'foo', description: 'The description.'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START}
+ end
+ end
+ TYPE
+ end
+
+ it 'adds an offense when description begins with "A"' do
+ expect_offense(<<~TYPE.strip)
+ module Types
+ class FakeEnum < BaseEnum
+ value 'FOO', value: 'foo', description: 'A description.'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START}
end
end
TYPE
@@ -150,8 +228,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
field :a_thing,
- ^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
- GraphQL::STRING_TYPE,
+ ^^^^^^^^^^^^^^^ #{described_class::MSG_NO_PERIOD}
+ GraphQL::Types::String,
null: false,
description: 'Behold! A description'
end
@@ -162,7 +240,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
field :a_thing,
- GraphQL::STRING_TYPE,
+ GraphQL::Types::String,
null: false,
description: 'Behold! A description.'
end
@@ -175,8 +253,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
field :a_thing,
- ^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
- GraphQL::STRING_TYPE,
+ ^^^^^^^^^^^^^^^ #{described_class::MSG_NO_PERIOD}
+ GraphQL::Types::String,
null: false,
description: <<~DESC
Behold! A description
@@ -189,7 +267,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
module Types
class FakeType < BaseObject
field :a_thing,
- GraphQL::STRING_TYPE,
+ GraphQL::Types::String,
null: false,
description: <<~DESC
Behold! A description.
diff --git a/spec/rubocop/cop/graphql/id_type_spec.rb b/spec/rubocop/cop/graphql/id_type_spec.rb
index a566488b118..d71031c6e1a 100644
--- a/spec/rubocop/cop/graphql/id_type_spec.rb
+++ b/spec/rubocop/cop/graphql/id_type_spec.rb
@@ -7,10 +7,10 @@ require_relative '../../../../rubocop/cop/graphql/id_type'
RSpec.describe RuboCop::Cop::Graphql::IDType do
subject(:cop) { described_class.new }
- it 'adds an offense when GraphQL::ID_TYPE is used as a param to #argument' do
+ it 'adds an offense when GraphQL::Types::ID is used as a param to #argument' do
expect_offense(<<~TYPE)
- argument :some_arg, GraphQL::ID_TYPE, some: other, params: do_not_matter
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use GraphQL::ID_TYPE, use a specific GlobalIDType instead
+ argument :some_arg, GraphQL::Types::ID, some: other, params: do_not_matter
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use GraphQL::Types::ID, use a specific GlobalIDType instead
TYPE
end
@@ -18,13 +18,13 @@ RSpec.describe RuboCop::Cop::Graphql::IDType do
RuboCop::Cop::Graphql::IDType::WHITELISTED_ARGUMENTS.each do |arg|
it "does not add an offense for calls to #argument with #{arg} as argument name" do
expect_no_offenses(<<~TYPE.strip)
- argument #{arg}, GraphQL::ID_TYPE, some: other, params: do_not_matter
+ argument #{arg}, GraphQL::Types::ID, some: other, params: do_not_matter
TYPE
end
end
end
- it 'does not add an offense for calls to #argument without GraphQL::ID_TYPE' do
+ it 'does not add an offense for calls to #argument without GraphQL::Types::ID' do
expect_no_offenses(<<~TYPE.strip)
argument :some_arg, ::Types::GlobalIDType[::Awardable], some: other, params: do_not_matter
TYPE
diff --git a/spec/rubocop/cop/graphql/json_type_spec.rb b/spec/rubocop/cop/graphql/json_type_spec.rb
index 50437953c1d..882e2b2ef88 100644
--- a/spec/rubocop/cop/graphql/json_type_spec.rb
+++ b/spec/rubocop/cop/graphql/json_type_spec.rb
@@ -32,7 +32,7 @@ RSpec.describe RuboCop::Cop::Graphql::JSONType do
it 'does not add an offense for other types' do
expect_no_offenses(<<~RUBY.strip)
class MyType
- field :some_field, GraphQL::STRING_TYPE
+ field :some_field, GraphQL::Types::String
end
RUBY
end
@@ -60,7 +60,7 @@ RSpec.describe RuboCop::Cop::Graphql::JSONType do
it 'does not add an offense for other types' do
expect_no_offenses(<<~RUBY.strip)
class MyType
- argument :some_arg, GraphQL::STRING_TYPE
+ argument :some_arg, GraphQL::Types::String
end
RUBY
end
diff --git a/spec/rubocop/cop/graphql/old_types_spec.rb b/spec/rubocop/cop/graphql/old_types_spec.rb
new file mode 100644
index 00000000000..396bf4ce997
--- /dev/null
+++ b/spec/rubocop/cop/graphql/old_types_spec.rb
@@ -0,0 +1,84 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require 'rspec-parameterized'
+require_relative '../../../../rubocop/cop/graphql/old_types'
+
+RSpec.describe RuboCop::Cop::Graphql::OldTypes do
+ using RSpec::Parameterized::TableSyntax
+
+ subject(:cop) { described_class.new }
+
+ where(:old_type, :message) do
+ 'GraphQL::ID_TYPE' | 'Avoid using GraphQL::ID_TYPE. Use GraphQL::Types::ID instead'
+ 'GraphQL::INT_TYPE' | 'Avoid using GraphQL::INT_TYPE. Use GraphQL::Types::Int instead'
+ 'GraphQL::STRING_TYPE' | 'Avoid using GraphQL::STRING_TYPE. Use GraphQL::Types::String instead'
+ 'GraphQL::BOOLEAN_TYPE' | 'Avoid using GraphQL::BOOLEAN_TYPE. Use GraphQL::Types::Boolean instead'
+ end
+
+ with_them do
+ context 'fields' do
+ it 'adds an offense when an old type is used' do
+ expect_offense(<<~RUBY)
+ class MyType
+ field :some_field, #{old_type}
+ ^^^^^^^^^^^^^^^^^^^#{'^' * old_type.length} #{message}
+ end
+ RUBY
+ end
+
+ it "adds an offense when an old type is used with other keywords" do
+ expect_offense(<<~RUBY)
+ class MyType
+ field :some_field, #{old_type}, null: true, description: 'My description'
+ ^^^^^^^^^^^^^^^^^^^#{'^' * old_type.length}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{message}
+ end
+ RUBY
+ end
+ end
+
+ context 'arguments' do
+ it 'adds an offense when an old type is used' do
+ expect_offense(<<~RUBY)
+ class MyType
+ field :some_arg, #{old_type}
+ ^^^^^^^^^^^^^^^^^#{'^' * old_type.length} #{message}
+ end
+ RUBY
+ end
+
+ it 'adds an offense when an old type is used with other keywords' do
+ expect_offense(<<~RUBY)
+ class MyType
+ argument :some_arg, #{old_type}, null: true, description: 'My description'
+ ^^^^^^^^^^^^^^^^^^^^#{'^' * old_type.length}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{message}
+ end
+ RUBY
+ end
+ end
+ end
+
+ it 'does not add an offense for other types in fields' do
+ expect_no_offenses(<<~RUBY.strip)
+ class MyType
+ field :some_field, GraphQL::Types::JSON
+ end
+ RUBY
+ end
+
+ it 'does not add an offense for other types in arguments' do
+ expect_no_offenses(<<~RUBY.strip)
+ class MyType
+ argument :some_arg, GraphQL::Types::JSON
+ end
+ RUBY
+ end
+
+ it 'does not add an offense for uses outside of field or argument' do
+ expect_no_offenses(<<~RUBY.strip)
+ class MyType
+ foo :some_field, GraphQL::ID_TYPE
+ end
+ RUBY
+ end
+end
diff --git a/spec/rubocop/cop/ignored_columns_spec.rb b/spec/rubocop/cop/ignored_columns_spec.rb
index 1c72fedbf31..f87b1a1e520 100644
--- a/spec/rubocop/cop/ignored_columns_spec.rb
+++ b/spec/rubocop/cop/ignored_columns_spec.rb
@@ -14,4 +14,82 @@ RSpec.describe RuboCop::Cop::IgnoredColumns do
end
RUBY
end
+
+ context 'when only CE model exist' do
+ let(:file_path) { full_path('app/models/bar.rb') }
+
+ it 'does not flag ignore_columns usage in CE model' do
+ expect_no_offenses(<<~RUBY, file_path)
+ class Bar < ApplicationRecord
+ ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22'
+ end
+ RUBY
+ end
+
+ it 'flags ignore_column usage in EE model' do
+ expect_no_offenses(<<~RUBY, file_path)
+ class Baz < ApplicationRecord
+ ignore_column :bar, remove_with: '14.3', remove_after: '2021-09-22'
+ end
+ RUBY
+ end
+ end
+
+ context 'when only EE model exist' do
+ let(:file_path) { full_path('ee/app/models/ee/bar.rb') }
+
+ before do
+ allow(File).to receive(:exist?).with(full_path('app/models/bar.rb')).and_return(false)
+ end
+
+ it 'flags ignore_columns usage in EE model' do
+ expect_no_offenses(<<~RUBY, file_path)
+ class Bar < ApplicationRecord
+ ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22'
+ end
+ RUBY
+ end
+
+ it 'flags ignore_column usage in EE model' do
+ expect_no_offenses(<<~RUBY, file_path)
+ class Bar < ApplicationRecord
+ ignore_column :foo, remove_with: '14.3', remove_after: '2021-09-22'
+ end
+ RUBY
+ end
+ end
+
+ context 'when CE and EE model exist' do
+ let(:file_path) { full_path('ee/app/models/ee/bar.rb') }
+
+ before do
+ allow(File).to receive(:exist?).with(full_path('app/models/bar.rb')).and_return(true)
+ end
+
+ it 'flags ignore_columns usage in EE model' do
+ expect_offense(<<~RUBY, file_path)
+ class Bar < ApplicationRecord
+ ignore_columns :foo, remove_with: '14.3', remove_after: '2021-09-22'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ If the model exists in CE and EE, [...]
+ end
+ RUBY
+ end
+
+ it 'flags ignore_column usage in EE model' do
+ expect_offense(<<~RUBY, file_path)
+ class Bar < ApplicationRecord
+ ignore_column :foo, remove_with: '14.3', remove_after: '2021-09-22'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ If the model exists in CE and EE, [...]
+ end
+ RUBY
+ end
+ end
+
+ private
+
+ def full_path(path)
+ rails_root = '../../../'
+
+ File.expand_path(File.join(rails_root, path), __dir__)
+ end
end
diff --git a/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb b/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb
index 7bcaf36b014..6a8df2b507d 100644
--- a/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb
+++ b/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb
@@ -116,7 +116,6 @@ RSpec.describe RuboCop::Cop::Migration::CreateTableWithForeignKeys do
shared_context 'when there is a target to a high traffic table' do |dsl_method|
%w[
audit_events
- ci_build_trace_sections
ci_builds
ci_builds_metadata
ci_job_artifacts
diff --git a/spec/rubocop/cop/qa/selector_usage_spec.rb b/spec/rubocop/cop/qa/selector_usage_spec.rb
new file mode 100644
index 00000000000..b40c57f8991
--- /dev/null
+++ b/spec/rubocop/cop/qa/selector_usage_spec.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+
+require_relative '../../../../rubocop/cop/qa/selector_usage'
+
+RSpec.describe RuboCop::Cop::QA::SelectorUsage do
+ subject(:cop) { described_class.new }
+
+ shared_examples 'non-qa file usage' do
+ it 'reports an offense' do
+ expect_offense(<<-RUBY)
+ find('#{selector}').click
+ #{'^' * (selector.size + 2)} Do not use `#{selector}` as this is reserved for the end-to-end specs. Use a different selector or a data-testid instead.
+ RUBY
+ end
+ end
+
+ context 'in a QA file' do
+ before do
+ allow(cop).to receive(:in_qa_file?).and_return(true)
+ end
+
+ it 'has no error' do
+ expect_no_offenses(<<-RUBY)
+ has_element?('[data-qa-selector="my_selector"]')
+ RUBY
+ end
+ end
+
+ context 'outside of QA' do
+ before do
+ allow(cop).to receive(:in_qa_file?).and_return(false)
+ allow(cop).to receive(:in_spec?).and_return(true)
+ end
+
+ context 'data-qa-selector' do
+ let(:selector) { '[data-qa-selector="my_selector"]' }
+
+ it_behaves_like 'non-qa file usage'
+ end
+
+ context 'qa class' do
+ let(:selector) { '.qa-selector' }
+
+ it_behaves_like 'non-qa file usage'
+ end
+ end
+end