A summary of data about the Ruby ecosystem.

https://github.com/rails/spring

Rails application preloader
https://github.com/rails/spring

Keywords from Contributors

activerecord activejob mvc rubygems rack crash-reporting rspec rubocop code-formatter static-code-analysis

Last synced: about 22 hours ago
JSON representation

Repository metadata

Rails application preloader

README.md

Spring

Build Status
Gem Version

Spring is a Rails application preloader. It speeds up development by
keeping your application running in the background, so you don't need to
boot it every time you run a test, rake task or migration.

Features

  • Totally automatic; no need to explicitly start and stop the background process
  • Reloads your application code on each run
  • Restarts your application when configs / initializers / gem
    dependencies are changed

Compatibility

  • Ruby versions: MRI 3.1+
  • Rails versions: 7.1+
  • Bundler v2.1+

Spring makes extensive use of Process.fork, so won't be able to
provide a speed up on platforms which don't support forking (Windows, JRuby).

Walkthrough

Setup

Add Spring to your Gemfile:

gem "spring", group: :development

(Note: using gem "spring", git: "..." won't work and is not a
supported way of using Spring.)

It's recommended to 'springify' the executables in your bin/
directory:

$ bundle install
$ bundle exec spring binstub --all

This generates a bin/spring executable, and inserts a small snippet of
code into relevant existing executables. The snippet looks like this:

begin
  load File.expand_path('../spring', __FILE__)
rescue LoadError => e
  raise unless e.message.include?('spring')
end

On platforms where Spring is installed and supported, this snippet
hooks Spring into the execution of commands. In other cases, the snippet
will just be silently ignored, and the lines after it will be executed as
normal.

If you don't want to prefix every command you type with bin/, you
can use direnv to
automatically add ./bin to your PATH when you cd into your application.
Simply create an .envrc file with the command PATH_add bin in your
Rails directory.

Enable reloading

Spring reloads application code, and therefore needs the application to have
reloading enabled.

