Class: RSpec::Mocks::InstanceMethodStasher

### Home Classes Methods

### In Files

- lib/rspec/mocks/instance_method_stasher.rb

### Parent

Object

### Methods

- ::new
- #method_is_stashed?
- #restore
- #stash
- #stashed_method_name

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Mocks
- RSpec::Mocks::AllowanceTarget
- RSpec::Mocks::AmbiguousReturnError
- RSpec::Mocks::AndCallOriginalImplementation
- RSpec::Mocks::AndReturnImplementation
- RSpec::Mocks::AndYieldImplementation
- RSpec::Mocks::AnyInstance
- RSpec::Mocks::AnyInstance::Chain
- RSpec::Mocks::AnyInstance::Chain::Customizations
- RSpec::Mocks::AnyInstance::ExpectationChain
- RSpec::Mocks::AnyInstance::MessageChains
- RSpec::Mocks::AnyInstance::PositiveExpectationChain
- RSpec::Mocks::AnyInstance::Recorder
- RSpec::Mocks::AnyInstance::StubChain
- RSpec::Mocks::AnyInstance::StubChainChain
- RSpec::Mocks::AnyInstanceAllowanceTarget
- RSpec::Mocks::AnyInstanceExpectationTarget
- RSpec::Mocks::ArgumentListMatcher
- RSpec::Mocks::ArgumentMatchers
- RSpec::Mocks::ArgumentMatchers::AnyArgMatcher
- RSpec::Mocks::ArgumentMatchers::AnyArgsMatcher
- RSpec::Mocks::ArgumentMatchers::BooleanMatcher
- RSpec::Mocks::ArgumentMatchers::DuckTypeMatcher
- RSpec::Mocks::ArgumentMatchers::EqualityProxy
- RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
- RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::InstanceOf
- RSpec::Mocks::ArgumentMatchers::KindOf
- RSpec::Mocks::ArgumentMatchers::MatcherMatcher
- RSpec::Mocks::ArgumentMatchers::NoArgsMatcher
- RSpec::Mocks::ArgumentMatchers::RegexpMatcher
- RSpec::Mocks::Configuration
- RSpec::Mocks::Constant
- RSpec::Mocks::ConstantMutator
- RSpec::Mocks::ConstantMutator::BaseMutator
- RSpec::Mocks::ConstantMutator::ConstantHider
- RSpec::Mocks::ConstantMutator::DefinedConstantReplacer
- RSpec::Mocks::ConstantMutator::UndefinedConstantSetter
- RSpec::Mocks::ConstantStubber
- RSpec::Mocks::Deprecation
- RSpec::Mocks::ErrorGenerator
- RSpec::Mocks::ExampleMethods
- RSpec::Mocks::ExampleMethods::ExpectHost
- RSpec::Mocks::ExpectationTarget
- RSpec::Mocks::Implementation
- RSpec::Mocks::InstanceExec
- RSpec::Mocks::InstanceMethodStasher
- RSpec::Mocks::Matchers
- RSpec::Mocks::Matchers::HaveReceived
- RSpec::Mocks::Matchers::Receive
- RSpec::Mocks::Matchers::Receive::Customization
- RSpec::Mocks::MessageExpectation
- RSpec::Mocks::MethodDouble
- RSpec::Mocks::MethodDouble::ProcWithBlock
- RSpec::Mocks::Mock
- RSpec::Mocks::MockExpectationError
- RSpec::Mocks::OrderGroup
- RSpec::Mocks::Proxy
- RSpec::Mocks::ProxyForNil
- RSpec::Mocks::RecursiveConstMethods
- RSpec::Mocks::Space
- RSpec::Mocks::StubChain
- RSpec::Mocks::Syntax
- RSpec::Mocks::TargetBase
- RSpec::Mocks::TestDouble
- RSpec::Mocks::Version
- Marshal

No matching classes.

# RSpec::Mocks::InstanceMethodStasher

@private

### Public Class Methods

new(klass, method) click to toggle source

    # File lib/rspec/mocks/instance_method_stasher.rb, line 5
    def initialize(klass, method)
      @klass = klass
      @method = method

      @method_is_stashed = false
    end

### Public Instance Methods

method_is_stashed?() click to toggle source

@private

    # File lib/rspec/mocks/instance_method_stasher.rb, line 13
    def method_is_stashed?
      @method_is_stashed
    end

restore() click to toggle source

@private

    # File lib/rspec/mocks/instance_method_stasher.rb, line 81
    def restore
      return unless @method_is_stashed

      if @klass.__send__(:method_defined?, @method)
        @klass.__send__(:undef_method, @method)
      end
      @klass.__send__(:alias_method, @method, stashed_method_name)
      @klass.__send__(:remove_method, stashed_method_name)
      @method_is_stashed = false
    end

stash() click to toggle source

@private

    # File lib/rspec/mocks/instance_method_stasher.rb, line 18
    def stash
      return if !method_defined_directly_on_klass? || @method_is_stashed

      @klass.__send__(:alias_method, stashed_method_name, @method)
      @method_is_stashed = true
    end

stashed_method_name() click to toggle source

@private

    # File lib/rspec/mocks/instance_method_stasher.rb, line 76
    def stashed_method_name
      "obfuscated_by_rspec_mocks__#{@method}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.