February 10, 2014

Spring is awesome!

Startup time of Rails applications is getting better and better with new Ruby and Rails versions. But it is still longer than I would like to have it.

Until now I was using spork-rails to preload my test environment so I could run my test faster. But there is a better solution.

Enter spring

Spring is a Rails application preloader. It starts automatically when it is needed. It reloads running application automatically when it is needed. And it is bundled with Rails 4.1.

With spork I could run my test faster. But with spring I can run everything faster, because it can also preload development environment. So now everything is faster, because I do not need to wait until my application starts. For example running database migrations or running rake tasks.

To make it work, you need to generate spring binstubs.

$ bundle exec spring binstub --all

And then make sure that you use them. For example you need to run ./bin/rails instead of rails. Or just configure your environment to run them automatically.

Spring with RSpec

By default Spring will generate binstubs for rails and rake. But if you would like to generate binstub also for rspec then add spring-commands-rspec to your Gemfile.

# Gemfile

# ...

gem 'spring-commands-rspec', group: :development

Hey there!

My name is Patrik Bóna and I am the only programmer at Memberful. This blog is kind of dead, but I just started my own Ruby on Rails screencast. Follow me on Twitter if you want to be notified about my newest videos.