rspec-graphql_response 0.2.1 → 0.3.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
  SHA256:
3
- metadata.gz: 33248d708802eabea6e21fefa0e586fa2fb2dc0c6d00b9252316538f92911e49
4
- data.tar.gz: d59b174e42be64bc1e4b7b63fd9d450e6e83ded86c006ac426140bc7ca3f2455
3
+ metadata.gz: 2e29dab7149a9ebfd23ce4ba769da4cc53cae5008c2c2125cfd958dbad39d1f0
4
+ data.tar.gz: 7e602e4c314336f7844e58bc195067229211a6a63dd99acee958982062c509c5
5
5
  SHA512:
6
- metadata.gz: d016273aecd683e9993feb56af85cf5572fdc3b1c64fc591126248935a89781714bb24f8b58ad12735c36452693da8d26bcc60247f2a0bd0dd4f9865080fe065
7
- data.tar.gz: 00e3e0270509d83d9426dedc9deb35446ba0fd5e333448072913f7eeaff1ccd85f0de5fb64c5b631e32260044431bf82c56729250b2b1f5103bb4cee7ca5f1c1
6
+ metadata.gz: b3be27dabfaafee8b1bcd789e47828f1603095ed7757d19e89f0b60209e9a40328ecae0548f886815bd1fb00e74c07467459fdd49ab3b6a3e77ca7e8f29ad65f
7
+ data.tar.gz: f65e64010b9940b7eca6801f170190eb51bdfcae35f29705d45c1e3034b3151a941f29c7b13af8cb502aad0fc85d59d208fdb2b6e806a3fd9a7f7225f68942e1
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-graphql_response (0.2.0)
5
- rspec (~> 3.10)
4
+ rspec-graphql_response (0.2.1)
5
+ graphql (>= 1.0)
6
+ rspec (>= 3.0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -38,7 +39,6 @@ PLATFORMS
38
39
 
39
40
  DEPENDENCIES
40
41
  bundler (~> 1.17)
41
- graphql (~> 1.12)
42
42
  pry (~> 0.14)
43
43
  pry-byebug (~> 3.8)
44
44
  rake (>= 12.0)
@@ -5,6 +5,9 @@ methods for configuring the query.
5
5
 
6
6
  ```ruby
7
7
  RSPec.describe Cool::Stuff, type: :graphql do
8
+ let(:user) { create(:graphql_user) }
9
+ let(:search_name) { "Pet" }
10
+
8
11
  graphql_query <<-GQL
9
12
  query SomeThing($name: String) {
10
13
  characters(name: $name) {
@@ -14,13 +17,17 @@ RSPec.describe Cool::Stuff, type: :graphql do
14
17
  }
15
18
  GQL
16
19
 
17
- graphql_variables {
18
- name: "Jam"
19
- }
20
+ graphql_variables do
21
+ {
22
+ name: search_name
23
+ }
24
+ end
20
25
 
21
- grapql_context {
22
- current_user: "some user or whatever you need"
23
- }
26
+ grapql_context do
27
+ {
28
+ current_user: user
29
+ }
30
+ end
24
31
 
25
32
  it "executes and does the thing with the vars and context" do
26
33
  # ... expect things here
@@ -6,13 +6,14 @@ module RSpec
6
6
 
7
7
  def self.add_helper(name, scope: :spec, &helper)
8
8
  helper_module = Module.new do |mod|
9
- mod.define_method(name) do |*args|
9
+ mod.define_method(name) do |*args, &block|
10
10
  instance_var = "@#{name}".to_sym
11
11
 
12
12
  if self.instance_variables.include? instance_var
13
13
  return self.instance_variable_get(instance_var)
14
14
  end
15
15
 
16
+ args << block
16
17
  result = self.instance_exec(*args, &helper)
17
18
  self.instance_variable_set(instance_var, result)
18
19
  end
@@ -20,7 +21,8 @@ module RSpec
20
21
 
21
22
  RSpec.configure do |config|
22
23
  config.after(:each) do
23
- helper_module.instance_variable_set(:@result, nil)
24
+ instance_var = "@#{name}".to_sym
25
+ helper_module.instance_variable_set(instance_var, nil)
24
26
  end
25
27
 
26
28
  module_method = if scope == :spec
@@ -1,9 +1,14 @@
1
1
  RSpec::GraphQLResponse.add_helper :execute_graphql do
2
2
  config = RSpec::GraphQLResponse.configuration
3
3
 
4
- query = get_graphql_query if respond_to? :get_graphql_query
5
- query_vars = get_graphql_variables if respond_to? :get_graphql_variables
6
- query_context = get_graphql_context if respond_to? :get_graphql_context
4
+ query = graphql_query if respond_to? :graphql_query
5
+ query = self.instance_eval(&graphql_query) if query.is_a? Proc
6
+
7
+ query_vars = graphql_variables if respond_to? :graphql_variables
8
+ query_vars = self.instance_eval(&graphql_variables) if query_vars.is_a? Proc
9
+
10
+ query_context = graphql_context if respond_to? :graphql_context
11
+ query_context = self.instance_eval(&query_context) if query_context.is_a? Proc
7
12
 
8
13
  config.graphql_schema.execute(query, {
9
14
  variables: query_vars,
@@ -1,3 +1,3 @@
1
1
  RSpec::GraphQLResponse.add_context_helper :graphql_context do |ctx|
2
- self.define_method(:get_graphql_context) { ctx }
2
+ self.define_method(:graphql_context) { ctx }
3
3
  end
@@ -1,3 +1,3 @@
1
1
  RSpec::GraphQLResponse.add_context_helper :graphql_query do |gql|
2
- self.define_method(:get_graphql_query) { gql }
2
+ self.define_method(:graphql_query) { gql }
3
3
  end
@@ -1,3 +1,3 @@
1
1
  RSpec::GraphQLResponse.add_context_helper :graphql_variables do |vars|
2
- self.define_method(:get_graphql_variables) { vars }
2
+ self.define_method(:graphql_variables) { vars }
3
3
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module GraphQLResponse
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-graphql_response
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - River Lynn Bailey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-08 00:00:00.000000000 Z
11
+ date: 2021-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler