samuelgiles / rspec-sorbet

A small gem consisting of helpers for using Sorbet & RSpec together.
MIT License
39 stars 9 forks source link

Never define call_validation_error_handler twice #26

Closed alex-tan closed 1 year ago

alex-tan commented 1 year ago

It results in a .

I haven't figured out why this is occurring in one of our large code bases but somehow RSpec::Sorbet.allow_doubles! is being called again when Guard runs RSpec after the first time.

It results in this over and over until a SystemStackError is raised when a signature is incorrect:

[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:17:in `block in allow_doubles!'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:32:in `handle_call_validation_error'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:120:in `call_validation_error_handler'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:17:in `block in allow_doubles!'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:32:in `handle_call_validation_error'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:120:in `call_validation_error_handler'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:17:in `block in allow_doubles!'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:32:in `handle_call_validation_error'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:120:in `call_validation_error_handler'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:17:in `block in allow_doubles!'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:32:in `handle_call_validation_error'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:120:in `call_validation_error_handler'
[GEM_PATH]/rspec-sorbet-1.9.1/lib/rspec/sorbet/doubles.rb:17:in `block in allow_doubles!'

I've tested this code out and it fixes the issue for us.

samuelgiles commented 1 year ago

Nice catch @alex-tan, I've taken the idea of this and wrapped it up in a more general mechanism to tear down the handlers the method puts in place: https://github.com/samuelgiles/rspec-sorbet/pull/27

samuelgiles commented 1 year ago

Closing through https://github.com/samuelgiles/rspec-sorbet/pull/27