2019-03-02 02:03:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-17 06:08:43 +00:00
|
|
|
require 'fast_spec_helper'
|
2018-10-11 17:10:42 +00:00
|
|
|
|
|
|
|
require_relative '../../../../rubocop/cop/qa/element_with_pattern'
|
|
|
|
|
2021-01-07 18:10:38 +00:00
|
|
|
RSpec.describe RuboCop::Cop::QA::ElementWithPattern do
|
2018-10-11 17:10:42 +00:00
|
|
|
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 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'
|
2019-07-09 21:44:16 +00:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't use a pattern for element, create a corresponding `data-qa-selector=groups_filter` instead.
|
2018-10-11 17:10:42 +00:00
|
|
|
element :groups_filter_placeholder, /Search by name/
|
2019-07-09 21:44:16 +00:00
|
|
|
^^^^^^^^^^^^^^ Don't use a pattern for element, create a corresponding `data-qa-selector=groups_filter_placeholder` instead.
|
2018-10-11 17:10:42 +00:00
|
|
|
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
|
2019-03-02 02:03:43 +00:00
|
|
|
|
|
|
|
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
|
2018-10-11 17:10:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'outside of a migration 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
|