module Restspec::RSpec::ApiHelpers

Public Class Methods

included(base) click to toggle source
# File lib/restspec/rspec/api_helpers.rb, line 59
def self.included(base)
  base.extend(self)
end

Public Instance Methods

call_endpoint(endpoint_full_name = nil, body: {}, url_params: {}, query_params: {}, merge_example_params: true, execution_method: :execute) click to toggle source
# File lib/restspec/rspec/api_helpers.rb, line 10
def call_endpoint(endpoint_full_name = nil, body: {},
                                      url_params: {},
                                      query_params: {},
                                      merge_example_params: true,
                                      execution_method: :execute)
  endpoint = find_endpoint_in_test_context(endpoint_full_name)

  if merge_example_params
    query_params = (@query_params || {}).merge(query_params)
    url_params = (@url_params || {}).merge(url_params)
  end

  endpoint.send(execution_method, body: body, url_params: url_params, query_params: query_params)
end
call_endpoint_once(endpoint_full_name = nil, options = {}) click to toggle source
# File lib/restspec/rspec/api_helpers.rb, line 42
def call_endpoint_once(endpoint_full_name = nil, options = {})
  call_endpoint(endpoint_full_name, options.merge(:execution_method => :execute_once))
end
execute_endpoint!() click to toggle source
# File lib/restspec/rspec/api_helpers.rb, line 46
def execute_endpoint!
  execute_endpoint_lambda.call
  response
end
find_endpoint_in_test_context(endpoint_full_name) click to toggle source
# File lib/restspec/rspec/api_helpers.rb, line 25
def find_endpoint_in_test_context(endpoint_full_name)
  if endpoint_full_name.present?
    test_context = self.class

    test_context.metadata[:endpoints] ||= {}
    test_context.metadata[:endpoints][endpoint_full_name] ||= begin
      Restspec::EndpointStore.get(endpoint_full_name)
    end
  else
    endpoint
  end
end
read_endpoint(endpoint_full_name = nil, options = {}) click to toggle source
# File lib/restspec/rspec/api_helpers.rb, line 6
def read_endpoint(endpoint_full_name = nil, options = {})
  call_endpoint(endpoint_full_name, options).read_body
end
read_endpoint_once(endpoint_full_name = nil, options = {}) click to toggle source
# File lib/restspec/rspec/api_helpers.rb, line 38
def read_endpoint_once(endpoint_full_name = nil, options = {})
  call_endpoint_once(endpoint_full_name, options).read_body
end
schema_example(schema_name = nil) click to toggle source
# File lib/restspec/rspec/api_helpers.rb, line 51
def schema_example(schema_name = nil)
  if schema_name.nil? && endpoint.present?
    schema_name = endpoint.schema_name
  end

  Restspec.example_for(schema_name)
end