diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-03 21:10:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-03 21:10:02 +0300 |
commit | 49058851264455c22a5ba00c8671b7d4cdfd8ee9 (patch) | |
tree | 6626f6610b69b418cea728edb1d804c79e189d29 /spec/rubocop/cop | |
parent | f397d486bc77b286d42f83b89e0879428c05299d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop/cop')
-rw-r--r-- | spec/rubocop/cop/qa/selector_usage_spec.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/rubocop/cop/qa/selector_usage_spec.rb b/spec/rubocop/cop/qa/selector_usage_spec.rb new file mode 100644 index 00000000000..b40c57f8991 --- /dev/null +++ b/spec/rubocop/cop/qa/selector_usage_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +require_relative '../../../../rubocop/cop/qa/selector_usage' + +RSpec.describe RuboCop::Cop::QA::SelectorUsage do + subject(:cop) { described_class.new } + + shared_examples 'non-qa file usage' do + it 'reports an offense' do + expect_offense(<<-RUBY) + find('#{selector}').click + #{'^' * (selector.size + 2)} Do not use `#{selector}` as this is reserved for the end-to-end specs. Use a different selector or a data-testid instead. + RUBY + end + end + + context 'in a QA file' do + before do + allow(cop).to receive(:in_qa_file?).and_return(true) + end + + it 'has no error' do + expect_no_offenses(<<-RUBY) + has_element?('[data-qa-selector="my_selector"]') + RUBY + end + end + + context 'outside of QA' do + before do + allow(cop).to receive(:in_qa_file?).and_return(false) + allow(cop).to receive(:in_spec?).and_return(true) + end + + context 'data-qa-selector' do + let(:selector) { '[data-qa-selector="my_selector"]' } + + it_behaves_like 'non-qa file usage' + end + + context 'qa class' do + let(:selector) { '.qa-selector' } + + it_behaves_like 'non-qa file usage' + end + end +end |