debian-mirror-gitlab/rubocop/cop/qa/ambiguous_page_object_name.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
require_relative '../../qa_helpers'
module RuboCop
module Cop
module QA
# This cop checks for the usage of the ambiguous name "page"
#
# @example
#
# # bad
# Page::Object.perform do |page| do ...
# Page::Another.perform { |page| ... }
#
# # good
# Page::Object.perform do |object| do ...
# Page::Another.perform { |another| ... }
2022-10-11 01:57:18 +05:30
class AmbiguousPageObjectName < RuboCop::Cop::Base
2019-12-04 20:38:33 +05:30
include QAHelpers
2021-04-29 21:17:54 +05:30
MESSAGE = "Don't use 'page' as a name for a Page Object. Use `%s` instead."
2019-12-04 20:38:33 +05:30
def_node_matcher :ambiguous_page?, <<~PATTERN
(block
(send
(const ...) :perform)
(args
(arg :page)) ...)
PATTERN
def on_block(node)
return unless in_qa_file?(node)
return unless ambiguous_page?(node)
add_offense(node.arguments.each_node(:arg).first,
message: MESSAGE % page_object_name(node))
end
private
def page_object_name(node)
node.send_node.children[-2].const_name.downcase.split('::').last
end
end
end
end
end