Module: StubRequests::API
Overview
Note:
This module can either be used by its class methods or included in say RSpec
Module API abstraction to reduce the amount of WebMock.stub_request
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#register_service(service_id, service_uri, &block) ⇒ Service
Register a service in the service registry.
-
#stub_endpoint(service_id, endpoint_id, uri_replacements = {}, options = {}, &callback) ⇒ WebMock::RequestStub
Stub a request to a registered service endpoint.
Class Method Details
.included(base) ⇒ Object
:nodoc:
22 23 24 |
# File 'lib/stub_requests/api.rb', line 22 def self.included(base) base.send(:extend, self) end |
Instance Method Details
#register_service(service_id, service_uri, &block) ⇒ Service
Register a service in the service registry
:reek:UtilityFunction
34 35 36 37 38 |
# File 'lib/stub_requests/api.rb', line 34 def register_service(service_id, service_uri, &block) service = ServiceRegistry.instance.register_service(service_id, service_uri) Docile.dsl_eval(service.endpoint_registry, &block) if block.present? service end |
#stub_endpoint(service_id, endpoint_id, uri_replacements = {}, options = {}, &callback) ⇒ WebMock::RequestStub
Stub a request to a registered service endpoint
:reek:UtilityFunction :reek:LongParameterList { max_params: 5 }
65 66 67 68 69 70 71 |
# File 'lib/stub_requests/api.rb', line 65 def stub_endpoint(service_id, endpoint_id, uri_replacements = {}, = {}, &callback) service = ServiceRegistry.instance.get_service!(service_id) endpoint = service.get_endpoint!(endpoint_id) uri = URI::Builder.build(service.uri, endpoint.uri_template, uri_replacements) StubRequests::WebMockBuilder.build(endpoint.verb, uri, , &callback) end |