Skip to content

Capybara/CurrentPathExpectation autocorrect incompatible with Style/TrailingComma autocorrect #1237

Closed
@izzergh

Description

@izzergh

rubocop version: 1.18.3
rubocop-rspec version: 2.4.0

Example code:

# original code
expect(current_path).to eq(
  some_path(
    record_id: record.id
  )
)

If Style/TrailingComma (in vanilla rubocop) is enabled for methods, it adds a comma after record.id and after the closed parenthesis.

Also, Capybara/CurrentPathExpectation adds , ignore_query: true to the have_current_path params. If both are fixed with the same autocorrect, the following is the result:

# after autocorrect
expect(page).to have_current_path(
  some_path(
    record_id: record.id
  ),, ignore_query: true
)

which is a syntax error (the double-comma) and still doesn't have the trailing comma.

A workaround is to run the Style cops first, then the RSpec cops, or vice-versa - just not in the same command

Activity

changed the title [-]Capybara/CurrentPathException autocorrect incompatible with Style/TrailingComma autocorrect[/-] [+]Capybara/CurrentPathExpectation autocorrect incompatible with Style/TrailingComma autocorrect[/+] on Feb 23, 2022
pirj

pirj commented on Feb 24, 2022

@pirj
Member

Thanks for reporting. Would you like to submit a PR?
I see two ways to resolving this:

  1. check if expectation_last_child contains a trailing comma
  2. strip expectation_last_child from its trailing comma with what RangeHelp provides (not sure if it's possible just by glancing at its code)
added a commit that references this issue on Mar 21, 2022

[Fix rubocop#1237] Fix `Capybara/CurrentPathExpectation` autocorrect …

1a03241
added 4 commits that reference this issue on Mar 22, 2022

[Fix rubocop#1237] Fix `Capybara/CurrentPathExpectation` autocorrect …

e23a512

[Fix rubocop#1237] Fix `Capybara/CurrentPathExpectation` autocorrect …

25c2f02

[Fix rubocop#1237] Fix `Capybara/CurrentPathExpectation` autocorrect …

d04fce9

[Fix rubocop#1237] Fix `Capybara/CurrentPathExpectation` autocorrect …

e0756c0
added 2 commits that reference this issue on Mar 25, 2022

[Fix rubocop#1237] Fix `Capybara/CurrentPathExpectation` autocorrect …

ed35dae

[Fix rubocop#1237] Fix `Capybara/CurrentPathExpectation` autocorrect …

eaeadbb
added a commit that references this issue on Mar 25, 2022

Merge pull request #1253 from ydah/fix-capybara-current-path-expectat…

1f2503b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @pirj@izzergh

      Issue actions

        Capybara/CurrentPathExpectation autocorrect incompatible with Style/TrailingComma autocorrect · Issue #1237 · rubocop/rubocop-rspec