Closed mathewtrivett closed 2 years ago
I actually got this working. It might be helpful to include a little bit extra in the README.md to help others, I'm happy to raise a PR if it would help?
Add the following to spec_helper.rb
require 'rspec/graphql_matchers'
include RSpec::GraphqlMatchers::TypesHelper
I also included in the config config.expose_dsl_globally = true
Then my test file became:
describe Types::JourneyType do
subject { described_class }
it { is_expected.to have_field(:arrivalDateTime) }
it { is_expected.to have_field(:startDateTime) }
it { is_expected.to have_field(:duration) }
end
@mathewtrivett first of all, sorry for taking soooooooo long to reply. Things have been crazy and notifications got lost.
So, I'm not sure why it didn't work for you in the first place. Looking at the error message, it looks like it has nothing to do with the gem. It just says a constant was not found. JourneyType
is a constant as any other, and if your spec file can't find it... :boom:
From your proposed solution I guess your constant is not defined at the root of the module namespace, but under Types
. In that case, what solved your issue was using the fully qualified constant name Types::JourneyType
.
The module RSpec::GraphqlMatchers::TypesHelper
is actually deprecated. I invite you to remove it and try running the specs again. It was a helper created for much older versions of the graphql gem (before the class / module interface for defining types was introduced), and it has been kept on the codebase for compatibility reasons only. I guess it's safe to remove it on the next release...
@mathewtrivett
Try to remove
require 'rspec/graphql_matchers'
include RSpec::GraphqlMatchers::TypesHelper
from your spec_helper.rb and make sure you've got --require rails_helper
in your .rspec
instead of --require spec_helper
.
HTH Tobi
Hi thanks for creating this gem, I'm looking forward to using it. I'm trying to get things set up with:
Ruby:
ruby 2.7.0p0
Rails:6.0.3
Rspec-rails:4.0.1
Graphql:1.11.5
I have the following tree type structure for graphql:
And the following for my specs:
I've create the following spec:
But get:
Do I need to add something to spec_helper.rb to make GraphQL types visible to rspec?