summaryrefslogtreecommitdiff
path: root/spec/support/matchers/graphql_matchers.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/matchers/graphql_matchers.rb')
-rw-r--r--spec/support/matchers/graphql_matchers.rb28
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