varvet / pundit

Minimal authorization through OO design and pure Ruby classes
MIT License
8.28k stars 629 forks source link

Add support for rubocop-rspec syntax extensions #745

Closed QWYNG closed 1 year ago

QWYNG commented 2 years ago

Hi, Thank you for Great Gem.

fix #691

Example

Gemfile

# frozen_string_literal: true

source 'https://rubygems.org'

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

.rubocop.yml

AllCops:
  NewCops: enable

require:
  - rubocop-rspec

inherit_gem:
  pundit: config/rubocop-rspec.yml

spec/policies/some_policy_spec.rb

# frozen_string_literal: true

RSpec.describe SomePolicy do
  permissions :update?, :edit? do
    'wowwow'
  end
end

Before

bundle exec rubocop
Inspecting 2 files
.C

Offenses:

spec/policies/some_policy_spec.rb:3:1: C: [Correctable] RSpec/EmptyExampleGroup: Empty example group detected.
RSpec.describe SomePolicy do
^^^^^^^^^^^^^^^^^^^^^^^^^

2 files inspected, 1 offense detected, 1 offense autocorrectable

After

bundle exec rubocop
Inspecting 2 files
.C

Offenses:

spec/policies/some_policy_spec.rb:4:3: C: [Correctable] RSpec/EmptyExampleGroup: Empty example group detected.
  permissions :update?, :edit? do
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2 files inspected, 1 offense detected, 1 offense autocorrectable

See also: https://github.com/palkan/action_policy/pull/138 https://github.com/test-prof/test-prof/pull/199

Burgestrand commented 1 year ago

Thank you!

I had issues seeing the change at first since both before and after triggered warnings, but I see it now :D

# frozen_string_literal: true

RSpec.describe SomePolicy do
  permissions :update?, :edit? do
    # empty example group here!
  end

  it 'does something'
end
madhums commented 1 year ago

@Burgestrand could you please make a release with this change?

Burgestrand commented 1 year ago

@Burgestrand could you please make a release with this change?

Thank you for the reminder! I'll dedicate some time to it monday next week.