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>2021-11-04 12:12:56 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-04 12:12:56 +0300
commit191020103bd4d2aad99c62a35201c05d9df74f8f (patch)
tree83ef6f71fea1f66842545e9af788fdc33d34d48b /rubocop
parent5bfd7a344b73d6a9482b420fa7646f7d1760a566 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/qa/duplicate_testcase_link.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/rubocop/cop/qa/duplicate_testcase_link.rb b/rubocop/cop/qa/duplicate_testcase_link.rb
new file mode 100644
index 00000000000..f30768c7d80
--- /dev/null
+++ b/rubocop/cop/qa/duplicate_testcase_link.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require_relative '../../qa_helpers'
+
+module RuboCop
+ module Cop
+ module QA
+ # This cop checks for duplicate testcase links across e2e specs
+ #
+ # @example
+ #
+ # # bad
+ # it 'some test', testcase: '(...)/quality/test_cases/1892'
+ # it 'another test, testcase: '(...)/quality/test_cases/1892'
+ #
+ # # good
+ # it 'some test', testcase: '(...)/quality/test_cases/1892'
+ # it 'another test, testcase: '(...)/quality/test_cases/1894'
+ class DuplicateTestcaseLink < RuboCop::Cop::Cop
+ include QAHelpers
+
+ MESSAGE = "Don't reuse the same testcase link in different tests. Replace one of `%s`."
+
+ @testcase_set = Set.new
+
+ def_node_matcher :duplicate_testcase_link, <<~PATTERN
+ (block
+ (send nil? ...
+ ...
+ (hash
+ (pair
+ (sym :testcase)
+ (str $_))...)...)...)
+ PATTERN
+
+ def on_block(node)
+ return unless in_qa_file?(node)
+
+ duplicate_testcase_link(node) do |link|
+ break unless self.class.duplicate?(link)
+
+ add_offense(node, message: MESSAGE % link)
+ end
+ end
+
+ def self.duplicate?(link)
+ !@testcase_set.add?(link)
+ end
+ end
+ end
+ end
+end