Module: Pundit::RSpec::DSL

Defined in:
lib/pundit/rspec.rb

Overview

Mixed in to all policy example groups to provide a DSL.

Since:

  • v0.1.0

Instance Method Summary collapse

Instance Method Details

#permissions(*list, &block) ⇒ void

This method returns an undefined value.

Examples:

describe PostPolicy do
  permissions :show?, :update? do
    it { is_expected.to permit(user, own_post) }
  end
end

focused example group

describe PostPolicy do
  permissions :show?, :update?, :focus do
    it { is_expected.to permit(user, own_post) }
  end
end

Parameters:

  • list (Symbol, Array<Symbol>)

    a permission to describe

Since:

  • v0.1.0



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/pundit/rspec.rb', line 131

def permissions(*list, &block)
   = { permissions: list, caller: caller }

  if list.last == :focus
    list.pop
    [:focus] = true
  end

  description = list.to_sentence
  describe(description, ) { instance_eval(&block) }
end