ruby-on-railsrubysorbet

Sorbet - Unable to resolve constant


After running srb init and srb tc passing in a new Rails project, I installed RSpec and srb tc now has many complaints including:

spec/spec_helper.rb:16: Unable to resolve constant RSpec https://srb.help/5002
    16 |RSpec.configure do |config|

How can I resolve this error?


Solution

  • This is because Sorbet does not know about anything defined in a gem by default. It needs to generate an RBI file for the gem to understand the gem's constants and APIs.

    When installing new gems you have to update the RBI files, which is easy with

    bundle exec tapioca gem