Sha256: abba28ddc6b727c5da2bceacfa5e7f228361cb87c65d14bfa61a4392ffa2018c

Contents?: true

Size: 832 Bytes

Versions: 2

Compression:

Stored size: 832 Bytes

Contents

require "mock5/version"
require "mock5/api"
require "set"

module Mock5
  extend self

  def mounted_apis
    @_mounted_apis ||= Set.new
  end

  def mock(*args, &block)
    Api.new(*args, &block)
  end

  def mount(*apis)
    apis.each do |api|
      if mounted_apis.add?(api)
        registry.register_request_stub api.request_stub
      end
    end
  end

  def unmount(*apis)
    apis.each do |api|
      if mounted_apis.delete?(api)
        registry.remove_request_stub api.request_stub
      end
    end
  end

  def mounted?(*apis)
    apis.to_set.subset?(mounted_apis)
  end

  def with_mounted(*apis)
    mount *apis
    yield
  ensure
    unmount *apis
  end

  def unmount_all!
    unmount *mounted_apis
  end

  alias_method :reset!, :unmount_all!

  private

  def registry
    WebMock::StubRegistry.instance
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mock5-1.0.2 lib/mock5.rb
mock5-1.0.1 lib/mock5.rb