lib/stub_requests/api.rb in stub_requests-0.1.4 vs lib/stub_requests/api.rb in stub_requests-0.1.5

- old
+ new

@@ -13,11 +13,10 @@ # @note This module can either be used by its class methods # or included in say RSpec # # @author Mikael Henriksson <mikael@zoolutions.se> # - # :reek:DataClump module API # extends "self" # @!parse extend self extend self @@ -32,47 +31,70 @@ # @param [Symbol] service_id a descriptive id for the service # @param [Symbol] service_uri the uri used to call the service # # @example Register a service with endpoints # register_service(:documents, "https://company.com/api/v1") do - # register_endpoints do - # register(:show, :get, "documents/:id") - # register(:index, :get, "documents") - # register(:create, :post, "documents") - # register(:update, :patch, "documents/:id") - # register(:destroy, :delete, "documents/:id") - # end + # get "documents/:id", as: :show + # get "documents", as: :index + # post "documents", as: :create + # patch "documents/:id", as: :update + # delete "documents/:id", as: :destroy # end # # @return [Service] a new service or a previously registered service # - # :reek:UtilityFunction def register_service(service_id, service_uri, &block) StubRequests::ServiceRegistry.register_service(service_id, service_uri, &block) end # + # Define stub methods for service in the receiver + # + # + # @see DSL#define_stubs + # + # @param [Symbol] service_id the id of a registered service + # @param [Module] receiver the receiver of the stub methods + # + # @return [void] outputs a list of methods to the console + # + def define_stubs(service_id, receiver:) + DSL.new(service_id, receiver: receiver).define_stubs + end + + # + # Print stub method definitions to manually add to a module or class + # + # @see DSL#print_stubs + # + # @param [Symbol] service_id the id of a registered service + # + # @return [void] prints to STDOUT + # + def print_stubs(service_id) + DSL.new(service_id).print_stubs + end + + # # Stub a request to a registered service endpoint # # # @param [Symbol] service_id the id of a registered service # @param [Symbol] endpoint_id the id of a registered endpoint # @param [Hash<Symbol>] route_params a map with route parameters # # @note the kind of timeout error raised by webmock is depending on the HTTP client used # # @example Stub a request to a registered service endpoint using block version - # register_stub(:documents, :index) do + # stub_endpoint(:documents, :index) do # with(headers: { "Accept" => "application/json" }}}) # to_return(body: "No content", status: 204) # end # # @see #stub_http_request # @return [WebMock::RequestStub] a mocked request # - # :reek:UtilityFunction - # :reek:LongParameterList { max_params: 5 } def stub_endpoint(service_id, endpoint_id, route_params = {}, &callback) StubRequests::ServiceRegistry.stub_endpoint(service_id, endpoint_id, route_params, &callback) end # @@ -83,12 +105,10 @@ # @param [Symbol] verb an HTTP verb/method # @param [Proc] callback a Proc to call when receiving response # # @return [void] # - # :reek:UtilityFunction - # :reek:LongParameterList def register_callback(service_id, endpoint_id, verb, callback) StubRequests::CallbackRegistry.register(service_id, endpoint_id, verb, callback) end # @@ -97,10 +117,9 @@ # @param [Symbol] service_id the id of a service # @param [Symbol] endpoint_id the id of an endpoint # # @return [void] # - # :reek:UtilityFunction def unregister_callback(service_id, endpoint_id, verb) StubRequests::CallbackRegistry.unregister(service_id, endpoint_id, verb) end end end