Sha256: 53c08cce4206e0bce32af3cb1c3ff3ba3278ac79ccf8c7f3ff0abf47a87227c5

Contents?: true

Size: 1.31 KB

Versions: 57

Compression:

Stored size: 1.31 KB

Contents

# typed: ignore

require_relative 'private/methods/_methods'

# Work around an interaction bug with sorbet-runtime and rspec-mocks,
# which occurs when using *_any_instance_of and and_call_original.
#
# When a sig is defined, sorbet-runtime will replace the sigged method
# with a wrapper that, upon first invocation, re-wraps the method with a faster
# implementation.
#
# When expect_any_instance_of is used, rspec stores a reference to the first wrapper,
# to be restored later.
#
# The first wrapper is invoked as part of the test and sorbet-runtime replaces
# the method definition with the second wrapper.
#
# But when mocks are cleaned up, rspec restores back to the first wrapper.
# Upon subsequent invocations, the first wrapper is called, and sorbet-runtime
# throws a runtime error, since this is an unexpected state.
#
# We work around this by forcing re-wrapping before rspec stores a reference
# to the method.
if defined? ::RSpec::Mocks::AnyInstance
  module T
    module CompatibilityPatches
      module RecorderExtensions
        def observe!(method_name)
          method = @klass.instance_method(method_name.to_sym)
          T::Private::Methods.maybe_run_sig_block_for_method(method)
          super(method_name)
        end
      end
      ::RSpec::Mocks::AnyInstance::Recorder.prepend(RecorderExtensions)
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
sorbet-runtime-0.4.4321 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4320 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4319 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4318 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4314 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4313 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4312 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4311 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4310 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4309 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4308 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4307 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4306 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4305 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4304 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4303 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4302 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4301 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4300 lib/types/compatibility_patches.rb
sorbet-runtime-0.4.4299 lib/types/compatibility_patches.rb