By Billy Shih June 18, 2014

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, which shaves time off of your commands. Like this:

Zeus1

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

zeus consol
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.

Installation

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 it’s done loading.

Zeus2

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.

Fixes

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 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 where 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}",

Other Resources

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


Check out the original post and more resources on Billy’s blog.