Skip to content

Use helper method to provide helpful error message

mo khan requested to merge mokhax/better-policy-assertion-output into master

What does this MR do and why?

This change uses the expect_allowed and expect_disallowed helper to improve the output of a test failure. Currently, when a test fails it is hard to determine which permission is allowed/disallowed. By using the helper it provides the permission that is causing the failure.

Before:

 Failure/Error: it { is_expected.to be_allowed(*allowed_abilities) }
   expected `#<GroupPolicy (@user10 : Group/456)>.allowed?(:read_dependency, :read_licenses)` to be truthy, got false

After:

 Failure/Error: permissions.each { |p| is_expected.to be_allowed(p) }
   expected `#<GroupPolicy (@user10 : Group/456)>.allowed?(:read_licenses)` to be truthy, got false

This was extracted from !151825.

#442851

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by mo khan

Merge request reports