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:



23
24
25
26
27
# File 'lib/faraday/adapter/test.rb', line 23

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

Instance Method Details

#delete(path, &block) ⇒ Object



62
63
64
# File 'lib/faraday/adapter/test.rb', line 62

def delete(path, &block)
  new_stub(:delete, path, &block)
end

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/faraday/adapter/test.rb', line 29

def empty?
  @stack.empty?
end

#get(path, &block) ⇒ Object



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

def get(path, &block)
  new_stub(:get, path, &block)
end

#head(path, &block) ⇒ Object



50
51
52
# File 'lib/faraday/adapter/test.rb', line 50

def head(path, &block)
  new_stub(:head, path, &block)
end

#match(request_method, path, body) ⇒ Object



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

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

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

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



54
55
56
# File 'lib/faraday/adapter/test.rb', line 54

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

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



58
59
60
# File 'lib/faraday/adapter/test.rb', line 58

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

#verify_stubbed_callsObject

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



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/faraday/adapter/test.rb', line 67

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