Class: MnoeFaradayTestAdapter::Stubs

Inherits:
Object
  • Object
show all
Defined in:
lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb

Defined Under Namespace

Classes: NotFound

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Stubs

Returns a new instance of Stubs.

Yields:

  • (_self)

Yield Parameters:



23
24
25
26
27
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 23

def initialize
  # {:get => [Stub, Stub]}
  @stack, @consumed = {}, {}
  yield(self) if block_given?
end

Instance Method Details

#delete(path, headers = {}, &block) ⇒ Object



66
67
68
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 66

def delete(path, headers = {}, &block)
  new_stub(:delete, path, headers, &block)
end

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 29

def empty?
  @stack.empty?
end

#get(path, headers = {}, &block) ⇒ Object



46
47
48
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 46

def get(path, headers = {}, &block)
  new_stub(:get, path, headers, &block)
end

#head(path, headers = {}, &block) ⇒ Object



50
51
52
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 50

def head(path, headers = {}, &block)
  new_stub(:head, path, headers, &block)
end

#match(request_method, path, headers, body) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 33

def match(request_method, path, headers, body)
  return false if !@stack.key?(request_method)
  stack = @stack[request_method]
  consumed = (@consumed[request_method] ||= [])

  if stub = matches?(stack, path, headers, body)
    consumed << stack.delete(stub)
    stub
  else
    matches?(consumed, path, headers, body)
  end
end

#options(path, headers = {}, &block) ⇒ Object



70
71
72
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 70

def options(path, headers = {}, &block)
  new_stub(:options, path, headers, &block)
end

#patch(path, body = nil, headers = {}, &block) ⇒ Object



62
63
64
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 62

def patch(path, body=nil, headers = {}, &block)
  new_stub(:patch, path, headers, body, &block)
end

#post(path, body = nil, headers = {}, &block) ⇒ Object



54
55
56
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 54

def post(path, body=nil, headers = {}, &block)
  new_stub(:post, path, headers, body, &block)
end

#put(path, body = nil, headers = {}, &block) ⇒ Object



58
59
60
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 58

def put(path, body=nil, headers = {}, &block)
  new_stub(:put, path, headers, body, &block)
end

#verify_stubbed_callsObject

Raises an error if any of the stubbed calls have not been made.



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb', line 75

def verify_stubbed_calls
  failed_stubs = []
  @stack.each do |method, stubs|
    unless stubs.size == 0
      failed_stubs.concat(stubs.map {|stub|
        "Expected #{method} #{stub}."
      })
    end
  end
  raise failed_stubs.join(" ") unless failed_stubs.size == 0
end