Commit 015b61b1 authored by ddavison's avatar ddavison

Change element_with_pattern cop to not use quotes

Using quotes within string validations can be messy. Let's
use  a typical CSS selector for an unquoted attribute

Update the cop spec to validate appropriate new message
parent 98fc3f23
...@@ -30,7 +30,7 @@ module RuboCop ...@@ -30,7 +30,7 @@ module RuboCop
return if args.first.nil? return if args.first.nil?
args.first.each_node(:str) do |arg| args.first.each_node(:str) do |arg|
add_offense(arg, message: MESSAGE % "data-qa-selector=\"#{element_name.value}\"") add_offense(arg, message: MESSAGE % "data-qa-selector=#{element_name.value}")
end end
end end
......
...@@ -23,9 +23,9 @@ describe RuboCop::Cop::QA::ElementWithPattern do ...@@ -23,9 +23,9 @@ describe RuboCop::Cop::QA::ElementWithPattern do
expect_offense(<<-RUBY) expect_offense(<<-RUBY)
view 'app/views/shared/groups/_search_form.html.haml' do view 'app/views/shared/groups/_search_form.html.haml' do
element :groups_filter, 'search_field_tag :filter' element :groups_filter, 'search_field_tag :filter'
^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't use a pattern for element, create a corresponding `qa-groups-filter` instead. ^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't use a pattern for element, create a corresponding `data-qa-selector=groups_filter` instead.
element :groups_filter_placeholder, /Search by name/ element :groups_filter_placeholder, /Search by name/
^^^^^^^^^^^^^^ Don't use a pattern for element, create a corresponding `qa-groups-filter-placeholder` instead. ^^^^^^^^^^^^^^ Don't use a pattern for element, create a corresponding `data-qa-selector=groups_filter_placeholder` instead.
end end
RUBY RUBY
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