Class: RSpec::Mocks::InstanceMethodStasher
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/instance_method_stasher.rb
Instance Attribute Summary collapse
-
#original_method ⇒ Object
readonly
Returns the value of attribute original_method.
Instance Method Summary collapse
-
#handle_restoration_failures ⇒ Object
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.
-
#initialize(object, method) ⇒ InstanceMethodStasher
constructor
A new instance of InstanceMethodStasher.
- #method_is_stashed? ⇒ Boolean
- #restore ⇒ Object
- #stash ⇒ Object
- #stashed_method_name ⇒ Object
Constructor Details
#initialize(object, method) ⇒ InstanceMethodStasher
Returns a new instance of InstanceMethodStasher.
5 6 7 8 9 10 11 12 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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 |
Instance Attribute Details
#original_method ⇒ Object (readonly)
Returns the value of attribute original_method.
14 15 16 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/instance_method_stasher.rb', line 14 def original_method @original_method end |
Instance Method Details
#handle_restoration_failures ⇒ Object
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
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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? ⇒ Boolean
18 19 20 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/instance_method_stasher.rb', line 18 def method_is_stashed? @method_is_stashed end |
#restore ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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 ⇒ Object
23 24 25 26 27 28 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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 ⇒ Object
31 32 33 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/instance_method_stasher.rb', line 31 def stashed_method_name "obfuscated_by_rspec_mocks__#{@method}" end |