Commit 8958858d authored by Peter Leitzen's avatar Peter Leitzen

Improve failure message of matcher require_graphql_authorizations

Before the message was missing details about permission names:

Mutation::Issues::Klass is expected to require graphql authorizations
:foo and :bar Failure/Error: specify { expect(described_class).to
  require_graphql_authorizations(:foo, :bar) } expected

  Mutations::Issues::Klass to require graphql authorizations :foo and :bar

Now, it's clear which permissions are missing and which are extra:

Mutation::Issues::Klass is expected to require graphql authorizations
:foo and :bar Failure/Error: specify { expect(described_class).to
  require_graphql_authorizations(:foo, :bar) }

  is missing permissions: [:bar]
  contained unexpected permissions: [:foo]

Note, the permission check is now order-independent.
parent 683f739f
...@@ -3,14 +3,30 @@ ...@@ -3,14 +3,30 @@
RSpec::Matchers.define_negated_matcher :be_nullable, :be_non_null RSpec::Matchers.define_negated_matcher :be_nullable, :be_non_null
RSpec::Matchers.define :require_graphql_authorizations do |*expected| 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| match do |klass|
permissions = if klass.respond_to?(:required_permissions) actual = permissions_for(klass)
klass.required_permissions
else expect(actual).to match_array(expected)
[klass.to_graphql.metadata[:authorize]] end
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
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