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

Extract Capybara cops #1519

Merged
merged 3 commits into from Jan 14, 2023
Merged

Extract Capybara cops #1519

merged 3 commits into from Jan 14, 2023

Conversation

pirj
Copy link
Member

@pirj pirj commented Dec 15, 2022

#1440

Extracted to https://github.com/rubocop/rubocop-capybara

To test that cop renaming isn't a breaking change, add some Capybara cop configuration to some other project, and:

  1. Observe a cop renamed warning
.rubocop.yml: RSpec/Capybara/SpecificActions has the wrong namespace - should be Capybara
  1. No errors!

TODO

  • once the gem is published, remove the temp commit that adds rubocop-capybara to Gemfile

Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • [-] Added tests.
  • [-] Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

@pirj pirj self-assigned this Dec 15, 2022
Gemfile Outdated Show resolved Hide resolved
@koic
Copy link
Member

koic commented Dec 16, 2022

Extracted to https://github.com/rubocop-hq/rubocop-capybara

@pirj I've created https://github.com/rubocop/rubocop-capybara repository and granting permissions to the RuboCop RSpec team.

JFYI, It's probably best to have commit history. Once upon a time when I extracted Performance and Rails from the RuboCop core, I used git cherry-pick, not cp:
https://speakerdeck.com/koic/road-to-rubocop-1-dot-0?slide=26

However, there may be a better way :-)

@bquorning
Copy link
Collaborator

It's probably best to have commit history.

I agree, we should try hard to keep the commit history.

@pirj When you move the code to the new repo, could you do it in another branch than master/main, and open a pull request for us to review and merge?

@pirj
Copy link
Member Author

pirj commented Dec 16, 2022

I've created https://github.com/rubocop/rubocop-capybara repository and granting permissions to the RuboCop RSpec team.

Thanks a lot, @koic ! ❤️

@pirj
Copy link
Member Author

pirj commented Dec 18, 2022

The problem with no history I believe is down to this:
image

Git doesn't seem to be able to detect file renames of significantly changed files.
I intend to split this into two commits, one for file rename, and another to change the indentation.

@pirj
Copy link
Member Author

pirj commented Dec 18, 2022

rubocop-hq/rubocop-capybara#1 - reviews are welcome.

Gemfile Outdated Show resolved Hide resolved
@pirj
Copy link
Member Author

pirj commented Dec 22, 2022

@koic I'm trying to git push --set-upstream origin master

ERROR: Permission to rubocop/rubocop-capybara.git denied to pirj.
fatal: Could not read from remote repository.

May I kindly ask you to check permissions there?

@pirj
Copy link
Member Author

pirj commented Dec 26, 2022

@koic @bbatsov May I kindly ask you to check permissions in https://github.com/rubocop/rubocop-capybara?
I'd suggest adding @ydah as a maintainer there, as he had contributed a significant part of cops there.
I'll make sure to set gem publishing rights to @bquorning @Darhazer @ydah and optionally myself.

Merry X-Mas! 🎄

@koic
Copy link
Member

koic commented Dec 26, 2022

@pirj @ydah

May I kindly ask you to check permissions in https://github.com/rubocop/rubocop-capybara?

Sorry for the late reply. I just checked and I had insufficient write permissions. So updated the permissions.

I'd suggest adding @ydah as a maintainer there, as he had contributed a significant part of cops there.

I've invited as a collaborator for RuboCop Capybara.

Merry Christmas! 🎄

@koic
Copy link
Member

koic commented Dec 26, 2022

@pirj JFYI, I think @bquorning can also manage repositories and collaborators related to the RuboCop RSpec. Thank you.

@ydah
Copy link
Member

ydah commented Dec 26, 2022

@pirj Thanks for the recommendation! I'm very honored.
@koic Thank you for the invitation. I accepted and successfully became a collaborator.

Today is a very wonderful day for me. I really appreciate all of you.
Merry X-Mas! 🎄

@pirj
Copy link
Member Author

pirj commented Dec 29, 2022

Looks green. Removed the hack to use rubocop-capybara from GitHub source, now it should pick the one from RubyGems.

