Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exhaustiveness checking fails with doubles #21

Open
simoleone opened this issue Dec 9, 2022 · 2 comments
Open

Exhaustiveness checking fails with doubles #21

simoleone opened this issue Dec 9, 2022 · 2 comments

Comments

@simoleone
Copy link

For example code like this:

sig {params(x: T.any(A, B, C)).void}
def foo(x)
  case x
  when A
    do_a(x)
  when B
    do_b(x)
  else
    T.absurd(x)
  end
end

If a test does something like this:

let(:fake_a) { instance_double(A) }
it 'probably does not explode' do
  foo(fake_a)
end

It will hit the T.absurd, resulting in an error like this:

     TypeError:
       Control flow reached T.absurd. Got value: #[InstanceDouble(A) (anonymous)]

I'm not sure there is any way to get around this given the way the case statement works but I figured it couldn't hurt to report in case someone had an idea 😄

@multiplegeorges
Copy link

I believe that this issue on rspec-mocks covers the same issue and has a proposed solution.

See a POC here: https://github.com/ImmersiveLabsUkOrg/rspec-mocks/pull/2/files

@samuelgiles Would love your input on how to implement this in rspec-sorbet.

@samuelgiles
Copy link
Owner

Thanks @multiplegeorges, will take a closer look at this shortly.

The call_validation_error_handler approach that rspec-sorbet uses right now happens wayyy after anything that'd help re: case/#<=>.

I like the idea of an approach that works at a lower level like the one in the POC as it could through Sorbet's public API mean we'd avoid having to maintain this method: https://github.com/samuelgiles/rspec-sorbet/blob/master/lib/rspec/sorbet/doubles.rb#L98-L118 + we might be able to support the doubles being a little more transparent to implementation logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants