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

Add RuboCop RSpec support #138

Merged
merged 1 commit into from Nov 18, 2020
Merged

Conversation

pirj
Copy link
Contributor

@pirj pirj commented Nov 8, 2020

What is the purpose of this pull request?

Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls.

See:

Example project:

Gemfile:

# frozen_string_literal: true

source 'https://rubygems.org'

gem 'action_policy', path: '../../action_policy'
gem 'rubocop-rspec'

.rubocop.yml:

AllCops:
  NewCops: enable

require:
  - rubocop-rspec

inherit_gem:
  action_policy: .rubocop-rspec-aliases.yml

spec/policies/a_policy_spec.rb:

# frozen_string_literal: true

RSpec.describe 'A' do
  describe_rule :luck? do
    succeed 'when stars align'
  end
end

Before

$ rubocop
Inspecting 2 files
.C

Offenses:

spec/policies/a_policy_spec.rb:3:1: C: RSpec/EmptyExampleGroup: Empty example group detected.
RSpec.describe 'A' do
^^^^^^^^^^^^^^^^^^

2 files inspected, 1 offense detected

After

$ rubocop
Inspecting 2 files
..

2 files inspected, no offenses detected

What changes did you make? (overview)

  • added an RSpec alias config file that RuboCop is able to load and append to the default RuboCop RSpec alias configuration.
  • added docs on how to tell RuboCop to use those aliases

Is there anything you'd like reviewers to focus on?

I don't have any real projects using Action Policy handy. Please test this change on a real project.

Should I through in some spec that uses describe_rule/succeed/... aliases so that Lint Ruby build job checked them with rubocop-rspec and made sure there are no offences?


PR checklist:

  • [-] Tests included
  • Documentation updated
  • Changelog entry added

pirj added a commit to pirj/test-prof that referenced this pull request Nov 9, 2020
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of
cops were failing false offences, and some cops were unable to lint, as
they were skipping locally defined RSpec aliases taking them for
arbitrary blocks and method calls.

See:
 - rubocop/rubocop-rspec#1077
 - rubocop/rubocop-rspec#956

Sibling pull requests:
 - palkan/action_policy#138
pirj added a commit to pirj/test-prof that referenced this pull request Nov 9, 2020
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of
cops were failing false offences, and some cops were unable to lint, as
they were skipping locally defined RSpec aliases taking them for
arbitrary blocks and method calls.

See:
 - rubocop/rubocop-rspec#1077
 - rubocop/rubocop-rspec#956

Sibling pull requests:
 - palkan/action_policy#138
pirj added a commit to pirj/test-prof that referenced this pull request Nov 9, 2020
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of
cops were failing false offences, and some cops were unable to lint, as
they were skipping locally defined RSpec aliases taking them for
arbitrary blocks and method calls.

See:
 - rubocop/rubocop-rspec#1077
 - rubocop/rubocop-rspec#956

Sibling pull requests:
 - palkan/action_policy#138
Copy link
Owner

@palkan palkan left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks!

Just one request: let's move the config file into the config/rubocop-rspec.yml or anything else, just not the project's root folder.

@pirj
Copy link
Contributor Author

pirj commented Nov 17, 2020

Sounds good, will move in both PRs 👍

Previously, RuboCop RSpec failed to detect RSpec aliases. A number of
cops were failing false offences, and some cops were unable to lint, as
they were skipping locally defined RSpec aliases taking them for
arbitrary blocks and method calls.

See:
 - rubocop/rubocop-rspec#1077
 - rubocop/rubocop-rspec#956
 - palkan#103
pirj added a commit to pirj/test-prof that referenced this pull request Nov 17, 2020
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of
cops were failing false offences, and some cops were unable to lint, as
they were skipping locally defined RSpec aliases taking them for
arbitrary blocks and method calls.

See:
 - rubocop/rubocop-rspec#1077
 - rubocop/rubocop-rspec#956

Sibling pull requests:
 - palkan/action_policy#138
@pirj
Copy link
Contributor Author

pirj commented Nov 17, 2020

Moved the config and tested again, works.

@palkan palkan merged commit 5b7e23b into palkan:master Nov 18, 2020
@palkan
Copy link
Owner

palkan commented Nov 18, 2020

Thanks!

@pirj pirj deleted the add-rubocop-rspec-support branch November 18, 2020 16:13
pirj added a commit to pirj/test-prof that referenced this pull request Nov 18, 2020
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of
cops were failing false offences, and some cops were unable to lint, as
they were skipping locally defined RSpec aliases taking them for
arbitrary blocks and method calls.

See:
 - rubocop/rubocop-rspec#1077
 - rubocop/rubocop-rspec#956

Sibling pull requests:
 - palkan/action_policy#138
palkan pushed a commit to test-prof/test-prof that referenced this pull request Nov 18, 2020
Previously, RuboCop RSpec failed to detect RSpec aliases. A number of
cops were failing false offences, and some cops were unable to lint, as
they were skipping locally defined RSpec aliases taking them for
arbitrary blocks and method calls.

See:
 - rubocop/rubocop-rspec#1077
 - rubocop/rubocop-rspec#956

Sibling pull requests:
 - palkan/action_policy#138
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

2 participants