Sha256: 7c8ae81b93dfca2cf21001b4da5cadea3e9f08a15df329f9033f359eacda0974

Contents?: true

Size: 1.34 KB

Versions: 388

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true
# 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

388 entries across 388 versions & 1 rubygems

Version Path
sorbet-runtime-0.5.5435 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5434 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5430 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5429 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5427 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5420 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5417 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5413 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5410 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5406 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5403 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5400 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5391 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5390 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5388 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5384 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5376 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5373 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5371 lib/types/compatibility_patches.rb
sorbet-runtime-0.5.5369 lib/types/compatibility_patches.rb