module RSpec::GraphQLResponse
Constants
- VERSION
Public Class Methods
add_context_helper(name, &helper)
click to toggle source
# File lib/rspec/graphql_response/helpers.rb, line 3 def self.add_context_helper(name, &helper) self.add_helper(name, scope: :context, &helper) end
add_helper(name, scope: :spec, &helper)
click to toggle source
# File lib/rspec/graphql_response/helpers.rb, line 7 def self.add_helper(name, scope: :spec, &helper) helper_module = Module.new do |mod| mod.define_method(name) do |*args, &block| instance_var = "@#{name}".to_sym if self.instance_variables.include? instance_var return self.instance_variable_get(instance_var) end args << block result = self.instance_exec(*args, &helper) self.instance_variable_set(instance_var, result) end end RSpec.configure do |config| config.after(:each) do instance_var = "@#{name}".to_sym helper_module.instance_variable_set(instance_var, nil) end module_method = if scope == :spec :include elsif scope == :context :extend else raise ArgumentError, "A helper method's scope must be either :spec or :describe" end config.send(module_method, helper_module, type: :graphql) end end
add_matcher(name, &matcher)
click to toggle source
# File lib/rspec/graphql_response/matchers.rb, line 3 def self.add_matcher(name, &matcher) matcher_module = Module.new do |mod| extend RSpec::Matchers::DSL matcher(name, &matcher) end self.include(matcher_module) end
add_validator(name, &validator)
click to toggle source
# File lib/rspec/graphql_response/validators.rb, line 7 def self.add_validator(name, &validator) @validators ||= {} validator_class = Class.new(Validators::ValidationBase, &validator) @validators[name] = validator_class end
configuration()
click to toggle source
# File lib/rspec/graphql_response.rb, line 18 def self.configuration @configuration ||= Configuration.new end
configure(&block)
click to toggle source
# File lib/rspec/graphql_response.rb, line 12 def self.configure(&block) return if block.nil? block.call(configuration) end
remove_validator(name)
click to toggle source
# File lib/rspec/graphql_response/validators.rb, line 14 def self.remove_validator(name) @validators ||= {} @validators.delete(:key) end
reset_configuration()
click to toggle source
# File lib/rspec/graphql_response.rb, line 22 def self.reset_configuration @configuration = nil end
validator(name)
click to toggle source
# File lib/rspec/graphql_response/validators.rb, line 19 def self.validator(name) @validators[name].new end