Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 526
steel Avatar asked Sep 11 '25 13:09

steel


2 Answers

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
like image 173
steel Avatar answered Sep 14 '25 05:09

steel


Adding an update here, srb rbi is deprecated in favor of tapioca (https://github.com/Shopify/tapioca)

bundle exec tapioca init should resolve these issues

like image 33
Richard Mark Avatar answered Sep 14 '25 06:09

Richard Mark