rspec-graphql_matchers 0.4.0 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 305fd4862eb06da7a1f37e7c55b6f9af96eca4e2
4
- data.tar.gz: 343daa1c81d534979ee724ed6f5206765fa4109c
3
+ metadata.gz: ef64269a3e7859791ef772fa3fa7e5c1971c23b0
4
+ data.tar.gz: 383ed8c0d083b7dafc086179c5266ddc37d2b2c4
5
5
  SHA512:
6
- metadata.gz: 0eaaa0082cadbd26d2e9a577c0ed364ad769f5cfffd7fd8cb54784ad9684b2b9e44e0833e9d4fe25a4a6a22ba4a7c9da3298b329fad40a211dca0ce676885da4
7
- data.tar.gz: 7ab8f2831ebf8f6dbe80acbd889b6e92ae919b092bf6f796749909ce47cd62542808c5979ab970cc425fbc88374c40045c3d911e102929cce1405b6645628c88
6
+ metadata.gz: b3a9c8803fbfe709451399b1a220ffcc2918525e595760b1d2c89f156066dd47dd75ce0a9bfe2520f4e5fb6944733d2e2bcca4082513a1f1bc24196eafffd679
7
+ data.tar.gz: 6e73cc8a63366f37bd445cc7cbd0d0af44b5a40565d907fc97164e03e298fa01d54dcdb4e0109b47603096a803709a7e290c0843188639d73891f801b7fb38fb
data/CHANGELOG.md CHANGED
@@ -8,19 +8,21 @@
8
8
 
9
9
  ### Bug fixes
10
10
 
11
- ## 0.4.0 (Feb 10, 2017)
11
+ ## 0.5.0 (May 10, 2017)
12
12
 
13
- ### Breaking changes
13
+ ### New features
14
14
 
15
- ### Deprecations
15
+ - (PR #4) New matchers for mutations: `have_an_input_field` and `have_a_return_field` (Thanks to @aaronklaassen).
16
+
17
+ ## 0.4.0 (Feb, 2017)
16
18
 
17
19
  ### New features
18
20
 
19
- - Improved error messages for `have_a_field...of_type`
21
+ - Improvements on error messages of have_a_field(...).of_type(...)
20
22
 
21
23
  ### Bug fixes
22
24
 
23
- - FIXEd Type check when using the form `have_a_field(field_name).of_type(types.X)` not working. It was working if the expected type was provided as a String, but not when using the GraphQL constants.
25
+ - Fixed a bug preventing proper type checking when using matchers in the form have_a_field(fname).of_type(types.X). The bug would not happen when providing the type expectation as a string, only when using the GraphQL constants.
24
26
 
25
27
  ## 0.3.0 (Sep 16, 2016)
26
28
 
data/README.md CHANGED
@@ -11,9 +11,12 @@ gem 'rspec-graphql_matchers'
11
11
  ## Usage
12
12
 
13
13
  The matchers currently supported are:
14
- - `expect(graphql_type).to have_a_field(field_name).that_returns(valid_type)`
15
- - `expect(graphql_field).to be_of_type(valid_type)`
16
- - `expect(graphql_field).to accept_arguments(hash_of_arg_names_and_valid_types)`
14
+ - `expect(a_graphql_object).to have_a_field(field_name).that_returns(valid_type)`
15
+ - `expect(a_mutation_type).to have_a_return_field(field_name).returning(valid_type)`
16
+ - `expect(a_mutation_type).to have_an_input_field(field_name).of_type(valid_type)`
17
+ - `expect(a_field).to be_of_type(valid_type)`
18
+ - `expect(an_input).to accept_arguments(hash_of_arg_names_and_valid_types)`
19
+ - `expect(an_input).to accept_arguments(hash_of_arg_names_and_valid_types)`
17
20
 
18
21
  Where a valid type for the expectation is either:
19
22
  - A `GraphQL::ObjectType` object (ex: `types.String`, `!types.Int`, `types[types.Int]`, or your own)
@@ -137,8 +140,6 @@ For better fluency, `accept_arguments` is also available in singular form, as
137
140
 
138
141
  ## TODO
139
142
 
140
- - Setup CI and integrate w/codeclimate
141
- - Setup codeclimate / CI badges
142
143
  - New matchers!
143
144
 
144
145
  ## Contributing
@@ -3,20 +3,16 @@ require_relative 'base_matcher'
3
3
  module RSpec
4
4
  module GraphqlMatchers
5
5
  class HaveAField < BaseMatcher
6
- def initialize(expected_field_name)
6
+ def initialize(expected_field_name, fields = :fields)
7
7
  @expected_field_name = expected_field_name.to_s
8
8
  @expected_field_type = @graph_object = nil
9
+ @fields = fields.to_sym
9
10
  end
10
11
 
11
12
  def matches?(graph_object)
12
13
  @graph_object = graph_object
13
14
 
14
- unless @graph_object.respond_to?(:fields)
15
- raise "Invalid object #{@graph_object} provided to have_a_field " \
16
- 'matcher. It does not seem to be a valid GraphQL object type.'
17
- end
18
-
19
- @actual_field = @graph_object.fields[@expected_field_name]
15
+ @actual_field = field_collection[@expected_field_name]
20
16
  valid_field? && types_match?(@actual_field.type, @expected_field_type)
21
17
  end
22
18
 
@@ -66,6 +62,23 @@ module RSpec
66
62
  def describe_obj(field)
67
63
  field.respond_to?(:name) && field.name || field.inspect
68
64
  end
65
+
66
+ def field_collection
67
+ if @graph_object.respond_to?(@fields)
68
+ @graph_object.public_send(@fields)
69
+ else
70
+ raise "Invalid object #{@graph_object} provided to #{matcher_name} " \
71
+ 'matcher. It does not seem to be a valid GraphQL object type.'
72
+ end
73
+ end
74
+
75
+ def matcher_name
76
+ case @fields
77
+ when :fields then 'have_a_field'
78
+ when :input_fields then 'have_an_input_field'
79
+ when :return_fields then 'have_a_return_field'
80
+ end
81
+ end
69
82
  end
70
83
  end
71
84
  end
@@ -19,5 +19,17 @@ module RSpec
19
19
  RSpec::GraphqlMatchers::HaveAField.new(field_name)
20
20
  end
21
21
  alias have_field have_a_field
22
+
23
+ # rubocop:disable Style/PredicateName
24
+ def have_an_input_field(field_name)
25
+ RSpec::GraphqlMatchers::HaveAField.new(field_name, :input_fields)
26
+ end
27
+ alias have_input_field have_an_input_field
28
+
29
+ # rubocop:disable Style/PredicateName
30
+ def have_a_return_field(field_name)
31
+ RSpec::GraphqlMatchers::HaveAField.new(field_name, :return_fields)
32
+ end
33
+ alias have_return_field have_a_return_field
22
34
  end
23
35
  end
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module GraphqlMatchers
3
- VERSION = '0.4.0'.freeze
3
+ VERSION = '0.5'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-graphql_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Brandão
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-10 00:00:00.000000000 Z
11
+ date: 2017-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.4.8
139
+ rubygems_version: 2.6.8
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Collection of rspec matchers to test your graphQL api schema.