Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubocop/cop/gitlab')
-rw-r--r--spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb98
-rw-r--r--spec/rubocop/cop/gitlab/json_spec.rb45
-rw-r--r--spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb4
-rw-r--r--spec/rubocop/cop/gitlab/rspec/avoid_setup_spec.rb36
4 files changed, 81 insertions, 102 deletions
diff --git a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
deleted file mode 100644
index 0a121a495c9..00000000000
--- a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
+++ /dev/null
@@ -1,98 +0,0 @@
-# frozen_string_literal: true
-
-require 'rubocop_spec_helper'
-
-require_relative '../../../../rubocop/cop/gitlab/duplicate_spec_location'
-
-RSpec.describe RuboCop::Cop::Gitlab::DuplicateSpecLocation, type: :rubocop_rspec do
- let(:rails_root) { '../../../../' }
-
- def full_path(path)
- File.expand_path(File.join(rails_root, path), __dir__)
- end
-
- context 'Non-EE spec file' do
- it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE, full_path('spec/foo_spec.rb'))
- describe 'Foo' do
- end
- SOURCE
- end
- end
-
- context 'Non-EE application file' do
- it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE, full_path('app/models/blog_post.rb'))
- class BlogPost
- end
- SOURCE
- end
- end
-
- context 'EE application file' do
- it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE, full_path('ee/app/models/blog_post.rb'))
- class BlogPost
- end
- SOURCE
- end
- end
-
- context 'EE spec file for EE only code' do
- let(:spec_file_path) { full_path('ee/spec/controllers/foo_spec.rb') }
-
- it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE, spec_file_path)
- describe 'Foo' do
- end
- SOURCE
- end
-
- context 'there is a duplicate file' do
- before do
- allow(File).to receive(:exist?).and_call_original
-
- allow(File).to receive(:exist?)
- .with(full_path('ee/spec/controllers/ee/foo_spec.rb'))
- .and_return(true)
- end
-
- it 'marks the describe as offending' do
- expect_offense(<<~SOURCE, spec_file_path)
- describe 'Foo' do
- ^^^^^^^^^^^^^^ Duplicate spec location in `ee/spec/controllers/ee/foo_spec.rb`.
- end
- SOURCE
- end
- end
- end
-
- context 'EE spec file for EE extension' do
- let(:spec_file_path) { full_path('ee/spec/controllers/ee/foo_spec.rb') }
-
- it 'registers no offenses' do
- expect_no_offenses(<<~SOURCE, spec_file_path)
- describe 'Foo' do
- end
- SOURCE
- end
-
- context 'there is a duplicate file' do
- before do
- allow(File).to receive(:exist?).and_call_original
-
- allow(File).to receive(:exist?)
- .with(full_path('ee/spec/controllers/foo_spec.rb'))
- .and_return(true)
- end
-
- it 'marks the describe as offending' do
- expect_offense(<<~SOURCE, spec_file_path)
- describe 'Foo' do
- ^^^^^^^^^^^^^^ Duplicate spec location in `ee/spec/controllers/foo_spec.rb`.
- end
- SOURCE
- end
- end
- end
-end
diff --git a/spec/rubocop/cop/gitlab/json_spec.rb b/spec/rubocop/cop/gitlab/json_spec.rb
index e4ec107747d..70f63a78dd1 100644
--- a/spec/rubocop/cop/gitlab/json_spec.rb
+++ b/spec/rubocop/cop/gitlab/json_spec.rb
@@ -5,12 +5,41 @@ require_relative '../../../../rubocop/cop/gitlab/json'
RSpec.describe RuboCop::Cop::Gitlab::Json do
context 'when ::JSON is called' do
- it 'registers an offense' do
+ it 'registers an offense and autocorrects' do
expect_offense(<<~RUBY)
class Foo
def bar
JSON.parse('{ "foo": "bar" }')
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `JSON` directly. [...]
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Gitlab::Json` over calling `JSON` directly. [...]
+ end
+ end
+ RUBY
+
+ expect_correction(<<~RUBY)
+ class Foo
+ def bar
+ Gitlab::Json.parse('{ "foo": "bar" }')
+ end
+ end
+ RUBY
+ end
+ end
+
+ context 'when ::JSON is called in EE' do
+ it 'registers an offense and autocorrects' do
+ expect_offense(<<~RUBY, '/path/to/ee/foo.rb')
+ class Foo
+ def bar
+ JSON.parse('{ "foo": "bar" }')
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Gitlab::Json` over calling `JSON` directly. [...]
+ end
+ end
+ RUBY
+
+ expect_correction(<<~RUBY)
+ class Foo
+ def bar
+ ::Gitlab::Json.parse('{ "foo": "bar" }')
end
end
RUBY
@@ -18,12 +47,20 @@ RSpec.describe RuboCop::Cop::Gitlab::Json do
end
context 'when ActiveSupport::JSON is called' do
- it 'registers an offense' do
+ it 'registers an offense and autocorrects' do
expect_offense(<<~RUBY)
class Foo
def bar
ActiveSupport::JSON.parse('{ "foo": "bar" }')
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `JSON` directly. [...]
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `Gitlab::Json` over calling `JSON` directly. [...]
+ end
+ end
+ RUBY
+
+ expect_correction(<<~RUBY)
+ class Foo
+ def bar
+ Gitlab::Json.parse('{ "foo": "bar" }')
end
end
RUBY
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 a3c9ae8916e..6e60889f737 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', 'FEATURE_FLAG = :foo', 'foo'
end
+ describe 'ROUTING_FEATURE_FLAG = :foo' do
+ include_examples 'sets flag as used', 'ROUTING_FEATURE_FLAG = :foo', 'foo'
+ end
+
describe 'Worker `data_consistency` method' do
include_examples 'sets flag as used', 'data_consistency :delayed, feature_flag: :foo', 'foo'
include_examples 'does not set any flags as used', 'data_consistency :delayed'
diff --git a/spec/rubocop/cop/gitlab/rspec/avoid_setup_spec.rb b/spec/rubocop/cop/gitlab/rspec/avoid_setup_spec.rb
new file mode 100644
index 00000000000..f9226649f65
--- /dev/null
+++ b/spec/rubocop/cop/gitlab/rspec/avoid_setup_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+
+require_relative '../../../../../rubocop/cop/gitlab/rspec/avoid_setup'
+
+RSpec.describe RuboCop::Cop::Gitlab::RSpec::AvoidSetup do
+ context 'when calling let_it_be' do
+ let(:source) do
+ <<~SRC
+ let_it_be(:user) { create(:user) }
+ ^^^^^^^^^^^^^^^^ Avoid the use of `let_it_be` [...]
+ SRC
+ end
+
+ it 'registers an offense' do
+ expect_offense(source)
+ end
+ end
+
+ context 'without readability issues' do
+ let(:source) do
+ <<~SRC
+ it 'registers the user and sends them to a project listing page' do
+ user_signs_up
+
+ expect_to_see_account_confirmation_page
+ end
+ SRC
+ end
+
+ it 'does not register an offense' do
+ expect_no_offenses(source)
+ end
+ end
+end