Skip to content

Commit

Permalink
fix sorbet call_validation_error_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalii Iurev committed Mar 17, 2023
1 parent 0b6b714 commit 1d4a6e0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/mock_suey/sorbet_rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

require "sorbet-runtime"

error_handler = T::Configuration.instance_variable_get(:@call_validation_error_handler)
error_handler ||= proc do |signature, opts|
return T::Configuration.send(:call_validation_error_handler_default, signature, opts)
end

# Let methods with sig receive double/instance_double arguments
T::Configuration.call_validation_error_handler = lambda do |signature, opts|
is_mocked = opts[:value].is_a?(RSpec::Mocks::Double) || opts[:value].is_a?(RSpec::Mocks::VerifyingDouble)
unless is_mocked
return T::Configuration.send(:call_validation_error_handler_default, signature, opts)
end
return error_handler.call(signature, opts) unless is_mocked

# https://github.com/rspec/rspec-mocks/blob/main/lib/rspec/mocks/verifying_double.rb
# https://github.com/rspec/rspec-mocks/blob/v3.12.3/lib/rspec/mocks/test_double.rb
Expand All @@ -20,5 +23,5 @@
are_related = doubled_class <= opts[:type].raw_type
return if are_related

return T::Configuration.send(:call_validation_error_handler_default, signature, opts)
error_handler.call(signature, opts)
end

0 comments on commit 1d4a6e0

Please sign in to comment.