class Object

Public Instance Methods

build_content(verb) click to toggle source

Convert params and header to the request content (body, params, headers, …) @return [Hash] with params and headers key

# File lib/ryquest/context.rb, line 37
def build_content verb
  if Ryquest.configuration.content_type == :form || %w[GET DELETE].include?(verb)
    return { params: params, headers: headers }
  end

  { params: params, headers: headers || {} }.tap do |result|
    result[:params] = result[:params].to_json
    result[:headers] = result[:headers].merge 'CONTENT_TYPE' => 'application/json'
  end
end
build_path(path) click to toggle source

Replace params path with their value. Use param path id if present. @return [String]

# File lib/ryquest/context.rb, line 64
def build_path path
  return path if path.exclude? ':'

  path.scan(/:(\w+\b)/).flatten.each do |match|
    value = send match
    value = value.id if value.respond_to? :id

    path = path.gsub ":#{match}", value.to_s
  end

  path
end
json!() click to toggle source

@return [Hash] the response!.body parsed from json

# File lib/ryquest/context.rb, line 32
def json!; JSON.parse response!.body end
match_verb() click to toggle source

Find request http verb and path in the parents example description. @return [MatchData] verb in [0] path in [1]

# File lib/ryquest/context.rb, line 50
def match_verb
  match = nil

  self.class.parent_groups.each do |parent|
    match = parent.description.match /^(GET|POST|PATCH|PUT|DELETE) (.+)/
    break if match
  end

  match
end
response!() click to toggle source

Execute request described in example description and return response value. Example description must be formated as: “VERB /path”.

Request will not be launch if it not exist or response already have a value.

VERB can be: GET, POST, PUT, PATCH, DELETE

To add specific body or headers define them with ‘let(:headers/:params) { { key: :value } }

Params path can be send as: ‘VERB /path/:param’, :param will be replaced by ‘param` value (let, method, …) or their `id` value.

@return [ActionDispatch::TestResponse] the response value

# File lib/ryquest/context.rb, line 19
def response!
  match = match_verb
  return response if response || match.nil?

  verb = match[1]
  path = match[2]
  content = build_content verb

  send verb.downcase, build_path(path), params: content[:params], headers: content[:headers]
  response
end