Class: Faraday::Adapter::Test::Stubs
- Inherits:
-
Object
- Object
- Faraday::Adapter::Test::Stubs
- Defined in:
- lib/faraday/adapter/test.rb
Overview
A stack of Stubs
Defined Under Namespace
Classes: NotFound
Instance Method Summary collapse
- #delete(path, headers = {}, &block) ⇒ Object
- #empty? ⇒ Boolean
- #get(path, headers = {}, &block) ⇒ Object
- #head(path, headers = {}, &block) ⇒ Object
-
#initialize {|_self| ... } ⇒ Stubs
constructor
A new instance of Stubs.
- #match(request_method, host, path, headers, body) ⇒ Object
- #options(path, headers = {}, &block) ⇒ Object
- #patch(path, body = nil, headers = {}, &block) ⇒ Object
- #post(path, body = nil, headers = {}, &block) ⇒ Object
- #put(path, body = nil, headers = {}, &block) ⇒ Object
-
#verify_stubbed_calls ⇒ Object
Raises an error if any of the stubbed calls have not been made.
Constructor Details
#initialize {|_self| ... } ⇒ Stubs
Returns a new instance of Stubs.
50 51 52 53 54 55 |
# File 'lib/faraday/adapter/test.rb', line 50 def initialize # { get: [Stub, Stub] } @stack = {} @consumed = {} yield(self) if block_given? end |
Instance Method Details
#delete(path, headers = {}, &block) ⇒ Object
95 96 97 |
# File 'lib/faraday/adapter/test.rb', line 95 def delete(path, headers = {}, &block) new_stub(:delete, path, headers, &block) end |
#empty? ⇒ Boolean
57 58 59 |
# File 'lib/faraday/adapter/test.rb', line 57 def empty? @stack.empty? end |
#get(path, headers = {}, &block) ⇒ Object
75 76 77 |
# File 'lib/faraday/adapter/test.rb', line 75 def get(path, headers = {}, &block) new_stub(:get, path, headers, &block) end |
#head(path, headers = {}, &block) ⇒ Object
79 80 81 |
# File 'lib/faraday/adapter/test.rb', line 79 def head(path, headers = {}, &block) new_stub(:head, path, headers, &block) end |
#match(request_method, host, path, headers, body) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/faraday/adapter/test.rb', line 61 def match(request_method, host, path, headers, body) return false unless @stack.key?(request_method) stack = @stack[request_method] consumed = (@consumed[request_method] ||= []) stub, = matches?(stack, host, path, headers, body) if stub consumed << stack.delete(stub) return stub, end matches?(consumed, host, path, headers, body) end |
#options(path, headers = {}, &block) ⇒ Object
99 100 101 |
# File 'lib/faraday/adapter/test.rb', line 99 def (path, headers = {}, &block) new_stub(:options, path, headers, &block) end |
#patch(path, body = nil, headers = {}, &block) ⇒ Object
91 92 93 |
# File 'lib/faraday/adapter/test.rb', line 91 def patch(path, body = nil, headers = {}, &block) new_stub(:patch, path, headers, body, &block) end |
#post(path, body = nil, headers = {}, &block) ⇒ Object
83 84 85 |
# File 'lib/faraday/adapter/test.rb', line 83 def post(path, body = nil, headers = {}, &block) new_stub(:post, path, headers, body, &block) end |
#put(path, body = nil, headers = {}, &block) ⇒ Object
87 88 89 |
# File 'lib/faraday/adapter/test.rb', line 87 def put(path, body = nil, headers = {}, &block) new_stub(:put, path, headers, body, &block) end |
#verify_stubbed_calls ⇒ Object
Raises an error if any of the stubbed calls have not been made.
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/faraday/adapter/test.rb', line 104 def verify_stubbed_calls failed_stubs = [] @stack.each do |method, stubs| next if stubs.empty? failed_stubs.concat( stubs.map do |stub| "Expected #{method} #{stub}." end ) end raise failed_stubs.join(' ') unless failed_stubs.empty? end |