rspec-graphql_matchers 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00d732627e015320d3b20a00b562cc0846b1aa28
4
- data.tar.gz: ec338cd6d329e35af1819843cc79eed4c804547a
3
+ metadata.gz: 305fd4862eb06da7a1f37e7c55b6f9af96eca4e2
4
+ data.tar.gz: 343daa1c81d534979ee724ed6f5206765fa4109c
5
5
  SHA512:
6
- metadata.gz: 38a3cb488036ec21f3d688e5d1da919280d57c27b5f05a930072ca492580036b784d1528ae379b082425289b0b834c1ca10d7222c94b838c67245d0b9fbfc1bf
7
- data.tar.gz: 65813ccec06ea29b830fe4ed11ca55306a8aba55837c58db5b98f666987365ff6011e7c44a41e14dc837e757d5d1e1bdc0680d8625d3362c39b9fb931d01623a
6
+ metadata.gz: 0eaaa0082cadbd26d2e9a577c0ed364ad769f5cfffd7fd8cb54784ad9684b2b9e44e0833e9d4fe25a4a6a22ba4a7c9da3298b329fad40a211dca0ce676885da4
7
+ data.tar.gz: 7ab8f2831ebf8f6dbe80acbd889b6e92ae919b092bf6f796749909ce47cd62542808c5979ab970cc425fbc88374c40045c3d911e102929cce1405b6645628c88
@@ -8,6 +8,20 @@
8
8
 
9
9
  ### Bug fixes
10
10
 
11
+ ## 0.4.0 (Feb 10, 2017)
12
+
13
+ ### Breaking changes
14
+
15
+ ### Deprecations
16
+
17
+ ### New features
18
+
19
+ - Improved error messages for `have_a_field...of_type`
20
+
21
+ ### Bug fixes
22
+
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.
24
+
11
25
  ## 0.3.0 (Sep 16, 2016)
12
26
 
13
27
  ### Breaking changes
@@ -0,0 +1,11 @@
1
+ module RSpec
2
+ module GraphqlMatchers
3
+ class BaseMatcher
4
+ private
5
+
6
+ def types_match?(actual_type, expected_type)
7
+ expected_type.nil? || expected_type.to_s == actual_type.to_s
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,20 +1,27 @@
1
+ require_relative 'base_matcher'
2
+
1
3
  module RSpec
2
4
  module GraphqlMatchers
3
- class HaveAField
4
- def initialize(field_name)
5
- @field_name = field_name.to_s
6
- @field_type = @graph_object = nil
5
+ class HaveAField < BaseMatcher
6
+ def initialize(expected_field_name)
7
+ @expected_field_name = expected_field_name.to_s
8
+ @expected_field_type = @graph_object = nil
7
9
  end
8
10
 
9
11
  def matches?(graph_object)
10
12
  @graph_object = graph_object
11
13
 
12
- actual_field = @graph_object.fields[@field_name]
13
- actual_field && types_match?(@field_type, actual_field.type)
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]
20
+ valid_field? && types_match?(@actual_field.type, @expected_field_type)
14
21
  end
15
22
 
16
- def that_returns(field_type)
17
- @field_type = field_type
23
+ def that_returns(expected_field_type)
24
+ @expected_field_type = expected_field_type
18
25
 
19
26
  self
20
27
  end
@@ -22,23 +29,38 @@ module RSpec
22
29
  alias of_type that_returns
23
30
 
24
31
  def failure_message
25
- "expected #{describe_obj(@graph_object)} to #{description}"
32
+ "expected #{describe_obj(@graph_object)} to " \
33
+ "#{description}, #{explanation}."
26
34
  end
27
35
 
28
36
  def description
29
- "define field `#{@field_name}`" + of_type_description
37
+ "define field `#{@expected_field_name}`" + of_type_description
30
38
  end
31
39
 
32
40
  private
33
41
 
34
- def of_type_description
35
- return '' unless @field_type
42
+ def explanation
43
+ return 'but no field was found with that name' unless @actual_field
44
+
45
+ "but the field type was `#{@actual_field.type}`"
46
+ end
47
+
48
+ def valid_field?
49
+ unless @expected_field_type.nil? || @actual_field.respond_to?(:type)
50
+ error_msg = "The `#{@expected_field_name}` field defined by the GraphQL " \
51
+ 'object does\'t seem valid as it does not respond to #type. ' \
52
+ "\n\n\tThe field found was #{@actual_field.inspect}. "
53
+ puts error_msg
54
+ raise error_msg
55
+ end
36
56
 
37
- " of type `#{@field_type}`"
57
+ @actual_field
38
58
  end
39
59
 
40
- def types_match?(expected_type, actual_type)
41
- !expected_type || expected_type.to_s == actual_type.to_s
60
+ def of_type_description
61
+ return '' unless @expected_field_type
62
+
63
+ " of type `#{@expected_field_type}`"
42
64
  end
43
65
 
44
66
  def describe_obj(field)
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module GraphqlMatchers
3
- VERSION = '0.3.1'.freeze
3
+ VERSION = '0.4.0'.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.3.1
4
+ version: 0.4.0
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-01-24 00:00:00.000000000 Z
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -109,6 +109,7 @@ files:
109
109
  - bin/setup
110
110
  - lib/rspec/graphql_matchers.rb
111
111
  - lib/rspec/graphql_matchers/accept_arguments.rb
112
+ - lib/rspec/graphql_matchers/base_matcher.rb
112
113
  - lib/rspec/graphql_matchers/be_of_type.rb
113
114
  - lib/rspec/graphql_matchers/have_a_field.rb
114
115
  - lib/rspec/graphql_matchers/matchers.rb