Module: Imperium::Testing

Defined in:
lib/imperium/testing.rb

Overview

A collection of functions to build responses for use in tests needing mock responses.

Defined Under Namespace

Classes: MockResponse

Class Method Summary collapse

Class Method Details

.kv_get_response(body: '[]', status: 200, headers: {}, prefix: '', options: []) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/imperium/testing.rb', line 17

def self.kv_get_response(body: '[]', status: 200, headers: {}, prefix: '', options: [])
  expanded_options = @client.hashify_options(options)
  string_body = if String === body
                  body
                else
                  body.map { |obj|
                    obj['Value'] = Base64.encode64(obj['Value']) if obj['Value']
                    obj[:Value] = Base64.encode64(obj[:Value]) if obj[:Value]
                    obj
                  }.to_json
                end

  response = MockResponse.new(string_body, status, headers)
  KVGETResponse.new(response, prefix: prefix, options: expanded_options)
end

.kv_not_found_response(headers: {}, options: []) ⇒ Object



33
34
35
# File 'lib/imperium/testing.rb', line 33

def self.kv_not_found_response(headers: {}, options: [])
  kv_get_response(body: '', status: 404, headers: headers, options: options)
end