Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
acc6e675
Commit
acc6e675
authored
Mar 05, 2021
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a shared example, and a describe block per field
This also fixes todo-ed rubocop violations in graphql_matchers
parent
8c1c513f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
17 deletions
+31
-17
spec/graphql/types/snippets/blob_type_spec.rb
spec/graphql/types/snippets/blob_type_spec.rb
+25
-14
spec/support/matchers/graphql_matchers.rb
spec/support/matchers/graphql_matchers.rb
+6
-3
No files found.
spec/graphql/types/snippets/blob_type_spec.rb
View file @
acc6e675
...
@@ -14,26 +14,37 @@ RSpec.describe GitlabSchema.types['SnippetBlob'] do
...
@@ -14,26 +14,37 @@ RSpec.describe GitlabSchema.types['SnippetBlob'] do
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
end
end
specify
{
expect
(
described_class
.
fields
[
'richData'
].
type
).
not_to
be_non_null
}
let_it_be
(
:nullity
)
do
specify
{
expect
(
described_class
.
fields
[
'plainData'
].
type
).
not_to
be_non_null
}
{
specify
{
expect
(
described_class
.
fields
[
'rawPath'
].
type
).
to
be_non_null
}
'richData'
=>
be_nullable
,
specify
{
expect
(
described_class
.
fields
[
'size'
].
type
).
to
be_non_null
}
'plainData'
=>
be_nullable
,
specify
{
expect
(
described_class
.
fields
[
'binary'
].
type
).
to
be_non_null
}
'rawPath'
=>
be_non_null
,
specify
{
expect
(
described_class
.
fields
[
'name'
].
type
).
not_to
be_non_null
}
'size'
=>
be_non_null
,
specify
{
expect
(
described_class
.
fields
[
'path'
].
type
).
not_to
be_non_null
}
'binary'
=>
be_non_null
,
specify
{
expect
(
described_class
.
fields
[
'simpleViewer'
].
type
).
to
be_non_null
}
'name'
=>
be_nullable
,
specify
{
expect
(
described_class
.
fields
[
'richViewer'
].
type
).
not_to
be_non_null
}
'path'
=>
be_nullable
,
specify
{
expect
(
described_class
.
fields
[
'mode'
].
type
).
not_to
be_non_null
}
'simpleViewer'
=>
be_non_null
,
specify
{
expect
(
described_class
.
fields
[
'externalStorage'
].
type
).
not_to
be_non_null
}
'richViewer'
=>
be_nullable
,
specify
{
expect
(
described_class
.
fields
[
'renderedAsText'
].
type
).
to
be_non_null
}
'mode'
=>
be_nullable
,
'externalStorage'
=>
be_nullable
,
'renderedAsText'
=>
be_non_null
}
end
let_it_be
(
:blob
)
{
create
(
:snippet
,
:public
,
:repository
).
blobs
.
first
}
let_it_be
(
:blob
)
{
create
(
:snippet
,
:public
,
:repository
).
blobs
.
first
}
described_class
.
fields
.
each_value
do
|
field
|
shared_examples
'a field from the snippet blob presenter'
do
|
field
|
it
"resolves
#{
field
.
graphql_name
}
using the presenter"
,
:request_store
do
it
"resolves using the presenter"
,
:request_store
do
presented
=
SnippetBlobPresenter
.
new
(
blob
)
presented
=
SnippetBlobPresenter
.
new
(
blob
)
expect
(
resolve_field
(
field
,
blob
)).
to
eq
(
presented
.
try
(
field
.
method_sym
))
expect
(
resolve_field
(
field
,
blob
)).
to
eq
(
presented
.
try
(
field
.
method_sym
))
end
end
end
end
described_class
.
fields
.
each_value
do
|
field
|
describe
field
.
graphql_name
do
it_behaves_like
'a field from the snippet blob presenter'
,
field
specify
{
expect
(
field
.
type
).
to
match
(
nullity
.
fetch
(
field
.
graphql_name
))
}
end
end
end
end
spec/support/matchers/graphql_matchers.rb
View file @
acc6e675
# frozen_string_literal: true
# frozen_string_literal: true
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
|
match
do
|
klass
|
match
do
|
klass
|
permissions
=
if
klass
.
respond_to?
(
:required_permissions
)
permissions
=
if
klass
.
respond_to?
(
:required_permissions
)
...
@@ -90,7 +92,7 @@ RSpec::Matchers.define :have_graphql_arguments do |*expected|
...
@@ -90,7 +92,7 @@ RSpec::Matchers.define :have_graphql_arguments do |*expected|
@names
||=
Array
.
wrap
(
expected
).
map
{
|
name
|
GraphqlHelpers
.
fieldnamerize
(
name
)
}
@names
||=
Array
.
wrap
(
expected
).
map
{
|
name
|
GraphqlHelpers
.
fieldnamerize
(
name
)
}
if
field
.
type
.
try
(
:ancestors
)
&
.
include?
(
GraphQL
::
Types
::
Relay
::
BaseConnection
)
if
field
.
type
.
try
(
:ancestors
)
&
.
include?
(
GraphQL
::
Types
::
Relay
::
BaseConnection
)
@names
|
%w
(after before first last)
@names
|
%w
[after before first last]
else
else
@names
@names
end
end
...
@@ -103,9 +105,10 @@ RSpec::Matchers.define :have_graphql_arguments do |*expected|
...
@@ -103,9 +105,10 @@ RSpec::Matchers.define :have_graphql_arguments do |*expected|
end
end
failure_message
do
|
field
|
failure_message
do
|
field
|
names
=
expected_names
(
field
)
names
=
expected_names
(
field
).
inspect
args
=
field
.
arguments
.
keys
.
inspect
"expected that
#{
field
.
name
}
would have the following
fields:
#{
names
.
inspect
}
, but it has
#{
field
.
arguments
.
keys
.
inspect
}
."
"expected that
#{
field
.
name
}
would have the following
arguments:
#{
names
}
, but it has
#{
args
}
."
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment