Welcome to mirror list, hosted at ThFree Co, Russian Federation.

element_with_pattern_spec.rb « qa « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ccc03d7f5ae83f3611db5023889503fde361e94c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true

require 'rubocop_spec_helper'

require_relative '../../../../rubocop/cop/qa/element_with_pattern'

RSpec.describe RuboCop::Cop::QA::ElementWithPattern do
  let(:source_file) { 'qa/page.rb' }

  context 'in a QA file' do
    before do
      allow(cop).to receive(:in_qa_file?).and_return(true)
    end

    it "registers an offense for elements with a pattern" do
      expect_offense(<<-RUBY)
      view 'app/views/shared/groups/_search_form.html.haml' do
        element :groups_filter, 'search_field_tag :filter'
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't use a pattern for element, create a corresponding `data-qa-selector=groups_filter` instead.
        element :groups_filter_placeholder, /Search by name/
                                             ^^^^^^^^^^^^^^ Don't use a pattern for element, create a corresponding `data-qa-selector=groups_filter_placeholder` instead.
      end
      RUBY
    end

    it "does not register an offense for element without a pattern" do
      expect_no_offenses(<<-RUBY)
      view 'app/views/shared/groups/_search_form.html.haml' do
        element :groups_filter
        element :groups_filter_placeholder
      end
      RUBY

      expect_no_offenses(<<-RUBY)
      view 'app/views/shared/groups/_search_form.html.haml' do
        element :groups_filter, required: true
        element :groups_filter_placeholder, required: false
      end
      RUBY
    end
  end

  context 'when outside of a QA spec file' do
    it "does not register an offense" do
      expect_no_offenses(<<-RUBY)
        describe 'foo' do
          let(:user) { create(:user) }
        end
      RUBY
    end
  end
end