Sha256: 9e4e17ba6e93a072e48a44b5138841ce88cc5129f41af581a2cb12dbe11f6416

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

#
# Abstraction over WebMock to reduce duplication
#
# @author Mikael Henriksson <mikael@zoolutions.se>
# @since 0.1.0
#
module StubRequests
  #
  # Module WebMock extends WebMock with more functionality
  #
  # @author Mikael Henriksson <mikael@zoolutions.se>
  # @since 0.1.2
  #
  module WebMock
    #
    # Module StubRegistryExtension extends WebMock::StubRegistry with
    #   recording of when a response was found and used for a WebMock::RequestStub
    #
    # @author Mikael Henriksson <mikael@zoolutions.se>
    # @since 0.1.2
    #
    module StubRegistryExtension
      # :nodoc:
      def self.included(base)
        base.class_eval do
          alias_method :request_stub_for_orig, :request_stub_for
          alias_method :request_stub_for, :request_stub_for_ext
        end
      end

      private

      def request_stub_for_ext(request_signature)
        request_stub = request_stub_for_orig(request_signature)
        return request_stub unless request_stub

        StubRequests::StubRegistry.instance.mark_as_responded(request_stub)
        request_stub
      end
    end
  end
end

::WebMock::StubRegistry.send(:include, StubRequests::WebMock::StubRegistryExtension)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stub_requests-0.1.11 lib/stub_requests/webmock/stub_registry_extension.rb
stub_requests-0.1.10 lib/stub_requests/webmock/stub_registry_extension.rb