Commit 1fec44af authored by Dan Davison's avatar Dan Davison

Add rubocop disable statements to existing offenders

Disable QA/AmbiguousPageObjectName cop for all offenses
under QA
parent 6bd8a2e1
......@@ -29,7 +29,7 @@ module QA
QA::Page::Group::Menu.perform(&:click_group_epics_link)
QA::EE::Page::Group::Epic::Index.perform do |page|
QA::EE::Page::Group::Epic::Index.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.click_new_epic
page.set_title(@title)
page.create_new_epic
......
......@@ -14,7 +14,7 @@ module QA
QA::Page::Admin::Menu.perform(&:click_geo_menu_link)
EE::Page::Admin::Geo::Nodes::Show.perform(&:new_node!)
EE::Page::Admin::Geo::Nodes::New.perform do |page|
EE::Page::Admin::Geo::Nodes::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
raise ArgumentError if @name.nil? || @address.nil?
page.set_node_name(@name)
......
......@@ -9,7 +9,7 @@ module QA
QA::Page::Main::Menu.perform(&:click_admin_area)
QA::Page::Admin::Menu.perform(&:click_license_menu_link)
EE::Page::Admin::License.perform do |page|
EE::Page::Admin::License.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.add_new_license(license) unless page.license?
end
......
......@@ -6,7 +6,7 @@ module QA
attr_accessor :name, :expires_at
attribute :username do
Page::Project::Settings::Repository.perform do |page|
Page::Project::Settings::Repository.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.expand_deploy_tokens do |token|
token.token_username
end
......@@ -14,7 +14,7 @@ module QA
end
attribute :password do
Page::Project::Settings::Repository.perform do |page|
Page::Project::Settings::Repository.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.expand_deploy_tokens do |token|
token.token_password
end
......
......@@ -27,7 +27,7 @@ module QA
Page::Project::Show.perform(&:create_first_new_file!)
Page::File::Form.perform do |page|
Page::File::Form.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.add_name(@name)
page.add_content(@content)
page.add_commit_message(@commit_message)
......
......@@ -41,7 +41,7 @@ module QA
fork_new.choose_namespace(user.name)
end
Page::Layout::Banner.perform do |page|
Page::Layout::Banner.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.has_notice?('The project was successfully forked.')
end
......
......@@ -25,7 +25,7 @@ module QA
Page::Project::Show.perform(&:go_to_new_issue)
Page::Project::Issue::New.perform do |page|
Page::Project::Issue::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.add_title(@title)
page.add_description(@description)
page.create_new_issue
......
......@@ -24,7 +24,7 @@ module QA
Page::Project::Operations::Kubernetes::Add.perform(
&:add_existing_cluster)
Page::Project::Operations::Kubernetes::AddExisting.perform do |page|
Page::Project::Operations::Kubernetes::AddExisting.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.set_cluster_name(@cluster.cluster_name)
page.set_api_url(@cluster.api_url)
page.set_ca_certificate(@cluster.ca_certificate)
......@@ -34,7 +34,7 @@ module QA
end
if @install_helm_tiller
Page::Project::Operations::Kubernetes::Show.perform do |page|
Page::Project::Operations::Kubernetes::Show.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
# We must wait a few seconds for permissions to be set up correctly for new cluster
sleep 10
......
......@@ -28,7 +28,7 @@ module QA
Page::Project::Menu.perform(&:go_to_labels)
Page::Label::Index.perform(&:click_new_label_button)
Page::Label::New.perform do |page|
Page::Label::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.fill_title(@title)
page.fill_description(@description)
page.fill_color(@color)
......
......@@ -16,7 +16,7 @@ module QA
Page::Main::Menu.perform(&:click_settings_link)
Page::Profile::Menu.perform(&:click_access_tokens)
Page::Profile::PersonalAccessTokens.perform do |page|
Page::Profile::PersonalAccessTokens.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.fill_token_name(name || 'api-test-token')
page.check_api
page.click_create_token_button
......
......@@ -30,13 +30,13 @@ module QA
end
attribute :repository_ssh_location do
Page::Project::Show.perform do |page|
Page::Project::Show.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.repository_clone_ssh_location
end
end
attribute :repository_http_location do
Page::Project::Show.perform do |page|
Page::Project::Show.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.repository_clone_http_location
end
end
......@@ -59,7 +59,7 @@ module QA
Page::Group::Show.perform(&:go_to_new_project)
end
Page::Project::New.perform do |page|
Page::Project::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.choose_test_namespace
page.choose_name(@name)
page.add_description(@description)
......
......@@ -17,15 +17,15 @@ module QA
Page::Group::Show.perform(&:go_to_new_project)
Page::Project::New.perform do |page|
Page::Project::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.click_import_project
end
Page::Project::New.perform do |page|
Page::Project::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.click_github_link
end
Page::Project::Import::Github.perform do |page|
Page::Project::Import::Github.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.add_personal_access_token(@personal_access_token)
page.list_repos
page.import!(@github_repository_path, @name)
......
......@@ -18,7 +18,7 @@ module QA
def fabricate!
project.visit!
Page::Project::Menu.perform do |page|
Page::Project::Menu.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.click_issues
page.click_milestones
end
......
......@@ -18,11 +18,11 @@ module QA
def fabricate!
Page::Main::Menu.perform(&:go_to_groups)
Page::Dashboard::Groups.perform do |page|
if page.has_group?(path)
page.click_group(path)
Page::Dashboard::Groups.perform do |groups_page|
if groups_page.has_group?(path)
groups_page.click_group(path)
else
page.click_new_group
groups_page.click_new_group
Page::Group::New.perform do |group|
group.set_path(path)
......
......@@ -16,7 +16,7 @@ module QA
def fabricate!
Page::Dashboard::Snippet::Index.perform(&:go_to_new_snippet_page)
Page::Dashboard::Snippet::New.perform do |page|
Page::Dashboard::Snippet::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.fill_title(@title)
page.fill_description(@description)
page.set_visibility(@visibility)
......
......@@ -17,7 +17,7 @@ module QA
Page::Main::Menu.perform(&:click_settings_link)
Page::Profile::Menu.perform(&:click_ssh_keys)
Page::Profile::SSHKeys.perform do |page|
Page::Profile::SSHKeys.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.add_key(public_key, title)
end
end
......
......@@ -8,7 +8,7 @@ module QA
Page::Main::Login.perform(&:sign_in_using_credentials)
Page::Main::Menu.perform(&:go_to_groups)
Page::Dashboard::Groups.perform do |page|
Page::Dashboard::Groups.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.click_new_group
expect(page).to have_content(
......
......@@ -11,7 +11,7 @@ module QA
Runtime::Browser.visit(:mattermost, Page::Mattermost::Login)
Page::Mattermost::Login.perform(&:sign_in_using_oauth)
Page::Mattermost::Main.perform do |page|
Page::Mattermost::Main.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
expect(page).to have_content(/(Welcome to: Mattermost|Logout GitLab Mattermost)/)
end
end
......
......@@ -15,7 +15,7 @@ module QA
project.visit!
Page::Project::Menu.perform(&:go_to_members_settings)
Page::Project::Settings::Members.perform do |page|
Page::Project::Settings::Members.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.add_member(user.username)
end
......
......@@ -30,7 +30,7 @@ module QA
project.visit!
Page::Project::Show.perform(&:go_to_members_settings)
Page::Project::Settings::Members.perform do |page|
Page::Project::Settings::Members.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.add_member(user.username)
end
......
......@@ -57,7 +57,7 @@ module QA
@project.visit!
Page::Project::Show.perform(&:create_new_file!)
Page::File::Form.perform do |page|
Page::File::Form.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.select_template template[:file_name], template[:name]
end
......
......@@ -35,7 +35,7 @@ module QA
def view_commit
@project.visit!
Page::Project::Show.perform do |page|
Page::Project::Show.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.click_commit(@commit_message)
end
end
......
......@@ -57,7 +57,7 @@ module QA
@project.visit!
Page::Project::Show.perform(&:open_web_ide!)
Page::Project::WebIDE::Edit.perform do |page|
Page::Project::WebIDE::Edit.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.create_new_file_from_template template[:file_name], template[:name]
expect(page.has_file?(template[:file_name])).to be_truthy
......
......@@ -16,7 +16,7 @@ module QA
validate_content('My First Wiki Content')
Page::Project::Wiki::Edit.perform(&:click_edit)
Page::Project::Wiki::New.perform do |page|
Page::Project::Wiki::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.set_content("My Second Wiki Content")
page.save_changes
end
......
......@@ -23,7 +23,7 @@ module QA
issue.title = 'Performance bar test'
end
Page::Layout::PerformanceBar.perform do |page|
Page::Layout::PerformanceBar.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
expect(page).to have_performance_bar
expect(page).to have_detailed_metrics
expect(page).to have_request_for('realtime_changes') # Always requested on issue pages
......
......@@ -93,12 +93,12 @@ module QA
project.visit!
Page::Project::Menu.perform(&:go_to_members_settings)
Page::Project::Settings::Members.perform do |page|
Page::Project::Settings::Members.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.invite_group(@group.path)
end
Page::Project::Menu.perform(&:go_to_members_settings)
Page::Project::Settings::Members.perform do |page|
Page::Project::Settings::Members.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.remove_group(@group.path)
end
......
......@@ -68,7 +68,7 @@ module QA
Page::Group::Menu.perform(&:go_to_ldap_sync_settings)
EE::Page::Group::Settings::LDAPSync.perform do |page|
EE::Page::Group::Settings::LDAPSync.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.set_sync_method('LDAP Group cn')
page.set_group_cn('Engineering')
page.click_add_sync_button
......@@ -118,7 +118,7 @@ module QA
Page::Group::Menu.perform(&:go_to_ldap_sync_settings)
EE::Page::Group::Settings::LDAPSync.perform do |page|
EE::Page::Group::Settings::LDAPSync.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.set_user_filter('(&(objectClass=person)(cn=HR*))')
page.click_add_sync_button
end
......@@ -171,7 +171,7 @@ module QA
end
def verify_users_synced(expected_users)
EE::Page::Group::Members.perform do |page|
EE::Page::Group::Members.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.click_sync_now
users_synchronised = page.retry_until(reload: true) do
expected_users.map { |user| page.has_content?(user) }.all?
......
......@@ -23,7 +23,7 @@ module QA
it 'User logs in to group with SAML SSO' do
Page::Group::Menu.perform(&:go_to_saml_sso_group_settings)
EE::Page::Group::Settings::SamlSSO.perform do |page|
EE::Page::Group::Settings::SamlSSO.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.set_id_provider_sso_url(QA::EE::Runtime::Saml.idp_sso_url)
page.set_cert_fingerprint(QA::EE::Runtime::Saml.idp_certificate_fingerprint)
page.click_save_changes
......@@ -47,7 +47,7 @@ module QA
it 'Lets group admin test settings' do
Page::Group::Menu.perform(&:go_to_saml_sso_group_settings)
EE::Page::Group::Settings::SamlSSO.perform do |page|
EE::Page::Group::Settings::SamlSSO.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.set_id_provider_sso_url(QA::EE::Runtime::Saml.idp_sso_url)
page.set_cert_fingerprint(QA::EE::Runtime::Saml.idp_certificate_fingerprint)
page.click_save_changes
......@@ -86,7 +86,7 @@ module QA
Page::Group::Menu.perform(&:go_to_saml_sso_group_settings)
EE::Page::Group::Settings::SamlSSO.perform do |page|
EE::Page::Group::Settings::SamlSSO.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.enforce_sso
page.set_id_provider_sso_url(QA::EE::Runtime::Saml.idp_sso_url)
page.set_cert_fingerprint(QA::EE::Runtime::Saml.idp_certificate_fingerprint)
......
......@@ -38,7 +38,7 @@ module QA
@project.visit!
Page::Project::Menu.perform(&:go_to_members_settings)
Page::Project::Settings::Members.perform do |page|
Page::Project::Settings::Members.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.add_member(user.username)
end
end
......
......@@ -56,7 +56,7 @@ module QA
@group.visit!
Page::Group::Show.perform(&:go_to_new_project)
Page::Project::New.perform do |page|
Page::Project::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.click_create_from_template_tab
expect(page).to have_text(built_in)
......@@ -86,13 +86,13 @@ module QA
Page::Main::Menu.perform(&:click_admin_area)
Page::Admin::Menu.perform(&:go_to_template_settings)
Page::Admin::Settings::Templates.perform do |page|
Page::Admin::Settings::Templates.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.choose_custom_project_template("#{@template_container_group_name}")
end
Page::Admin::Menu.perform(&:go_to_template_settings)
Page::Admin::Settings::Templates.perform do |page|
Page::Admin::Settings::Templates.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
expect(page.current_custom_project_template).to include @template_container_group_name
end
......@@ -105,7 +105,7 @@ module QA
end
it 'successfully imports the project using template' do
Page::Project::New.perform do |page|
Page::Project::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
expect(page.instance_template_tab_badge_text).to eq "1"
expect(page).to have_text(@template_project.name)
end
......@@ -133,7 +133,7 @@ module QA
Page::Main::Login.perform(&:sign_in_using_credentials)
Page::Main::Menu.perform(&:go_to_groups)
Page::Dashboard::Groups.perform { |page| page.click_group(Runtime::Namespace.sandbox_name) }
Page::Dashboard::Groups.perform { |page| page.click_group(Runtime::Namespace.sandbox_name) } # rubocop:disable QA/AmbiguousPageObjectName
Page::Project::Menu.perform(&:click_settings)
Page::Group::Settings::General.perform do |settings|
......@@ -155,7 +155,7 @@ module QA
end
it 'successfully imports the project using template' do
Page::Project::New.perform do |page|
Page::Project::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
expect(page.group_template_tab_badge_text).to eq "1"
expect(page).to have_text(@template_container_group_name)
expect(page).to have_text(@template_project.name)
......@@ -173,7 +173,7 @@ module QA
end
def create_project_using_template(project_name:, namespace:, template_name:)
Page::Project::New.perform do |page|
Page::Project::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.use_template_for_project(template_name)
page.choose_namespace(namespace)
page.choose_name("#{project_name} #{SecureRandom.hex(8)}")
......
......@@ -95,7 +95,7 @@ module QA
it 'displays security reports in the group security dashboard' do
Page::Main::Menu.perform(&:go_to_groups)
Page::Dashboard::Groups.perform do |page|
Page::Dashboard::Groups.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
page.click_group @project.group.path
end
Page::Group::Menu.perform(&:click_group_security_link)
......@@ -120,7 +120,7 @@ module QA
it 'displays the Dependency List' do
Page::Project::Menu.perform(&:click_on_dependency_list)
EE::Page::Project::Secure::DependencyList.perform do |page|
EE::Page::Project::Secure::DependencyList.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
expect(page).to have_dependency_count_of number_of_dependencies_in_fixture
end
end
......
......@@ -32,7 +32,7 @@ module QA
token_name = 'api-test-token'
Page::Profile::PersonalAccessTokens.perform do |page|
Page::Profile::PersonalAccessTokens.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
while page.has_token_row_for_name?(token_name)
page.revoke_first_token_with_name(token_name)
print "\e[32m.\e[0m"
......
# 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| ... }
class AmbiguousPageObjectName < RuboCop::Cop::Cop
include QAHelpers
MESSAGE = "Don't use 'page' as a name for a Page Object. Use `%s` instead.".freeze
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
......@@ -36,6 +36,7 @@ require_relative 'cop/rspec/env_assignment'
require_relative 'cop/rspec/factories_in_migration_specs'
require_relative 'cop/rspec/top_level_describe_path'
require_relative 'cop/qa/element_with_pattern'
require_relative 'cop/qa/ambiguous_page_object_name'
require_relative 'cop/sidekiq_options_queue'
require_relative 'cop/scalability/file_uploads'
require_relative 'cop/destroy_all'
......
# frozen_string_literal: true
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/qa/ambiguous_page_object_name'
describe RuboCop::Cop::QA::AmbiguousPageObjectName do
include CopHelper
let(:source_file) { 'qa/page.rb' }
subject(:cop) { described_class.new }
context 'in a QA file' do
before do
allow(cop).to receive(:in_qa_file?).and_return(true)
end
it "registers an offense for pages named `page`" do
expect_offense(<<-RUBY)
Page::Layout::Bar.perform do |page|
^^^^ Don't use 'page' as a name for a Page Object. Use `bar` instead.
expect(page).to have_performance_bar
expect(page).to have_detailed_metrics
end
RUBY
end
it "doesnt offend if the page object is named otherwise" do
expect_no_offenses(<<-RUBY)
Page::Object.perform do |obj|
obj.whatever
end
RUBY
end
end
context 'outside of a QA file' do
before do
allow(cop).to receive(:in_qa_file?).and_return(false)
end
it "does not register an offense" do
expect_no_offenses(<<-RUBY)
Page::Object.perform do |page|
page.do_something
end
RUBY
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment