Sha256: e0fe08804e2e8bca52a464ae31a8f61663c9003feeb2bea456d305255dc0cb1f

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

RSpec::Matchers.define :raise_access_denied do |_expected|
  def supports_block_expectations?
    true
  end

  match do |actual|
    begin
      subject && subject.stub(:access_denied) do |exception|
        raise exception
      end

      actual.call
      false
    rescue CanCan::AccessDenied
      true
    rescue Services::Security::AccessDeniedError
      true
    rescue
      false
    end
  end
end

RSpec::Matchers.define :be_permitted_to do |*args|

  def supports_block_expectations?
    true
  end

  failure_message do |actual|
    "expected that #{ actual.class.name } would be permitted to #{ expected.first } #{ expected.second }"
  end
  match do |policy|
    policy.permit?( *args )
  end
end

RSpec::Matchers.define :maybe_be_permitted_to do |*args|

  def supports_block_expectations?
    true
  end

  failure_message do |actual|
    "expected that #{ actual.class.name } might be permitted to #{ expected.first } #{ expected.second }"
  end

  match do |policy|
    policy.permit?( *args ) == :maybe
  end
end

RSpec::Matchers.define :absolutely_be_permitted_to do |*args|

  def supports_block_expectations?
    true
  end

  failure_message do |actual|
    "expected that #{ actual.class.name } would absolutely be permitted to #{ expected.first } #{ expected.second }"
  end

  match do |policy|
    policy.permit?( *args ) == :yes
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shamu-0.0.24 lib/shamu/rspec/matchers.rb
shamu-0.0.21 lib/shamu/rspec/matchers.rb
shamu-0.0.20 lib/shamu/rspec/matchers.rb
shamu-0.0.19 lib/shamu/rspec/matchers.rb