Class: Faraday::Adapter::Test::Stubs

Inherits:
Object
  • Object
show all
Defined in:
lib/faraday/adapter/test.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:


46
47
48
49
50
# File 'lib/faraday/adapter/test.rb', line 46

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

Instance Method Details

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


89
90
91
# File 'lib/faraday/adapter/test.rb', line 89

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

#empty?Boolean


52
53
54
# File 'lib/faraday/adapter/test.rb', line 52

def empty?
  @stack.empty?
end

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


69
70
71
# File 'lib/faraday/adapter/test.rb', line 69

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

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


73
74
75
# File 'lib/faraday/adapter/test.rb', line 73

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

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


56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/faraday/adapter/test.rb', line 56

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

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

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


93
94
95
# File 'lib/faraday/adapter/test.rb', line 93

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

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


85
86
87
# File 'lib/faraday/adapter/test.rb', line 85

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

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


77
78
79
# File 'lib/faraday/adapter/test.rb', line 77

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

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


81
82
83
# File 'lib/faraday/adapter/test.rb', line 81

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.


98
99
100
101
102
103
104
105
106
107
108
# File 'lib/faraday/adapter/test.rb', line 98

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