Commit a2375c4c authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'pl-rspec-matcher-require-graphql-authorization' into 'master'

Improve failure message of matcher require_graphql_authorizations

See merge request gitlab-org/gitlab!71568
parents fdb04627 8958858d
......@@ -3,14 +3,30 @@
RSpec::Matchers.define_negated_matcher :be_nullable, :be_non_null
RSpec::Matchers.define :require_graphql_authorizations do |*expected|
match do |klass|
permissions = if klass.respond_to?(:required_permissions)
def permissions_for(klass)
if klass.respond_to?(:required_permissions)
klass.required_permissions
else
[klass.to_graphql.metadata[:authorize]]
end
end
match do |klass|
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment