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:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-07-26 15:07:29 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-26 15:07:29 +0300
commit597d5ed08988cb00681eaf252d04ebae4bd24731 (patch)
treefa6c90ecda00858be51b790dad9e4d9098d29fdb /rubocop
parente2cf652edb5e9d9fa9a081952070074c07bf651e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/rspec/before_all.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/rubocop/cop/rspec/before_all.rb b/rubocop/cop/rspec/before_all.rb
new file mode 100644
index 00000000000..3fbb9447bc6
--- /dev/null
+++ b/rubocop/cop/rspec/before_all.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'rubocop-rspec'
+
+module Rubocop
+ module Cop
+ module RSpec
+ # This cop checks for `before(:all) in RSpec tests`
+ #
+ # @example
+ #
+ # bad
+ #
+ # before(:all) do
+ # project.repository.add_tag(user, 'v1.2.3', 'master')
+ # end
+ #
+ # good
+ #
+ # before_all do
+ # project.repository.add_tag(user, 'v1.2.3', 'master')
+ # end
+ #
+ class BeforeAll < RuboCop::Cop::Base
+ extend RuboCop::Cop::AutoCorrector
+
+ MSG = "Prefer using `before_all` over `before(:all)`. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#common-test-setup"
+
+ RESTRICT_ON_SEND = %i[before].freeze
+
+ def_node_matcher :before_all_block?, <<~PATTERN
+ (send nil? :before (sym :all) ...)
+ PATTERN
+
+ def on_send(node)
+ return unless before_all_block?(node)
+
+ add_offense(node) do |corrector|
+ replacement = 'before_all'
+ corrector.replace(node.source_range, replacement)
+ end
+ end
+ end
+ end
+ end
+end