Ensure that config.enable_reloading is true in the environments that
Spring manages. That setting is typically configured in
config/environments/*.rb. In particular, make sure it is true for the
test environment.

Note: in versions of Rails before 7.1, the setting is called cache_classes,
and it needs to be false for Spring to work.

Usage

For this walkthrough I've generated a new Rails application, and run
rails generate scaffold post name:string.

Let's run a test:

$ time bin/rake test test/controllers/posts_controller_test.rb
Running via Spring preloader in process 2734
Run options:

# Running tests:

.......

Finished tests in 0.127245s, 55.0121 tests/s, 78.5887 assertions/s.

7 tests, 10 assertions, 0 failures, 0 errors, 0 skips

real    0m2.165s
user    0m0.281s
sys     0m0.066s

That wasn't particularly fast because it was the first run, so Spring
had to boot the application. It's now running:

$ bin/spring status
Spring is running:

26150 spring server | spring-demo-app | started 3 secs ago
26155 spring app    | spring-demo-app | started 3 secs ago | test mode

The next run is faster:

$ time bin/rake test test/controllers/posts_controller_test.rb
Running via Spring preloader in process 8352
Run options:

# Running tests:

.......

Finished tests in 0.176896s, 39.5714 tests/s, 56.5305 assertions/s.

7 tests, 10 assertions, 0 failures, 0 errors, 0 skips

real    0m0.610s
user    0m0.276s
sys     0m0.059s

If we edit any of the application files, or test files, the changes will
be picked up on the next run without the background process having to
restart. This works in exactly the same way as the code reloading
which allows you to refresh your browser and instantly see changes during
development.

But if we edit any of the files which were used to start the application
(configs, initializers, your gemfile), the application needs to be fully
restarted. This happens automatically.

Let's "edit" config/application.rb:

$ touch config/application.rb
$ bin/spring status
Spring is running:

26150 spring server | spring-demo-app | started 36 secs ago
26556 spring app    | spring-demo-app | started 1 sec ago | test mode

The application detected that config/application.rb changed and
automatically restarted itself.

If we run a command that uses a different environment, then that
environment gets booted up:

$ bin/rake routes
Running via Spring preloader in process 2363
    posts GET    /posts(.:format)          posts#index
          POST   /posts(.:format)          posts#create
 new_post GET    /posts/new(.:format)      posts#new
edit_post GET    /posts/:id/edit(.:format) posts#edit
     post GET    /posts/:id(.:format)      posts#show
          PUT    /posts/:id(.:format)      posts#update
          DELETE /posts/:id(.:format)      posts#destroy

$ bin/spring status
Spring is running:

26150 spring server | spring-demo-app | started 1 min ago
26556 spring app    | spring-demo-app | started 42 secs ago | test mode
26707 spring app    | spring-demo-app | started 2 secs ago | development mode

There's no need to "shut down" Spring. This will happen automatically
when you close your terminal. However, if you do want to do a manual shut
down, use the stop command:

$ bin/spring stop
Spring stopped.

From within your code, you can check whether Spring is active with if defined?(Spring).

Removal

To remove Spring:

  • 'Unspring' your bin/ executables: bin/spring binstub --remove --all
  • Remove spring from your Gemfile

Deployment

You must not install Spring on your production environment. To prevent it from
being installed, run the bundle config set without 'development test' before
bundle install command which is used to install gems on your production
machines:

$ bundle config set without 'development test'
$ bundle install

Commands

rake

Runs a rake task. Rake tasks run in the development environment by
default. You can change this on the fly by using the RAILS_ENV
environment variable. The environment is also configurable with the
Spring::Commands::Rake.environment_matchers hash. This has sensible
defaults, but if you need to match a specific task to a specific
environment, you'd do it like this:

Spring::Commands::Rake.environment_matchers["perf_test"] = "test"
Spring::Commands::Rake.environment_matchers[/^perf/]     = "test"

# To change the environment when you run `rake` with no arguments
Spring::Commands::Rake.environment_matchers[:default] = "development"

rails console, rails generate, rails runner

These execute the rails command you already know and love. If you run
a different sub command (e.g. rails server) then Spring will automatically
pass it through to the underlying rails executable (without the
speed-up).

Additional commands

You can add these to your Gemfile for additional commands:

Use without adding to bundle

If you don't want Spring-related code checked into your source
repository, it's possible to use Spring without adding to your Gemfile.
However, using Spring binstubs without adding Spring to the Gemfile is not
supported.

To use Spring like this, do a gem install spring and then prefix
commands with spring. For example, rather than running bin/rake -T,
you'd run spring rake -T.

Temporarily disabling Spring

If you're using Spring binstubs, but temporarily don't want commands to
run through Spring, set the DISABLE_SPRING environment variable.

Class reloading

Spring uses Rails' class reloading mechanism to keep your code up to date
between test runs. This is the same mechanism which allows you to see changes
during development when you refresh the page. However, you may never have used
this mechanism with your test environment before, and this can cause problems.

It's important to realise that code reloading means that the constants
in your application are different objects after files have changed:

$ bin/rails runner 'puts User.object_id'
70127987886040
$ touch app/models/user.rb
$ bin/rails runner 'puts User.object_id'
70127976764620

Suppose you have an initializer config/initializers/save_user_class.rb
like so:

USER_CLASS = User

This saves off the first version of the User class, which will not
be the same object as User after the code has been reloaded:

$ bin/rails runner 'puts User == USER_CLASS'
true
$ touch app/models/user.rb
$ bin/rails runner 'puts User == USER_CLASS'
false

So to avoid this problem, don't save off references to application
constants in your initialization code.

Using Spring with a containerized development environment

As of Spring 1.7, there is some support for doing this. See this
example
repository
for
information about how to do it with Docker.

Configuration

Spring will read ~/.spring.rb and config/spring.rb for custom
settings. Note that ~/.spring.rb is loaded before bundler, but
config/spring.rb is loaded after bundler. So if you have any
spring-commands-* gems installed that you want to be available in all
projects without having to be added to the project's Gemfile, require
them in your ~/.spring.rb.

config/spring_client.rb is also loaded before bundler and before a
server process is started, it can be used to add new top-level commands.

Application root

Spring must know how to find your Rails application. If you have a
normal app everything works out of the box. If you are working on a
project with a special setup (an engine for example), you must tell
Spring where your app is located:

Spring.application_root = './test/dummy'

Running code before forking

There is no Spring.before_fork callback. To run something before the
fork, you can place it in ~/.spring.rb or config/spring.rb or in any of the files
which get run when your application initializes, such as
config/application.rb, config/environments/*.rb or
config/initializers/*.rb.

Running code after forking

You might want to run code after Spring forked off the process but
before the actual command is run. You might want to use an
after_fork callback if you have to connect to an external service,
do some general cleanup or set up dynamic configuration.

Spring.after_fork do
  # run arbitrary code
end

If you want to register multiple callbacks you can simply call
Spring.after_fork multiple times with different blocks.

Watching files and directories

Spring will automatically detect file changes to any file loaded when the server
boots. Changes will cause the affected environments to be restarted.

If there are additional files or directories which should trigger an
application restart, you can specify them with Spring.watch:

Spring.watch "config/some_config_file.yml"

By default, Spring polls the filesystem for changes once every 0.2 seconds. This
method requires zero configuration, but if you find that it's using too
much CPU, then you can use event-based file system listening by
installing the
spring-watcher-listen
gem.

Quiet output

To disable the "Running via Spring preloader" message which is shown each time
a command runs:

Spring.quiet = true

You can also set the initial state of the quiet configuration option to true
by setting the SPRING_QUIET environment variable before executing Spring.
This is useful if you want to set quiet mode when invoking the Spring executable
in a subprocess, and cannot or prefer not to set it programmatically
via the Spring.quiet option in ~/.spring.rb or the app's config/spring.rb.

Environment variables

The following environment variables are used by Spring:

  • DISABLE_SPRING - If set, Spring will be bypassed, and your
    application will boot in a foreground process
  • SPRING_LOG - The path to a file which Spring will write log messages
    to.
  • SPRING_TMP_PATH - The directory where Spring should write its temporary
    files (a pidfile and a socket). By default, we use the
    XDG_RUNTIME_DIR environment variable, or else Dir.tmpdir, and then
    create a directory in that named spring-$UID. We don't use your
    Rails application's tmp/ directory because that may be on a
    filesystem which doesn't support UNIX sockets.
  • SPRING_APPLICATION_ID - Used to identify distinct Rails
    applications. By default, it is an MD5 hash of the current
    RUBY_VERSION, and the path to your Rails project root.
  • SPRING_SOCKET - The path which should be used for the UNIX socket
    which Spring uses to communicate with the long-running Spring server
    process. By default, this is SPRING_TMP_PATH/SPRING_APPLICATION_ID.
  • SPRING_PIDFILE - The path which should be used to store the pid of
    the long-running Spring server process. By default, this is related to
    the socket path; if the socket path is /foo/bar/spring.sock the
    pidfile will be /foo/bar/spring.pid.
  • SPRING_QUIET - If set, the initial state of the Spring.quiet
    configuration option will default to true.
  • SPRING_SERVER_COMMAND - The command to run to start up the Spring
    server when it is not already running. Defaults to spring _[version]_ server --background.

Troubleshooting

If you want to get more information about what Spring is doing, you can
run Spring explicitly in a separate terminal:

$ spring server

Logging output will be printed to stdout. You can also send log output
to a file with the SPRING_LOG environment variable.


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 1 day ago

Total Commits: 761
Total Committers: 136
Avg Commits per committer: 5.596
Development Distribution Score (DDS): 0.448

Commits in past year: 27
Committers in past year: 9
Avg Commits per committer in past year: 3.0
Development Distribution Score (DDS) in past year: 0.37

Name Email Commits
Jon Leighton j@j****m 420
Rafael Mendonça França r****l@r****g 63
Michael Grosser m****l@g****t 23
Yves Senn y****n@g****m 21
Jean Boussier j****r@g****m 18
Robert Jackson r****n@m****m 11
Jeremy Daer j****r@g****m 9
David Rodríguez d****z@r****t 8
Felix Bünemann b****n@l****o 5
Xavier Noria f****n@h****m 5
Akira Matsuda r****e@d****p 4
Gannon McGibbon g****n@g****m 4
Thomas Scholtes t****s@g****e 4
Aditya Prakash a****2@g****m 3
Cody Cutrer c****y@c****s 3
Fumiaki MATSUSHIMA m****m@g****m 3
Gabriel Sobrinho g****o@g****m 3
Paweł Charyło p****o@r****m 3
Tomohiro Nishimura t****8@g****m 3
Wojciech Wnętrzak w****k@g****m 3
yuuji.yaginuma y****a@g****m 3
Tim Rogers t****m@g****m 3
Roberto Miranda r****r@g****m 2
Rubem Nakamura r****a@g****m 2
Ryan Patterson c****y@c****m 2
Rémy Coutable r****y@r****e 2
Adrianna Chang a****g@s****m 2
Alex Ghiculescu a****x@t****o 2
Andrew Novoselac a****c@s****m 2
Matt Brictson m****t@5****m 2
and 106 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 11 days ago

Total issues: 66
Total pull requests: 111
Average time to close issues: almost 2 years
Average time to close pull requests: 7 months
Total issue authors: 61
Total pull request authors: 63
Average comments per issue: 5.32
Average comments per pull request: 1.24
Merged pull request: 63
Bot issues: 0
Bot pull requests: 0

Past year issues: 6
Past year pull requests: 15
Past year average time to close issues: 4 months
Past year average time to close pull requests: about 1 month
Past year issue authors: 5
Past year pull request authors: 8
Past year average comments per issue: 2.5
Past year average comments per pull request: 0.13
Past year merged pull request: 7
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/rails/spring

Top Issue Authors

  • tagliala (2)
  • thebravoman (2)
  • mattbrictson (2)
  • fschwahn (2)
  • davidmles (2)
  • fmichaut-diff (1)
  • davingee (1)
  • coding-red-panda (1)
  • williantenfen (1)
  • johnmaxwell (1)
  • fxn (1)
  • mockdeep (1)
  • visibletrap (1)
  • yv3s (1)
  • DTrejo (1)

Top Pull Request Authors

  • casperisfine (8)
  • byroot (7)
  • rafaelfranca (6)
  • gmcgibbon (5)
  • prognostikos (4)
  • chaadow (4)
  • andrewn617 (4)
  • f1sherman (3)
  • kpumuk (3)
  • nvasilevski (3)
  • amomchilov (2)
  • ghiculescu (2)
  • m-nakamura145 (2)
  • zygzagZ (2)
  • masato-hi (2)

Top Issue Labels

  • bug (2)

Top Pull Request Labels


Package metadata

gem.coop: spring

Preloads your application so things like console, rake and tests run faster

rubygems.org: spring

Preloads your application so things like console, rake and tests run faster

gem.coop: nrispring

Preloads your application so things like console, rake and tests run faster

  • Homepage: https://github.com/rails/spring
  • Documentation: http://www.rubydoc.info/gems/nrispring/
  • Licenses: MIT
  • Latest release: 2.1.3 (published over 5 years ago)
  • Last Synced: 2026-02-28T11:02:44.793Z (3 days ago)
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 59,251 Total
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 4.345%
    • Downloads: 13.035%
  • Maintainers (1)
proxy.golang.org: github.com/rails/spring

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/rails/spring#section-documentation
  • Licenses: mit
  • Latest release: v4.4.2+incompatible (published 27 days ago)
  • Last Synced: 2026-02-28T11:02:46.209Z (3 days ago)
  • Versions: 51
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Stargazers count: 1.284%
    • Forks count: 1.511%
    • Average: 5.793%
    • Dependent packages count: 9.576%
    • Dependent repos count: 10.802%
rubygems.org: nrispring

Preloads your application so things like console, rake and tests run faster

  • Homepage: https://github.com/rails/spring
  • Documentation: http://www.rubydoc.info/gems/nrispring/
  • Licenses: MIT
  • Latest release: 2.1.3 (published over 5 years ago)
  • Last Synced: 2026-02-28T11:02:44.707Z (3 days ago)
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 59,251 Total
  • Rankings:
    • Stargazers count: 0.613%
    • Forks count: 1.351%
    • Downloads: 12.266%
    • Average: 15.343%
    • Dependent packages count: 15.706%
    • Dependent repos count: 46.782%
  • Maintainers (1)
ubuntu-24.04: ruby-spring

  • Homepage: https://github.com/rails/spring
  • Licenses:
  • Latest release: 2.1.1-2 (published 25 days ago)
  • Last Synced: 2026-02-06T16:04:29.509Z (25 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-10: ruby-spring

  • Homepage: https://github.com/rails/spring
  • Documentation: https://packages.debian.org/buster/ruby-spring
  • Licenses:
  • Latest release: 2.0.2-4 (published 20 days ago)
  • Last Synced: 2026-02-13T04:26:20.461Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.04: ruby-spring

  • Homepage: https://github.com/rails/spring
  • Licenses:
  • Latest release: 2.1.1-2 (published 20 days ago)
  • Last Synced: 2026-02-11T06:50:23.916Z (20 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-20.04: ruby-spring

  • Homepage: https://github.com/rails/spring
  • Licenses:
  • Latest release: 2.1.0-1 (published 18 days ago)
  • Last Synced: 2026-02-13T07:23:17.009Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.10: ruby-spring

  • Homepage: https://github.com/rails/spring
  • Licenses:
  • Latest release: 2.1.1-2 (published 22 days ago)
  • Last Synced: 2026-02-09T17:22:16.945Z (22 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-11: ruby-spring

  • Homepage: https://github.com/rails/spring
  • Documentation: https://packages.debian.org/bullseye/ruby-spring
  • Licenses:
  • Latest release: 2.1.0-2 (published 20 days ago)
  • Last Synced: 2026-02-13T08:24:58.014Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.10: ruby-spring

  • Homepage: https://github.com/rails/spring
  • Licenses:
  • Latest release: 2.1.1-2 (published 18 days ago)
  • Last Synced: 2026-02-13T18:33:22.732Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-12: ruby-spring

  • Homepage: https://github.com/rails/spring
  • Documentation: https://packages.debian.org/bookworm/ruby-spring
  • Licenses:
  • Latest release: 2.1.1-2 (published 18 days ago)
  • Last Synced: 2026-02-12T23:42:09.237Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
ubuntu-22.04: ruby-spring

  • Homepage: https://github.com/rails/spring
  • Licenses:
  • Latest release: 2.1.1-2 (published 18 days ago)
  • Last Synced: 2026-02-13T13:26:25.072Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-13: ruby-spring

  • Homepage: https://github.com/rails/spring
  • Documentation: https://packages.debian.org/trixie/ruby-spring
  • Licenses:
  • Latest release: 2.1.1-2 (published 19 days ago)
  • Last Synced: 2026-02-13T13:20:03.294Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%

Dependencies

Gemfile rubygems
  • activesupport >= 0
  • activesupport >= 7.0.0.alpha
spring.gemspec rubygems
  • activesupport >= 0 development
  • bump >= 0 development
  • rake >= 0 development
.github/workflows/ci.yml actions
  • actions/checkout v2 composite
  • ruby/setup-ruby v1 composite
.devcontainer/Dockerfile docker
  • mcr.microsoft.com/vscode/devcontainers/ruby 0-${VARIANT} build

Score: 34.082219197903626