Sha256: 36d4a80b88c98a645f853667fe86ad37780e72b131eaf68e537c2fe39f921ea1

Contents?: true

Size: 863 Bytes

Versions: 62

Compression:

Stored size: 863 Bytes

Contents

require 'mocha/class_method'

module Mocha

  class AnyInstanceMethod < ClassMethod
  
    def unstub
      remove_new_method
      restore_original_method
      stubbee.any_instance.reset_mocha
    end
    
    def mock
      stubbee.any_instance.mocha
    end
   
    def hide_original_method
      stubbee.class_eval "alias_method :#{hidden_method}, :#{method}" if stubbee.method_defined?(method)
    end

    def define_new_method
      stubbee.class_eval "def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end"
    end

    def remove_new_method
      stubbee.class_eval "remove_method :#{method}"
    end

    def restore_original_method
      stubbee.class_eval "alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}" if stubbee.method_defined?(hidden_method)
    end

  end
  
end

Version data entries

62 entries across 62 versions & 6 rubygems

Version Path
greatseth-google-geo-2.0 vendor/mocha-0.4.0/lib/mocha/any_instance_method.rb
greatseth-google-geo-2.1 vendor/mocha-0.4.0/lib/mocha/any_instance_method.rb
greatseth-google-geo-2.2 vendor/mocha-0.4.0/lib/mocha/any_instance_method.rb
redcar-dev-0.12.1dev-java lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-dev-0.12.0dev-java lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.11 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.11.0dev lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.10 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.9.2 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.9.1 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.9.0 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.8.1 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.8 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.7 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.6.1 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.6 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.6.1dev lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.5.1 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.5 lib/openssl/mocha/lib/mocha/any_instance_method.rb
redcar-0.5.6dev lib/openssl/mocha/lib/mocha/any_instance_method.rb