Copy link
Collaborator

@bquorning bquorning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be really nitpicking, the commit messages and PR description are a bit out of date after the recent publishing of the rubocop-capybara gem.

@pirj
Copy link
Member Author

pirj commented Dec 29, 2022

@bquorning Fair enough 👍. Updated the PR description and the first commit's message.

@pirj
Copy link
Member Author

pirj commented Dec 29, 2022

I really appreciate if you find some time and test it on some real project that is uses rubocop-rspec and preferably extracted cops to make sure those cops are still on duty :shrek-cat-eyes:

@pirj
Copy link
Member Author

pirj commented Dec 29, 2022

I'll dump this here for history.

A method to keep the history for a limited number of files in the repo:

git clone --no-local rubocop-rspec rubocop-capybara-hist
cd rubocop-capybara-hist
git-filter-repo $( (cat ../rubocop-capybara/rename | xargs -I_ echo '--path-rename _ ') )
git-filter-repo $( (cd ../rubocop-capybara && git ls-files) | xargs -I_ echo '--path _ ')
git remote add origin git@github.com:rubocop/rubocop-capybara.git
git push --set-upstream origin master
git checkout -b capybara-only
cd ../rubocop-capybara
cp -r * ../rubocop-capybara-hist
cp -r $( git ls-files | grep '^\.' | grep -v '\.github' ) ../rubocop-capybara-hist
cp -r .github ../rubocop-capybara-hist
cd -
git commit --all --message 'RSpec -> Capybara'
rvm use --create 3.0.4@rubocop-capybara
bundle
rake
git push origin capybara-only
hub pull-request --assign pirj

rename:

docs/modules/ROOT/pages/cops_rspec_capybara.adoc:docs/modules/ROOT/pages/cops_capybara.adoc
docs/modules/ROOT/pages/development.adoc:docs/modules/ROOT/pages/development.adoc
docs/modules/ROOT/pages/index.adoc:docs/modules/ROOT/pages/index.adoc
docs/modules/ROOT/pages/installation.adoc:docs/modules/ROOT/pages/installation.adoc
docs/modules/ROOT/pages/usage.adoc:docs/modules/ROOT/pages/usage.adoc
lib/rubocop/rspec/config_formatter.rb:lib/rubocop/capybara/config_formatter.rb
lib/rubocop/rspec/description_extractor.rb:lib/rubocop/capybara/description_extractor.rb
lib/rubocop/rspec/version.rb:lib/rubocop/capybara/version.rb
lib/rubocop/cop/rspec/mixin/capybara_help.rb:lib/rubocop/cop/capybara/mixin/capybara_help.rb
lib/rubocop/cop/rspec/mixin/css_selector.rb:lib/rubocop/cop/capybara/mixin/css_selector.rb
lib/rubocop/cop/rspec/capybara/current_path_expectation.rb:lib/rubocop/cop/capybara/current_path_expectation.rb
lib/rubocop/cop/rspec/capybara/match_style.rb:lib/rubocop/cop/capybara/match_style.rb
lib/rubocop/cop/rspec/capybara/negation_matcher.rb:lib/rubocop/cop/capybara/negation_matcher.rb
lib/rubocop/cop/rspec/capybara/specific_actions.rb:lib/rubocop/cop/capybara/specific_actions.rb
lib/rubocop/cop/rspec/capybara/specific_finders.rb:lib/rubocop/cop/capybara/specific_finders.rb
lib/rubocop/cop/rspec/capybara/specific_matcher.rb:lib/rubocop/cop/capybara/specific_matcher.rb
lib/rubocop/cop/rspec/capybara/visibility_matcher.rb:lib/rubocop/cop/capybara/visibility_matcher.rb
lib/rubocop/cop/rspec_cops.rb:lib/rubocop/cop/capybara_cops.rb
lib/rubocop-rspec.rb:lib/rubocop-capybara.rb
rubocop-rspec.gemspec:rubocop-capybara.gemspec
spec/project/changelog_spec.rb:spec/project/changelog_spec.rb
spec/project/default_config_spec.rb:spec/project/default_config_spec.rb
spec/rubocop/rspec/config_formatter_spec.rb:spec/rubocop/capybara/config_formatter_spec.rb
spec/rubocop/rspec/description_extractor_spec.rb:spec/rubocop/capybara/description_extractor_spec.rb
spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb:spec/rubocop/cop/capybara/current_path_expectation_spec.rb
spec/rubocop/cop/rspec/capybara/match_style_spec.rb:spec/rubocop/cop/capybara/match_style_spec.rb
spec/rubocop/cop/rspec/capybara/negation_matcher_spec.rb:spec/rubocop/cop/capybara/negation_matcher_spec.rb
spec/rubocop/cop/rspec/capybara/specific_actions_spec.rb:spec/rubocop/cop/capybara/specific_actions_spec.rb
spec/rubocop/cop/rspec/capybara/specific_finders_spec.rb:spec/rubocop/cop/capybara/specific_finders_spec.rb
spec/rubocop/cop/rspec/capybara/specific_matcher_spec.rb:spec/rubocop/cop/capybara/specific_matcher_spec.rb
spec/rubocop/cop/rspec/capybara/visibility_matcher_spec.rb:spec/rubocop/cop/capybara/visibility_matcher_spec.rb

