diff options
author | Dan Davison <ddavison@gitlab.com> | 2019-05-28 19:44:22 +0300 |
---|---|---|
committer | Dan Davison <ddavison@gitlab.com> | 2019-05-28 19:44:22 +0300 |
commit | e6c6acaf0750700614e9a28d1eb42ae6a206f90f (patch) | |
tree | b9dfc35f0559ab7ad8f0bc1985e61abf7b6d0bd0 /rubocop/cop | |
parent | 2efc284a99e5791a486da5bfd137142d465fb38c (diff) | |
parent | 83cfd20ca86d5f0992438c44707b074a711b7752 (diff) |
Merge branch 'qa-extend-click-visit-actions' into 'master'
Implement dynamic validation on QA Pages
Closes gitlab-qa#280
See merge request gitlab-org/gitlab-ce!25704
Diffstat (limited to 'rubocop/cop')
-rw-r--r-- | rubocop/cop/qa/element_with_pattern.rb | 20 |
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 |