Class: ShopifyAPI::Mock::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify-mock/response.rb

Overview

used to manage the mocked responses

Constant Summary collapse

@@responses =

store for all registered responses

[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, resource, response) ⇒ FakeWeb

creates and registers a new mocked response

Examples:

Registering a response to the path “/orders/count.xml” with the response “hello world”

ShopifyAPI::Mock::Response.new :get, "orders/count.xml", "hello world"

Parameters:

  • method (Symbol)

    The method of the reponse. Can be one of [:put, :get, :post, :delete]

  • resource (String)

    The path to the resource.

  • response (String)

    The response to provide when that URL is called



13
14
15
16
17
18
# File 'lib/shopify-mock/response.rb', line 13

def initialize(method, resource, response)
  @@responses += FakeWeb.register_uri(
    method, /#{SHOPIFY_MOCK_SHOP_BASE_URL}#{resource}/,
    :body => response
  )
end

Class Method Details

.allArray, FakeWeb

finds all the registered responses

Examples:

List all the registered responses

puts ShopifyAPI::Mock::Response.all

Returns:

  • (Array, FakeWeb)

    all the FakeWeb registered responses



29
30
31
# File 'lib/shopify-mock/response.rb', line 29

def all
  @@responses
end

.clearArray

clears all the currently registered responses

Examples:

Clearing all registered responses

ShopifyAPI::Mock::Response.clear

Returns:

  • (Array)

    the registered responses after clearing (should be empty)



38
39
40
41
# File 'lib/shopify-mock/response.rb', line 38

def clear
  FakeWeb.clean_registry
  @@responses = []
end