diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-05 18:12:53 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-05 18:12:53 +0300 |
commit | a84626f13d61d190b2db5e44caf71b22fc541276 (patch) | |
tree | 5cf591ce134ac0ad5b8c101e3518b2e49101b6ad /spec/support/matchers | |
parent | c9b0dfef1ba43a9e04264023b08c589bcb9eb397 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/matchers')
-rw-r--r-- | spec/support/matchers/graphql_matchers.rb | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/spec/support/matchers/graphql_matchers.rb b/spec/support/matchers/graphql_matchers.rb index 904b7efdd7f..dcaec176687 100644 --- a/spec/support/matchers/graphql_matchers.rb +++ b/spec/support/matchers/graphql_matchers.rb @@ -3,14 +3,30 @@ RSpec::Matchers.define_negated_matcher :be_nullable, :be_non_null RSpec::Matchers.define :require_graphql_authorizations do |*expected| + def permissions_for(klass) + if klass.respond_to?(:required_permissions) + klass.required_permissions + else + [klass.to_graphql.metadata[:authorize]] + end + end + match do |klass| - permissions = if klass.respond_to?(:required_permissions) - klass.required_permissions - else - [klass.to_graphql.metadata[:authorize]] - end + actual = permissions_for(klass) + + expect(actual).to match_array(expected) + end + + failure_message do |klass| + actual = permissions_for(klass) + missing = actual - expected + extra = expected - actual - expect(permissions).to eq(expected) + message = [] + message << "is missing permissions: #{missing.inspect}" if missing.any? + message << "contained unexpected permissions: #{extra.inspect}" if extra.any? + + message.join("\n") end end |