Billy Shih

Writing in English and Code

Develop Faster in Rails With Zeus

Waiting is my least favorite part of developing. In Rails, every time you run a test or a rake command, even if it’s just a few seconds, it’s seconds that stop your flow.

Zeus is a gem that is out to solve that problem. It preloads the Rails app so that when you run commands it doesn’t have to boot up Rails and so shaves time off of your commands. Like this:

Zeus speed comparison

Here are the supported zeus commands.  It makes running all of these faster:

zeus console
zeus server
zeus test (works for rspec too)
zeus cucumber
zeus dbconsole
zeus generate
zeus destroy
zeus rake
zeus runner

Instead of running rails server, you run zeus server and instead of bin/rspec you run zeus rspec, etc.


Zeus requires:
  • OS X 10.7+ OR Linux 2.6.13+
  • Rails 3.x
  • Ruby 1.9.3+
  • Recommended: Use with backported GC from Ruby 2.0
I ended up using this command to get the rvm patch working:
rvm get head && rvm install 1.9.3-p0-perf --patch falcon
To install zeus, simply:
 gem install zeus
Now go to your Rails app’s directory and do:
start zeus

Zeus will show that it’s running and show green statuses when its done loading.
Zeus start console

After that, simply run the zeus commands listed above!

Note: Since RSpec support files and FactoryGirl factories are preloaded, Zeus will need to be restarted to utilize changes to those file types. To restart, ctrl+c to stop Zeus and then run zeus start.

Zeus creates a .zeus.sock file you should add to your .gitignore_global file so that you don’t commit it.


So I ran into a few problems using Zeus, many of which were documented in the GitHub repo. Here are the fixes I used:

Remove the require statements below in ‘spec/spec_helper.rb’ to solve problems with RSpec. RSpec was running twice or getting undefined methods when I ran tests, but this fixed it. (Source 1, 2)
 - require 'rspec/autotest'
 - require 'rspec/autorun'

If you have problems with the “zeus rake” command, try “zeus rspec spec”. I had to do this to fix an “Uninitialized constant FactoryGirl” error. (Source)

Zeus is can be picky about the order of your gems in the gemfile, try reorganizing it or even adding it to your gemfile (although that will slow it down).

Lastly, if you see things behaving incorrectly, try restarting zeus by using ctrl+c to stop it in the terminal you’re running zeus and then running “zeus start” again.

Adding onto Zeus

If you use Sublime Text 2, utilize it with Sublime Text 2 Ruby Tests, which allows you to run tests inside of Sublime Text. Install it via the Package Manager or the GitHub repo. Then customize it to use Zeus by finding the RubyTest.sublime-settings file inside of the RubyTest package directory and copy it. Place the copy in the package User directory. Open the copied file and replace the “run_cucumber_command” and “run_rspec_command” settings with this:

 "run_cucumber_command": "zeus cucumber {relative_path} --no-color",
 "run_single_cucumber_command": "zeus cucumber {relative_path}:{line_number} --no-color",
"run_rspec_command": "zeus rspec {relative_path}",
 "run_single_rspec_command": "zeus rspec {relative_path}:{line_number}",

Andy Wait shows how he uses Zeus with Guard to autorun tests.

Thoughtbot sets up Zeus with some customizations.

The Zeus-Parallel Tests gem combines Zeus and another gem to allow running tests in parallel.

There’s a great Railscast that goes over the Zeus installation as I did above and also covers alternatives called Spring and Command. If you like Zeus or have problems with it, check those out too. Spring looks pretty great and doesn’t require starting up separately, so I might do another post on it.

Let me know your experience with Zeus and if there are any other speedy gems out there by tweeting me or email me.