checklist:

  • push master and a branch with an identical PR to rubocop/rubocop-capybara as soon as I have proper permissions to push there
  • publish the gem, and share publish rights with maintainers
  • send a PR to https://github.com/rubocop/docs.rubocop.org/ to add the new extension

@bquorning
Copy link
Collaborator

Two questions:

  1. Now that the cops exist in the rubocop-capybara gem, and we have obsoletion code in place – shouldn’t we delete the classes from rubocop-rspec?
  2. What happens to the FeatureMethods cop? Should we move it into RSpec namespace?

I am sorry if these questions have already been asked and answered elsewhere.

@bquorning
Copy link
Collaborator

I ran rubocop --regenerate-todo on a project, and it finished with this error:

Error: The RSpec/Capybara/SpecificMatcher cop has been moved to Capybara/SpecificMatcher.
(obsolete configuration found in .rubocop_todo.yml, please update it)

Now the TODO file contains both a section for both Capybara/SpecificMatcher and RSpec/Capybara/SpecificMatcher. And a lot of lines are missing from the “regenerated” TODO file, so it seems the error above causes the generation to end prematurely.

@bquorning
Copy link
Collaborator

Is the intention to extract all 3 new gems in the same RuboCop-RSpec release? I keep going back and forth on whether that would be a good idea or not.

@pirj
Copy link
Member Author

pirj commented Jan 11, 2023

Good question!
I can't think of any benefit of extracting all three at once. There are certain risks something goes wrong.
The only far-fetched downside of extracting iteratively would be different starting versions.

Copy link
Member

@ydah ydah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good😀 Great work 🎉

As for the future extraction schedule, it seems less risky and better to complete the extraction of Capybara and confirm that there seems to be no problem after the release, and then proceed with the next extraction after we are confident of success.

Note that I am opening the following PR for FactoryBot, but I don't think it will be a stop for extraction, so please don't worry about it and proceed.
Even if the extraction is done first, the PR is modified for the post-extraction repository and sent again 👍

Copy link
Collaborator

@bquorning bquorning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@koic
Copy link
Member

koic commented Jan 12, 2023

@pirj Please let me have some feedback.

No errors!

I get the following error. My local changes are below:

% git diff 
diff --git a/.rubocop.yml b/.rubocop.yml
index 9223aa07..c07d140c 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -16,6 +16,9 @@ AllCops:
     - 'tmp/**/*'
     - 'spec/smoke_tests/**/*.rb'

+RSpec/Capybara/SpecificActions:
+  Enabled: true
+
 Layout/HashAlignment:
   EnforcedHashRocketStyle:
     - key
diff --git a/Gemfile b/Gemfile
index ad31d642..8e2c8cad 100644
--- a/Gemfile
+++ b/Gemfile
@@ -8,7 +8,7 @@ gem 'bump'
 gem 'rack'
 gem 'rake'
 gem 'rspec', '~> 3.11'
