Sha256: 75e4ab8a95858d1ca8c5c304ab7c65b0686bf33137b53f3818b3f10790b099e3

Contents?: true

Size: 755 Bytes

Versions: 15

Compression:

Stored size: 755 Bytes

Contents

require_relative "replaces_type/redefines_new"
require_relative "replaces_type/redefines_singleton_methods"

module Mocktail
  class ReplacesType
    def initialize
      @top_shelf = TopShelf.instance
      @redefines_new = RedefinesNew.new
      @redefines_singleton_methods = RedefinesSingletonMethods.new
    end

    def replace(type)
      unless type.is_a?(Class) || type.is_a?(Module)
        raise UnsupportedMocktail.new("Mocktail.replace() only supports classes and modules")
      end

      if type.is_a?(Class)
        @top_shelf.register_new_replacement!(type)
        @redefines_new.redefine(type)
      end

      @top_shelf.register_singleton_method_replacement!(type)
      @redefines_singleton_methods.redefine(type)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mocktail-1.2.3 lib/mocktail/replaces_type.rb
mocktail-1.2.2 lib/mocktail/replaces_type.rb
mocktail-1.2.1 lib/mocktail/replaces_type.rb
mocktail-1.2.0 lib/mocktail/replaces_type.rb
mocktail-1.1.3 lib/mocktail/replaces_type.rb
mocktail-1.1.2 lib/mocktail/replaces_type.rb
mocktail-1.1.1 lib/mocktail/replaces_type.rb
mocktail-1.1.0 lib/mocktail/replaces_type.rb
mocktail-1.0.0 lib/mocktail/replaces_type.rb
mocktail-0.0.6 lib/mocktail/replaces_type.rb
mocktail-0.0.5 lib/mocktail/replaces_type.rb
mocktail-0.0.4 lib/mocktail/replaces_type.rb
mocktail-0.0.3 lib/mocktail/replaces_type.rb
mocktail-0.0.2 lib/mocktail/replaces_type.rb
mocktail-0.0.1 lib/mocktail/replaces_type.rb