Module: GraphqlRails::RSpecControllerHelpers
- Defined in:
- lib/graphql_rails/rspec_controller_helpers.rb
Overview
provides all helpers neccesary for testing graphql controllers. It is similar to rspec controller specs
Adds 3 helper methods in to rspec test:
-
mutation
-
query
-
result
‘mutation` and `query“ methods are identical
Usage: it ‘works’ do
mutation(:createUser, params: { name: 'John'}, context: { current_user_id: 1 })
expect(response).to be_successful?
expect(response)not_to be_failure?
expect(response.result).to be_a(User)
expect(response.errors).to be_empty
end
Defined Under Namespace
Classes: FakeContext, Request, Response, SingleControllerSchemaBuilder
Instance Method Summary collapse
- #mutation(*args, **kwargs) ⇒ Object
- #query(query_name, params: {}, context: {}) ⇒ Object
- #response ⇒ Object
Instance Method Details
#mutation(*args, **kwargs) ⇒ Object
126 127 128 |
# File 'lib/graphql_rails/rspec_controller_helpers.rb', line 126 def mutation(*args, **kwargs) query(*args, **kwargs) end |
#query(query_name, params: {}, context: {}) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/graphql_rails/rspec_controller_helpers.rb', line 116 def query(query_name, params: {}, context: {}) schema_builder = SingleControllerSchemaBuilder.new(described_class) context_object = FakeContext.new(values: context, schema: schema_builder.call) request = Request.new(params, context_object, controller: described_class, action_name: query_name) described_class.new(request).call(query_name) @response = Response.new(request) @response end |
#response ⇒ Object
130 131 132 |
# File 'lib/graphql_rails/rspec_controller_helpers.rb', line 130 def response @response end |