Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use squiggly heredocs wherever possible #91

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/rubocop/cop/capybara/current_path_expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ class CurrentPathExpectation < ::RuboCop::Cop::Base
RESTRICT_ON_SEND = %i[expect].freeze

# @!method expectation_set_on_current_path(node)
def_node_matcher :expectation_set_on_current_path, <<-PATTERN
def_node_matcher :expectation_set_on_current_path, <<~PATTERN
(send nil? :expect (send {(send nil? :page) nil?} :current_path))
PATTERN

# Supported matchers: eq(...) / match(/regexp/) / match('regexp')
# @!method as_is_matcher(node)
def_node_matcher :as_is_matcher, <<-PATTERN
def_node_matcher :as_is_matcher, <<~PATTERN
(send
#expectation_set_on_current_path ${:to :to_not :not_to}
${(send nil? :eq ...) (send nil? :match (regexp ...))})
PATTERN

# @!method regexp_node_matcher(node)
def_node_matcher :regexp_node_matcher, <<-PATTERN
def_node_matcher :regexp_node_matcher, <<~PATTERN
(send
#expectation_set_on_current_path ${:to :to_not :not_to}
$(send nil? :match ${str dstr xstr}))
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/capybara/specific_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SpecificActions < ::RuboCop::Cop::Base
}.freeze

# @!method click_on_selector(node)
def_node_matcher :click_on_selector, <<-PATTERN
def_node_matcher :click_on_selector, <<~PATTERN
(send _ :find (str $_) ...)
PATTERN

Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/capybara/specific_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class SpecificMatcher < ::RuboCop::Cop::Base
}.freeze

# @!method first_argument(node)
def_node_matcher :first_argument, <<-PATTERN
def_node_matcher :first_argument, <<~PATTERN
(send nil? _ (str $_) ... )
PATTERN

# @!method text_with_regexp?(node)
def_node_search :text_with_regexp?, <<-PATTERN
def_node_search :text_with_regexp?, <<~PATTERN
(pair (sym {:text :exact_text}) (regexp ...))
PATTERN

Expand Down
2 changes: 1 addition & 1 deletion rubocop-capybara.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require 'rubocop/capybara/version'
Gem::Specification.new do |spec|
spec.name = 'rubocop-capybara'
spec.summary = 'Code style checking for Capybara test files'
spec.description = <<-DESCRIPTION
spec.description = <<~DESCRIPTION
Code style checking for Capybara test files (RSpec, Cucumber, Minitest).
A plugin for the RuboCop code style enforcing & linting tool.
DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/capybara/description_extractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

RSpec.describe RuboCop::Capybara::DescriptionExtractor do
let(:yardocs) do
YARD.parse_string(<<-RUBY)
YARD.parse_string(<<~RUBY)
# This is not a cop
class RuboCop::Cop::Mixin::Sneaky
end
Expand Down
10 changes: 5 additions & 5 deletions spec/rubocop/cop/capybara/current_path_expectation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
end

it 'flags offenses for `expect(page.current_path)`' do
expect_offense(<<-RUBY)
expect_offense(<<~RUBY)
expect(page.current_path).to eq("/callback")
^^^^^^ Do not set an RSpec expectation on `current_path` in Capybara feature specs - instead, use the `have_current_path` matcher on `page`
RUBY

expect_correction(<<-RUBY)
expect_correction(<<~RUBY)
expect(page).to have_current_path("/callback", ignore_query: true)
RUBY
end
Expand Down Expand Up @@ -208,19 +208,19 @@
end

it "doesn't flag an offense for other expectations" do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
expect(current_user).to eq(user)
RUBY
end

it "doesn't flag an offense for other references to `current_path`" do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
current_path = WalkingRoute.last.path
RUBY
end

it 'ignores `match` with a variable, but does not autocorrect' do
expect_offense(<<-RUBY)
expect_offense(<<~RUBY)
expect(page.current_path).to match(variable)
^^^^^^ Do not set an RSpec expectation on `current_path` in Capybara feature specs - instead, use the `have_current_path` matcher on `page`
RUBY
Expand Down
38 changes: 19 additions & 19 deletions spec/rubocop/cop/capybara/specific_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,31 @@

it 'does not register an offense for find and click actions when ' \
'first argument is multiple selector `,`' do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
find('button,a').click
find('a, button').click
RUBY
end

it 'does not register an offense for find and click actions when ' \
'first argument is multiple selector `>`' do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
find('button>a').click
find('a > button').click
RUBY
end

it 'does not register an offense for find and click actions when ' \
'first argument is multiple selector `+`' do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
find('button+a').click
find('a + button').click
RUBY
end

it 'does not register an offense for find and click actions when ' \
'first argument is multiple selector `~`' do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
find('button~a').click
find('a ~ button').click
RUBY
Expand All @@ -94,7 +94,7 @@
it 'registers an offense for abstract action when ' \
"first argument is element with replaceable attributes #{attr} " \
'for `click_button`' do
expect_offense(<<-RUBY, attr: attr)
expect_offense(<<~RUBY, attr: attr)
find("button[#{attr}=foo]").click
^^^^^^^^^^^^^^{attr}^^^^^^^^^^^^^ Prefer `click_button` over `find('button').click`.
RUBY
Expand All @@ -105,7 +105,7 @@
it 'does not register an offense for abstract action when ' \
"first argument is element with replaceable attributes #{attr} " \
'for `click_link` without `href`' do
expect_no_offenses(<<-RUBY, attr: attr)
expect_no_offenses(<<~RUBY, attr: attr)
find("a[#{attr}=foo]").click
find("a[#{attr}]").click
RUBY
Expand All @@ -114,7 +114,7 @@
it 'registers an offense for abstract action when ' \
"first argument is element with replaceable attributes #{attr} " \
'for `click_link` with attribute `href`' do
expect_offense(<<-RUBY, attr: attr)
expect_offense(<<~RUBY, attr: attr)
find("a[#{attr}=foo][href='http://example.com']").click
^^^^^^^^^{attr}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `click_link` over `find('a').click`.
RUBY
Expand All @@ -123,7 +123,7 @@
it 'registers an offense for abstract action when ' \
"first argument is element with replaceable attributes #{attr} " \
'for `click_link` with option `href`' do
expect_offense(<<-RUBY, attr: attr)
expect_offense(<<~RUBY, attr: attr)
find("a[#{attr}=foo]", href: 'http://example.com').click
^^^^^^^^^{attr}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `click_link` over `find('a').click`.
find("a[#{attr}=foo]", text: 'foo', href: 'http://example.com').click
Expand All @@ -134,30 +134,30 @@

it 'registers an offense when using abstract action with ' \
'first argument is element with multiple replaceable attributes' do
expect_offense(<<-RUBY)
expect_offense(<<~RUBY)
find('button[disabled=true][name="foo"]', exact_text: 'foo').click
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `click_button` over `find('button').click`.
RUBY
end

it 'registers an offense when using abstract action with state' do
expect_offense(<<-RUBY)
expect_offense(<<~RUBY)
find('button[disabled=false]', exact_text: 'foo').click
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `click_button` over `find('button').click`.
RUBY
end

it 'registers an offense when using abstract action with ' \
'first argument is element with replaceable pseudo-classes' do
expect_offense(<<-RUBY)
expect_offense(<<~RUBY)
find('button:not([disabled=true])', exact_text: 'bar').click
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `click_button` over `find('button').click`.
RUBY
end

it 'registers an offense when using abstract action with ' \
'first argument is element with multiple replaceable pseudo-classes' do
expect_offense(<<-RUBY)
expect_offense(<<~RUBY)
find('button:not([disabled=true]):enabled').click
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `click_button` over `find('button').click`.
find('button:not([disabled=false]):disabled').click
Expand All @@ -167,7 +167,7 @@

it 'does not register an offense when using abstract action with' \
'first argument is element with not replaceable attributes' do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
find('button[disabled]').click
find('button[id=some-id][disabled]').click
find('button[visible]').click
Expand All @@ -177,21 +177,21 @@
it 'does not register an offense when using abstract action with ' \
'first argument is element with replaceable pseudo-classes' \
'and not boolean attributes' do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
find('button:not([name="foo"][disabled=true])').click
RUBY
end

it 'does not register an offense when using abstract action with ' \
'first argument is element with multiple nonreplaceable pseudo-classes' do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
find('button:first-of-type:not([disabled=true])').click
RUBY
end

it 'does not register an offense for abstract action when ' \
'first argument is element with nonreplaceable attributes' do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
find('button[data-disabled=true]').click
find('button[foo=bar]').click
find('button[foo-bar=baz]', exact_text: 'foo').click
Expand All @@ -200,7 +200,7 @@

it 'does not register an offense for abstract action when ' \
'first argument is element with multiple nonreplaceable attributes' do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
find('button[disabled=true][foo=bar]').click
find('button[foo=bar][disabled=true]').click
find('button[foo=bar][disabled=true][bar=baz]').click
Expand All @@ -211,15 +211,15 @@

it 'does not register an offense for find and click actions when ' \
'first argument is not a replaceable element' do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
find('article').click
find('body').click
RUBY
end

it 'does not register an offense for find and click actions when ' \
'first argument is not an element' do
expect_no_offenses(<<-RUBY)
expect_no_offenses(<<~RUBY)
find('.a').click
find('#button').click
find('[a]').click
Expand Down
Loading