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:
-rw-r--r--.rubocop.yml8
-rw-r--r--rubocop/cop/rspec/be_success_matcher.rb1
-rw-r--r--rubocop/spec_helpers.rb16
-rw-r--r--spec/rubocop/cop/rspec/be_success_matcher_spec.rb34
4 files changed, 16 insertions, 43 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 012f4890c33..1319752fc9c 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -265,3 +265,11 @@ RSpec/EnvAssignment:
- 'ee/spec/**/rails_helper.rb'
- 'spec/**/spec_helper.rb'
- 'ee/spec/**/spec_helper.rb'
+RSpec/BeSuccessMatcher:
+ Enabled: true
+ Include:
+ - 'spec/controllers/**/*'
+ - 'ee/spec/controllers/**/*'
+ - 'spec/support/shared_examples/controllers/**/*'
+ - 'ee/spec/support/shared_examples/controllers/**/*'
+ - 'spec/support/controllers/**/*'
diff --git a/rubocop/cop/rspec/be_success_matcher.rb b/rubocop/cop/rspec/be_success_matcher.rb
index ca937a8ee9f..0b7d737f4e2 100644
--- a/rubocop/cop/rspec/be_success_matcher.rb
+++ b/rubocop/cop/rspec/be_success_matcher.rb
@@ -41,7 +41,6 @@ module RuboCop
end
def on_send(node)
- return unless in_controller_spec?(node)
return unless be_success_usage?(node)
add_offense(node, location: :expression, message: MESSAGE)
diff --git a/rubocop/spec_helpers.rb b/rubocop/spec_helpers.rb
index b38dc3f8cdb..ecd77c4351d 100644
--- a/rubocop/spec_helpers.rb
+++ b/rubocop/spec_helpers.rb
@@ -2,7 +2,6 @@ module RuboCop
module SpecHelpers
SPEC_HELPERS = %w[fast_spec_helper.rb rails_helper.rb spec_helper.rb].freeze
MIGRATION_SPEC_DIRECTORIES = ['spec/migrations', 'spec/lib/gitlab/background_migration'].freeze
- CONTROLLER_SPEC_DIRECTORIES = ['spec/controllers', 'spec/support/shared_examples/controllers'].freeze
# Returns true if the given node originated from the spec directory.
def in_spec?(node)
@@ -27,20 +26,5 @@ module RuboCop
in_spec?(node) &&
path.start_with?(*migration_directories)
end
-
- def controller_directories
- @controller_directories ||= CONTROLLER_SPEC_DIRECTORIES.map do |dir|
- pwd = RuboCop::PathUtil.pwd
- [File.join(pwd, dir), File.join(pwd, 'ee', dir)]
- end.flatten
- end
-
- # Returns true if the given node originated from a controller spec.
- def in_controller_spec?(node)
- path = node.location.expression.source_buffer.name
-
- in_spec?(node) &&
- path.start_with?(*controller_directories)
- end
end
end
diff --git a/spec/rubocop/cop/rspec/be_success_matcher_spec.rb b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
index 95f08a61557..77aff7c9dcc 100644
--- a/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
+++ b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
@@ -59,35 +59,17 @@ describe RuboCop::Cop::RSpec::BeSuccessMatcher do
end
end
- context 'in a controller spec file' do
- before do
- allow(cop).to receive(:in_controller_spec?).and_return(true)
+ CODE_EXAMPLES.each do |code_example|
+ context "using #{code_example[:bad]} call" do
+ it_behaves_like 'an offensive be_success call', code_example[:bad]
+ it_behaves_like 'an autocorrected be_success call', code_example[:bad], code_example[:good]
end
- CODE_EXAMPLES.each do |code_example|
- context "using #{code_example[:bad]} call" do
- it_behaves_like 'an offensive be_success call', code_example[:bad]
- it_behaves_like 'an autocorrected be_success call', code_example[:bad], code_example[:good]
- end
-
- context "using #{code_example[:good]} call" do
- it 'does not register an offense' do
- inspect_source(code_example[:good])
-
- expect(cop.offenses.size).to eq(0)
- end
- end
- end
- end
-
- context 'outside of a controller spec file' do
- CODE_EXAMPLES.each do |code_example|
- context "using #{code_example[:bad]} call" do
- it 'does not register an offense' do
- inspect_source(code_example[:bad])
+ context "using #{code_example[:good]} call" do
+ it 'does not register an offense' do
+ inspect_source(code_example[:good])
- expect(cop.offenses.size).to eq(0)
- end
+ expect(cop.offenses.size).to eq(0)
end
end
end