Zeus improves Rails boot time. Saving seconds is most important when running focused tests:
rspec spec/models/user_spec.rb
rspec spec/models/user_spec.rb:123
Those are times when a tight feedback loop make a meaningful difference.
Install the Zeus gem on your machine:
gem install zeus
Do not include it in your Gemfile. It is an external piece of software.
Initialize:
zeus init
This will create two files in your Rails app’s directory. Ignore them globally in ~/.gitignore:
custom_plan.rb
zeus.json
Edit zeus.json to include only the tasks for which you’ll use Zeus. Mine looks like this:
{
"command": "ruby -rubygems -r./custom_plan -eZeus.go",
"plan": {
"boot": {
"default_bundle": {
"development_environment": {
"prerake": {"rake": []},
"console": ["c"],
"generate": ["g"]
},
"test_environment": {
"test_helper": {"test": ["rspec"]}
}
}
}
}
}
I remove cucumber in favor of RSpec and Capybara. I remove server in favor of Foreman and Pow.
In spec/spec_helper.rb, change:
ENV['RAILS_ENV'] ||= 'test'
To:
ENV['RAILS_ENV'] = 'test'
The goal is to run tests in the context of Zeus. So, remove other similar systems.
From the RSpec docs:
> Generally, life is simpler if you just use the rspec command. If you
> must use the ruby command, however, you’ll want to do the following:
require 'rspec/autorun'
> This tells RSpec to run your examples.
We don’t need this behavior and can cause bugs when used with Zeus.
Remove either of these lines in spec/spec_helper.rb if they exist:
require 'rspec/autorun'
require 'rspec/autotest'
For the same reasons, if you’re using Spork and Guard, delete them from your Gemfile, delete your Guardfile, and delete any related Spork code in spec/spec_helper.rb or spec/support/.
Zeus will need to be running before you can use its commands:
zeus start
I usually run this, and other long-running processes in a tmux session.
Now, those original commands will have the benefit of Rails boot time in under a second:
zeus rspec spec/models/user_spec.rb
zeus rspec spec/models/user_spec.rb:123
Many of us are running specs directly from vim. If you edit your ~/.vimrc to use Zeus like in this commit, you can run focused specs with:
t
Enjoy!
Written by Dan Croak.