A Sorbet build for Rails apps that type-checks specs, factories, and ERB views
open sourceApache-2.0self-hostablefree
Forked from Sorbet in 2026. To type-check the Ruby DSLs and Rails code that upstream Sorbet leaves untyped (RSpec, Capybara, rswag, FactoryBot, ActiveAdmin, ERB views, the methods Rails and Sidekiq define), through rewriter plugins compiled into the build; upstream offers no way for third-party rewriters to plug in
DocSpring's Sorbet build is upstream Sorbet plus a small plugin core, compiled with rewriter plugins from DocSpring/sorbet-plugins that teach Sorbet the Ruby DSLs whose blocks it otherwise can't type. The plugins cover RSpec (spec types, loops, shared examples), Capybara's feature DSL, rswag, FactoryBot (checked factory, trait and attribute names) and ActiveAdmin. erb_views type-checks Rails ERB templates at typed: strict, with instance variable types inferred from the controller actions that render them and partial locals typed by a sig comment. rails writes the methods Rails, Sidekiq, ViewComponent and Shrine define from an app's own code (model columns from db/structure.sql, associations, scopes, enums, job perform_async, mailer actions) in place of Tapioca's DSL RBIs, reporting an error instead of guessing when it can't type something exactly. Plugins run only when enabled, so without flags the build behaves like upstream.
Problems it solves
- Sorbet leaves every RSpec block untyped, so our specs get no type checking at all
- type-check ERB view templates in a Rails app
- a typo in an instance variable in a Rails view only shows up as nil at runtime
- catch a misspelled FactoryBot trait or attribute name before running the test suite
- partial locals in Rails views have no types and break silently when someone renames one
- Tapioca's DSL RBIs go stale every time someone adds a column or a scope and forgets to regenerate
- Sorbet can't see the perform_async signature of my Sidekiq jobs
- ActiveAdmin register blocks are a black hole for static typing
- rswag API specs and Capybara feature specs don't type-check
- teach a Ruby type checker about a DSL by rewriting the syntax tree before it runs
- get typed model attributes and associations without running the app to generate RBIs
- ViewComponent slot methods and Shrine attachment readers show up as missing methods in Sorbet
Features
- rspec plugin: spec-type modules, test_each loops, typed example params, let_it_be and before_all
- capybara and rswag DSLs as RSpec groups
- factory_bot plugin: checked factory, trait and attribute names, typed results
- active_admin plugin: binds register blocks to the DSL, view or controller
- erb_views plugin: ERB templates checked at typed: strict with typed ivars and partial locals
- rails plugin: model columns, associations, scopes, enums, job, mailer, helper, ViewComponent and Shrine methods from the app's code
- RBI generators that run inside the app
- plugin API for writing new rewriters (C++, Bazel)
Capabilities
| Has a command line tool | plan not known |
|---|---|
| Takes plugins | plan not known |
What this fork adds
- A rewriter plugin API (plugins/Plugin.h) and a host that fills Sorbet's existing link-time SemanticExtensionProvider slot, with --enable-plugin=<name> and the plugin repositories compiled in Not offered upstream
- Two more hooks for plugins: transformSource gives Sorbet the Ruby to parse for a file in another language (ERB templates) at the same byte offsets, and strictLevelWithoutSigil gives such a file's strictness Not offered upstream
- PluginError (3590), the error a plugin reports on code it can't type exactly Not offered upstream
- Several sigs a rewriter or plugin writes before one method are overloads, as in an RBI file, so the rails plugin can write Tapioca's overloaded relation methods into each model Not offered upstream
- A positional or ** parameter that a plugin synthesized keeps its name in errors and hover instead of showing an empty name, <arg>1 or <kwargs> Not offered upstream
- The language server runs the plugins in every copy of its state that indexes or hashes a file, so the first edit after startup no longer drops the plugins' methods Not offered upstream
- Semantic extensions run on files indexed on worker threads (copyForIndexThread copies them) Merged upstream pull request
Alternatives
The same job
These do what Sorbet for Rails does.
- sorbet_view Extracts Ruby code from view templates (ERB, etc.) for Sorbet type-checking, with LSP support
- sorbet_erb Extracts Ruby code from ERB files so you can run Sorbet over them
- Tapioca The swiss army knife of RBI generation
- Sorbet A fast, powerful type checker designed for Ruby
- Steep Gradual typing for Ruby
