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

- (Stubs) initialize {|_self| ... }

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

- (Object) delete(path, &block)



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

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

- (Boolean) empty?



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

def empty?
  @stack.empty?
end

- (Object) get(path, &block)



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

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

- (Object) head(path, &block)



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

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

- (Object) match(request_method, path, body)



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

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

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

- (Object) options(path, &block)



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

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

- (Object) patch(path, body = nil, &block)



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

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

- (Object) post(path, body = nil, &block)



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

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

- (Object) put(path, body = nil, &block)



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

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

- (Object) verify_stubbed_calls

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



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

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