class RSpec::Mocks::InstanceMethodStasher

@private

Attributes

original_method[R]

Public Instance Methods

handle_restoration_failures() { || ... } click to toggle source

ruby 2.0.0-p247 and 2.0.0-p195 both have a bug that we can’t work around :(. bugs.ruby-lang.org/issues/8686

# File lib/rspec/mocks/instance_method_stasher.rb, line 79
def handle_restoration_failures
  yield
rescue TypeError
  RSpec.warn_with(
    "RSpec failed to properly restore a partial double (#{@object.inspect}) "              "to its original state due to a known bug in MRI 2.0.0-p195 & p247 "              "(https://bugs.ruby-lang.org/issues/8686). This object may remain "              "screwed up for the rest of this process. Please upgrade to 2.0.0-p353 or above.",
    :call_site => nil, :use_spec_location_as_call_site => true
  )
end
method_is_stashed?() click to toggle source

@private

# File lib/rspec/mocks/instance_method_stasher.rb, line 18
def method_is_stashed?
  @method_is_stashed
end
restore() click to toggle source

@private

# File lib/rspec/mocks/instance_method_stasher.rb, line 36
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 23
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 31
def stashed_method_name
  "obfuscated_by_rspec_mocks__#{@method}"
end

Public Class Methods

new(object, method) click to toggle source
# File lib/rspec/mocks/instance_method_stasher.rb, line 5
def initialize(object, method)
  @object = object
  @method = method
  @klass = (class << object; self; end)

  @original_method = nil
  @method_is_stashed = false
end