-gem 'rubocop-capybara', github: 'rubocop-hq/rubocop-capybara'
+gem 'rubocop-capybara', github: 'rubocop/rubocop-capybara'
 gem 'rubocop-performance', '~> 1.7'
 gem 'rubocop-rake', '~> 0.6'
 gem 'yard'

It's a reproduction:

% bundle exec rubocop --only RSpec/Capybara/SpecificActions
Error: The `RSpec/Capybara/SpecificActions` cop has been moved to `Capybara/SpecificActions`.
(obsolete configuration found in .rubocop.yml, please update it)

This works like this because of the Base.inherited hook.

I'm sorry, I forgot this existed. In the current implementation, it may be simpler to use inheritance as the first your suggestion.

As an example, I updated rubocop/rubocop#11111 to prevent breaking change. The points are below:

  • Inherit deprecated cop
  • Update deprecated cop docs
  • Add VersionRemoved to deprecated config/config.yml (Actually, VersionRemoved has never been used, so I'm not sure if it's appropriate)
  • Comment out config/obsoletion.yml. If not commented out, an error will occur when a deprecated name is specified in .rubocop.yml

So, it saves the documentation generation hacks and prevents the error.

@koic
Copy link
Member

koic commented Jan 12, 2023

I get the following error. My local changes are below:

Oops, I was using old resources. The warning displays as expected:

% bundle exec rubocop --only RSpec/Capybara/SpecificActions
.rubocop.yml: RSpec/Capybara/SpecificActions has the wrong namespace - should be Capybara
--only option: RSpec/Capybara/SpecificActions has the wrong namespace - should be Capybara
(snip)

Please don’t worry about it. 🙇

@bquorning
Copy link
Collaborator

Yes, as I understand this extraction, we require our users to change any explicit RSpec/Capybara/SpecificActions in their config into Capybara/SpecificActions.

@pirj
Copy link
Member Author

pirj commented Jan 12, 2023

we require our users to change any explicit RSpec/Capybara/SpecificActions in their config into Capybara/SpecificActions.

Not really. We just warn them that they may want to change it.

@bquorning
Copy link
Collaborator

@pirj If you consider this PR done, you should feel free to merge at will. We can then release this as v2.18.0 without any other changes. Or would you prefer a v2.18.0.pre?

`load_file` throws obsoletion errors
...and soft-aliasing the old one with a constant pointing to a class
@pirj pirj merged commit 41be00e into master Jan 14, 2023
@pirj pirj deleted the extract-capybara-cops branch January 14, 2023 05:50
@pirj
Copy link
Member Author

pirj commented Jan 14, 2023

would you prefer a v2.18.0.pre?

Good question. Does it require a --pre Bundler flag to be installed? I can't recall if I've seen this used in practice.

@bquorning
Copy link
Collaborator

Yea, exactly that. But perhaps it’s not necessary?

By the way, there were a few patches merged into master yesterday. I’ll see if I can release them separately from this change even though they’re both merged.

@Darhazer
Copy link
Member

Sorry I've missed your plan for release and merged some patches

@bquorning
Copy link
Collaborator

No worries. It wasn’t well communicated to start with. 😅

@Drenmi
Copy link
Contributor

Drenmi commented Jun 9, 2023

What happens to the FeatureMethods cop? Should we move it into RSpec namespace?

It seems to me this should also go in rubocop-capybara, since it concerns the Capybara DSL. I'll be happy to lift and shift this unless there are any objections. Maybe @pirj had a reason for omitting it?

@pirj
Copy link
Member Author

pirj commented Jun 9, 2023

@Drenmi It’s intentional. Even though it would only detect Captbara aliases, it is specific to RSpec aliases. It might become a more generic cop, covering more aliases to make specs less magic-y, and more RSpec’y, like e.g. https://actionpolicy.evilmartians.io/#/./testing?id=rspec-dsl
We can make it configurable in those other gems (I hope config parsing would work with loose dependency).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants