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:


21
22
23
24
25
# File 'lib/faraday/adapter/test.rb', line 21

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

Instance Method Details

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


64
65
66
# File 'lib/faraday/adapter/test.rb', line 64

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

#empty?Boolean


27
28
29
# File 'lib/faraday/adapter/test.rb', line 27

def empty?
  @stack.empty?
end

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


44
45
46
# File 'lib/faraday/adapter/test.rb', line 44

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

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


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

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

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


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/faraday/adapter/test.rb', line 31

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


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

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

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


60
61
62
# File 'lib/faraday/adapter/test.rb', line 60

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

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


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

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

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


56
57
58
# File 'lib/faraday/adapter/test.rb', line 56

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.


73
74
75
76
77
78
79
80
81
82
83
# File 'lib/faraday/adapter/test.rb', line 73

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