Class: HttpFake::RequestLog
- Inherits:
-
Object
- Object
- HttpFake::RequestLog
- Defined in:
- lib/httpfake/request_log.rb
Overview
Thread-safe store of every request received by the fake server. Cleared between examples via Server#stop → new Server per example.
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
- #all ⇒ Object
- #clear ⇒ Object
- #count ⇒ Object
-
#for(method, path) ⇒ Object
Returns all entries matching the given HTTP method and exact path.
-
#initialize ⇒ RequestLog
constructor
A new instance of RequestLog.
- #record(method:, path:, body:, headers:, query_params:) ⇒ Object
Constructor Details
#initialize ⇒ RequestLog
Returns a new instance of RequestLog.
10 11 12 13 |
# File 'lib/httpfake/request_log.rb', line 10 def initialize @entries = [] @mutex = Mutex.new end |
Instance Method Details
#all ⇒ Object
27 28 29 |
# File 'lib/httpfake/request_log.rb', line 27 def all @mutex.synchronize { @entries.dup } end |
#clear ⇒ Object
36 37 38 |
# File 'lib/httpfake/request_log.rb', line 36 def clear @mutex.synchronize { @entries.clear } end |
#count ⇒ Object
40 41 42 |
# File 'lib/httpfake/request_log.rb', line 40 def count @mutex.synchronize { @entries.size } end |
#for(method, path) ⇒ Object
Returns all entries matching the given HTTP method and exact path.
32 33 34 |
# File 'lib/httpfake/request_log.rb', line 32 def for(method, path) all.select { |e| e.http_method == method.to_s.upcase && e.path == path } end |
#record(method:, path:, body:, headers:, query_params:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/httpfake/request_log.rb', line 15 def record(method:, path:, body:, headers:, query_params:) @mutex.synchronize do @entries << Entry.new( http_method: method.to_s.upcase, path: path, body: body, headers: headers, query_params: query_params ) end end |