varvet / pundit

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

Support :focus for rspec permissions blocks #816

Closed pas256 closed 1 month ago

pas256 commented 3 months ago

When writing tests using rspec, there is a nice helper called permissions that works similar to describe, but it does not support the :focus attribute used to limit which tests are run.

Example:

RSpec.describe SheetPolicy, type: :policy do
  permissions :index? do
    it 'grants access if the workbook is created by the user' do
      expect(SheetPolicy).to permit(user, create(:sheet, workbook:))
    end
  end

  permissions :show?, :focus do
    it 'grants access if the workbook is created by the user' do
      expect(SheetPolicy).to permit(user, create(:sheet, workbook:))
    end
  end

When you have config.filter_run_when_matching :focus in your spec_helper.rb file, it should only run the index block of tests, but from what I can tell, permissions does not support it.

Burgestrand commented 3 months ago

Without looking into the details too much here, this feels something we should reasonably support.

Burgestrand commented 1 month ago

This was fixed in #820!