Module: Artemis::TestHelper
- Defined in:
- lib/artemis/test_helper.rb
Overview
TODO: Write documentation for TestHelper
Instance Method Summary collapse
-
#graphql_requests ⇒ Object
Returns out-going GraphQL requests.
-
#stub_graphql(service, query_name, arguments = :__unspecified__) ⇒ Object
Creates an object that stubs a GraphQL request for the given
service
.
Instance Method Details
#graphql_requests ⇒ Object
Returns out-going GraphQL requests.
51 52 53 |
# File 'lib/artemis/test_helper.rb', line 51 def graphql_requests Artemis::Adapters::TestAdapter.requests end |
#stub_graphql(service, query_name, arguments = :__unspecified__) ⇒ Object
Creates an object that stubs a GraphQL request for the given service
. No mock response is registered until the to_return
method.
# test/fixtures/graphql/metaphysics/artist.yml
leonardo_da_vinci:
data:
artist:
name: Leonardo da Vinci
birthday: 1452/04/15
# In a test:
stub_graphql(Metaphysics, :artist).to_return(:leonardo_da_vinci)
response = Metaphysics.artist(id: "leonardo-da-vinci")
response.data.artist.name # => "Leonardo da Vinci"
response.data.artist.birthday # => "1452/04/15"
Test responses could also be parameterized by specifying the arguments
argument for the query name.
stub_graphql(Metaphysics, :artist, id: "pablo-picasso").to_return(:pablo_picasso)
stub_graphql(Metaphysics, :artist, id: "leonardo-da-vinci").to_return(:leonardo_da_vinci)
pablo_picasso = Metaphysics.artist(id: "pablo-picasso")
da_vinci = Metaphysics.artist(id: "leonardo-da-vinci")
pablo_picasso.data.artist.name # => "Pablo Picasso"
da_vinci.data.artist.name # => "Leonardo da Vinci"
45 46 47 |
# File 'lib/artemis/test_helper.rb', line 45 def stub_graphql(service, query_name, arguments = :__unspecified__) StubbingDSL.new(service.to_s, query_name, graphql_fixture_files, arguments) end |