Skip to content

Commit

Permalink
Merge pull request #49 from khamusa/chore/fix-failing-specs-after-to_…
Browse files Browse the repository at this point in the history
…graphql-removal

Preparing for 1.4.0 release
  • Loading branch information
khamusa authored Apr 16, 2023
2 parents 15e602a + dedad8e commit 7d8a79a
Show file tree
Hide file tree
Showing 14 changed files with 286 additions and 437 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: RSpec

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on: [ push, pull_request ]
on: [push, pull_request]

jobs:
# This workflow contains a single job "rspec"
Expand All @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
ruby_version: [ 2.6, 2.7, 3.0 ]
ruby_version: [2.6, 2.7, 3.0, 3.1, 3.2]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand All @@ -36,6 +36,6 @@ jobs:
key: ${{ runner.os }}-${{ matrix.ruby_version }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.ruby_version }}-gems-
- name: Run RSpec
run: bundle exec rspec
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Changelog

## 1.4.0 (April 16th, 2023)

- Removal of deprecated calls to #to_graphql, replacing them with #to_type_signature that was added in graphql-ruby 1.8.3 (https://github.com/khamusa/rspec-graphql_matchers/pull/43 @RobinDaugherty)
- Dropped support for legacy .define API
- Dropped support to old relay interfaces
- Fixed with_hash_key matcher for newer versions of graphql-ruby
- Fixed errors that occured in some edge cases when generating descriptions for accept_argument and have_a_field matchers
- Documentations improvement and general cleanup
- Dropped support to graphql-ruby versions before 1.10.12.

## 1.3.1 (Aug 2nd, 2021)

- Corrected gem dependencies so it properly requires RSpec when loaded (thanks to @itay-grudev)

## 1.3.0 (May 7th, 2020)
Expand Down
8 changes: 0 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,3 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in rspec-graphql_matchers.gemspec
gemspec

# rubocop:disable Bundle/DuplicatedGem
if ENV['GRAPHQL_GEM_VERSION'] == '1.8'
gem 'graphql', '~> 1.8.0'
elsif ENV['GRAPHQL_GEM_VERSION'] == '1.9'
gem 'graphql', '~> 1.9.0'
end
# rubocop:enable Bundle/DuplicatedGem
37 changes: 6 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ Where a valid type for the expectation is either:
- [Recommended] A String representation of a type: `"String!"`, `"Int!"`, `"[String]!"`
(note the exclamation mark at the end, as required by the [GraphQL specifications](http://graphql.org/).

For objects defined with the legacy `#define` api, testing `:property`, `:hash_key` and _metadata_ is also possible by chaining `.with_property`, `.with_hash_key` and `.with_metadata`. For example:

- `expect(a_graphql_object).to have_a_field(field_name).with_property(property_name).with_metadata(metadata_hash)`
- `expect(a_graphql_object).to have_a_field(field_name).with_hash_key(hash_key)`

## Examples

Given a GraphQL object defined as
Expand All @@ -41,7 +36,7 @@ class PostType < GraphQL::Schema::Object
graphql_name "Post"
description "A blog post"

implements GraphQL::Relay::Node.interface
implements GraphQL::Types::Relay::Node

field :id, ID, null: false
field :comments, [String], null: false
Expand Down Expand Up @@ -97,27 +92,7 @@ describe PostType do
end
```

### 3) For objects defined using the legacy `#define` api, you can also use `with_property`, `with_hash_key` and `with_metadata`:

```ruby
PostTypeWithDefineApi = GraphQL::ObjectType.define do
name "DefinedPost"

interfaces [GraphQL::Relay::Node.interface]

field :id, !types.ID, property: :post_id
field :comments, !types[types.String], hash_key: :post_comments
field :isPublished, admin_only: true
end

describe PostTypeWithDefineApi do
it { is_expected.to have_a_field(:id).of_type('ID!').with_property(:post_id) }
it { is_expected.to have_a_field(:comments).with_hash_key(:post_comments) }
it { is_expected.to have_a_field(:isPublished).with_metadata(admin_only: true) }
end
```

### 4) Test the arguments accepted by a field with `accept_argument` matcher:
### 3) Test the arguments accepted by a field with `accept_argument` matcher:

```ruby
describe PostType do
Expand All @@ -138,7 +113,7 @@ describe PostType do
end
```

### 5) Test an object's interface implementations:
### 4) Test an object's interface implementations:

```ruby
describe PostType do
Expand All @@ -149,20 +124,20 @@ describe PostType do
end

# Accepts arguments as an array and type objects directly
it { is_expected.to implement(GraphQL::Relay::Node.interface) }
it { is_expected.to implement(GraphQL::Types::Relay::Node) }
it { is_expected.not_to implement('OtherInterface') }
end
```

### 6) Using camelize: false on field names
### 5) Using camelize: false on field names

By default the graphql gem camelizes field names. This gem deals with it transparently:

```ruby
class ObjectMessingWithCamelsAndSnakesType < GraphQL::Schema::Object
graphql_name 'ObjectMessingWithCamelsAndSnakes'

implements GraphQL::Relay::Node.interface
implements GraphQL::Types::Relay::Node

field :me_gusta_los_camellos, ID, null: false

Expand Down
8 changes: 6 additions & 2 deletions lib/rspec/graphql_matchers/accept_argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def description
private

def descriptions
@results.map(&:description)
results.map(&:description)
end

def failure_messages
@results.map(&:failure_message)
results.map(&:failure_message)
end

def field_arguments
Expand All @@ -74,6 +74,10 @@ def field_arguments
'matcher. It does not seem to be a valid GraphQL object type.'
end
end

def results
@results ||= []
end
end
end
end
8 changes: 6 additions & 2 deletions lib/rspec/graphql_matchers/have_a_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def actual_field
end

def descriptions
@results.map(&:description)
results.map(&:description)
end

def failure_messages
@results.map(&:failure_message)
results.map(&:failure_message)
end

def field_collection
Expand All @@ -108,6 +108,10 @@ def matcher_name
when :return_fields then 'have_a_return_field'
end
end

def results
@results ||= []
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def get_hash_key(actual_field)
return actual_field.hash_key.to_sym if actual_field.hash_key
end

actual_field.metadata[:type_class].method_sym
if actual_field.respond_to?(:metadata)
return actual_field.metadata[:type_class].method_sym
end

actual_field.method_sym
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/graphql_matchers/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Rspec
module GraphqlMatchers
VERSION = '1.3.1'.freeze
VERSION = '1.4.0'.freeze
end
end
2 changes: 1 addition & 1 deletion rspec-graphql_matchers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'graphql', '>= 1.8', '< 2.0'
spec.add_dependency 'graphql', '>= 1.10.12', '< 2.0'
spec.add_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'bundler', '~> 2.0'
# CodeClimate does not yet support SimpleCov 0.18
Expand Down
Loading

0 comments on commit 7d8a79a

Please sign in to comment.