How to configure Sorbet with rspec?

473 Views Asked by At

I have a simple test but the describe keyword is not working in Sorbet tests.

The error I'm receiving on these methods:

Method `describe` does not exist on `T.class_of(<root>)`7003
RSpec.describe(Model) do
  describe 'my test' do
    before(:each) do # .before error
      user = FactoryBot.create(:user)
    end

    it 'can fill in all fields' do # .it errors
    end
  end
end

I think I need to tell Sorbet some how that this is called in the context of spec_helper.rbbut I'm not sure how to do that.

I've already installed this gem rspec-sorbet and ran

spec/spec_helper.rb
require 'rspec/sorbet'

To silence the errors, I ran this:

RSpec.describe(Model) do
  T.bind(self, T.untyped)
  # T.bind(self, RSpec) This does not work either
end
1

There are 1 best solutions below

0
On

I've managed to get something kind of working by binding the RSpec file.

First, I installed rspec-sorbet gem which mostly helps with doubles and struct checking, not much else.

Then I manually bind the RSpec test. This allows me to get the autocomplete and benefits of the Sorbet extension although it does not working on everything.

RSpec.describe(MyModel) do
  T.bind(self, T.untyped)
  # add your tests...
end