Class: StubRequests::StubRegistry
- Extended by:
- Forwardable
- Includes:
- Enumerable, Singleton
- Defined in:
- lib/stub_requests/stub_registry.rb
Overview
Class Registry maintains a registry of stubbed endpoints. Also allows provides querying capabilities for said entities.
Instance Attribute Summary collapse
- #stubs ⇒ Object readonly
Instance Method Summary collapse
-
#find_by_webmock_stub(webmock_stub) ⇒ RequestStub
Finds a RequestStub amongst the endpoint stubs.
-
#initialize ⇒ StubRegistry
constructor
Initialize a new registry.
-
#mark_as_responded(webmock_stub) ⇒ void
Mark a RequestStub as having responded.
-
#record(endpoint_id, webmock_stub) ⇒ RequestStub
Records a WebMock::RequestStub as stubbed.
-
#reset ⇒ Object
private
Resets the map with stubbed endpoints.
Constructor Details
#initialize ⇒ StubRegistry
Initialize a new registry
40 41 42 |
# File 'lib/stub_requests/stub_registry.rb', line 40 def initialize reset end |
Instance Attribute Details
#stubs ⇒ Object (readonly)
34 35 36 |
# File 'lib/stub_requests/stub_registry.rb', line 34 def stubs @stubs end |
Instance Method Details
#find_by_webmock_stub(webmock_stub) ⇒ RequestStub
Finds a RequestStub amongst the endpoint stubs
93 94 95 |
# File 'lib/stub_requests/stub_registry.rb', line 93 def find_by_webmock_stub(webmock_stub) find { |stub| stub.webmock_stub == webmock_stub } end |
#mark_as_responded(webmock_stub) ⇒ void
Note:
Called when webmock responds successfully
This method returns an undefined value.
Mark a RequestStub as having responded
77 78 79 80 81 82 83 |
# File 'lib/stub_requests/stub_registry.rb', line 77 def mark_as_responded(webmock_stub) return unless (request_stub = find_by_webmock_stub(webmock_stub)) request_stub.mark_as_responded CallbackRegistry.instance.invoke_callbacks(request_stub) request_stub end |
#record(endpoint_id, webmock_stub) ⇒ RequestStub
Records a WebMock::RequestStub as stubbed
60 61 62 63 64 65 66 |
# File 'lib/stub_requests/stub_registry.rb', line 60 def record(endpoint_id, webmock_stub) return unless StubRequests.config.record_stubs? request_stub = RequestStub.new(endpoint_id, webmock_stub) concat([request_stub]) request_stub end |
#reset ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resets the map with stubbed endpoints
49 50 51 |
# File 'lib/stub_requests/stub_registry.rb', line 49 def reset @stubs = Concurrent::Array.new end |