summaryrefslogtreecommitdiff
path: root/rubocop
diff options
context:
space:
mode:
authorddavison <ddavison@gitlab.com>2019-03-01 18:03:43 -0800
committerddavison <ddavison@gitlab.com>2019-05-20 12:35:51 -0700
commit7d5b68d837545909204e6caf2352f34ac2f1ba7a (patch)
tree2c646c34cfdb635ff671647562a480af247f5bbb /rubocop
parent4063b7e811050c0870d782072664673e16eafdfe (diff)
downloadgitlab-ce-7d5b68d837545909204e6caf2352f34ac2f1ba7a.tar.gz
Implement dynamic validation on QA Pages
Elements now have the ability to be required on pages or not Currently using the default wait mechanism Altered the ElementWithPattern Cop to fit new splat for init
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/qa/element_with_pattern.rb20
1 files changed, 13 insertions, 7 deletions
diff --git a/rubocop/cop/qa/element_with_pattern.rb b/rubocop/cop/qa/element_with_pattern.rb
index 9d80946f1ba..d14eeaaeaf3 100644
--- a/rubocop/cop/qa/element_with_pattern.rb
+++ b/rubocop/cop/qa/element_with_pattern.rb
@@ -1,18 +1,21 @@
+# frozen_string_literal: true
+
require_relative '../../qa_helpers'
module RuboCop
module Cop
module QA
- # This cop checks for the usage of factories in migration specs
+ # This cop checks for the usage of patterns in QA elements
#
# @example
#
# # bad
- # let(:user) { create(:user) }
+ # element :some_element, "link_to 'something'"
+ # element :some_element, /link_to 'something'/
#
# # good
- # let(:users) { table(:users) }
- # let(:user) { users.create!(name: 'User 1', username: 'user1') }
+ # element :some_element
+ # element :some_element, required: true
class ElementWithPattern < RuboCop::Cop::Cop
include QAHelpers
@@ -22,10 +25,13 @@ module RuboCop
return unless in_qa_file?(node)
return unless method_name(node).to_s == 'element'
- element_name, pattern = node.arguments
- return unless pattern
+ element_name, *args = node.arguments
+
+ return if args.first.nil?
- add_offense(node, location: pattern.source_range, message: MESSAGE % "qa-#{element_name.value.to_s.tr('_', '-')}")
+ args.first.each_node(:str) do |arg|
+ add_offense(arg, message: MESSAGE % "qa-#{element_name.value.to_s.tr('_', '-')}")
+ end
end
private