(Adapted from a thread on the RubyMine support forums)
Zeus is a self-described “language-agnostic application checkpointer for non-multithreaded applications.” As a Rails developer, you can use Zeus to keep your rails environment loaded so your tests run super fast. Spork does this job as well, but Zeus is newer/shinier and requires less explicit configuration. Zeus’ standard operating mode requires you to keep a Zeus server running (started with zeus start) to which you can issue commands (like zeus rspec).
To get Zeus installed on your system, follow the readme orĀ this lovely post at ThoughtBot. The issue they mention with require ‘rspec/autorun’ should be fixed in the latest Zeus, but you can safely remove it from your spec_helper anyway.
In your Gemfile, add zeus:
group :test do
gem 'zeus'
endYes the Zeus manual wants you to only have one global install, but RubyMine won’t be able to see it when running tests, because it always runs them under bundler. (You’ll get a cannot load such file — zeus or zeus is not part of the bundle error.)
Add this script to your Rails project as script/rspec_runner.rb:
#!/usr/bin/env ruby
# Suppress zeus' whining about how it won't use your RAILS_ENV
ENV.delete('RAILS_ENV')
# Zeus 0.13.2 parses options badly. RubyMine will invoke this file like this:
# rspec_runner.rb spec/my_cool_file.rb --require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter
#
# ...but Zeus will parse those options thinking --require is meant for it, and die.
# If the test file is moved to the end, it dies less.
ARGV.push(ARGV.shift)
# Add rspec to the beginning of the commands sent to Zeus
ARGV.unshift 'rspec'
require 'rubygems'
require 'zeus'
load Gem.bin_path('zeus', 'zeus')
In RubyMine’s ‘Edit Configurations’, under Default -> Rspec:
Check ‘Use Custom Rspec Runner Script’
Set it to [your-absolute-app-path]/script/rspec_runner.rb
Your ‘Edit Configuration’ window should look like this: 
When starting the Zeus server, use the following line:
env RUBYLIB=/Applications/RubyMine.app/rb/testing/patch/common:/Applications/RubyMine.app/rb/testing/patch/bdd zeus start(I made this a script in my project called script/startzeus.)
These directories are where RubyMine keeps its favorite test formatters, and if you don’t tell Zeus about them at server load time, it may never find them. (you’ll get a cannot load such file — teamcity/spec/runner/formatter/teamcity/formatter error). If you’re not on OSX, you should replace these directories with something relevant to your system.
Now you can run a test in RubyMine just like you would normally, and it should be LIGHTNING FAST. Get it? Lightning? Zeus? You get it.
Thanks for the clear instructions, I was looking for exactly this.
February 21, 2013 at 10:36 pm
Have you been able to get the Rubymine debugger to work with zeus? I can get the tests to run using your example above and another approach, but the RubyMine debugger appears to be entirely skipped. I have the debugger working properly with my rspec tests without zeus.
March 8, 2013 at 1:31 pm
This mixed with auto-rerun must be fantastic.
March 11, 2013 at 8:42 pm
Same as @Julie, I’m using this and loving it, but I can’t get it working with the debugger, it’s simply not breaking. Does this work for you? Thanks!
March 30, 2013 at 4:34 pm
I really like how fast Zeus makes my test suite, but be wary that it basically ignores the concept of requiring files. You can remove the ‘require “spec_helper”‘ line from the top of your file and Zeus will still run the test just fine, although it will obviously not run on CI.
March 31, 2013 at 8:05 pm
Hey great article, thanls!
The shell script unfortenately only works for single files, if I do `run all specs in spec` (with the same default run config) i get the following error:
——————————————————————–
zeusclient.go:86: EOF
/Users/erotte/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/file_utils.rb:53:in `block in create_shell_runner’: Command failed with status (1): [/Users/erotte/.rbenv/versions/2.0.0-p0/bin...] (RuntimeError)
from /Users/erotte/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `call’
from /Users/erotte/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `sh’
from /Users/erotte/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `sh’
from /Applications/RubyMine.app/rb/testing/runner/specs_in_folder_runner.rb:139:in `’
from -e:1:in `load’
from -e:1:in `’
——————————————————————–
I didn’t get any further information sorry.
Any ideas about that?
April 11, 2013 at 3:56 pm
Doesn’t work – I get this error: “Unable to attach test reporter to test framework or test framework quit unexpectedly”.
No stack trace. Just this message in red. any idea?
April 15, 2013 at 10:50 am
I get the same error as Joe S . . . but with:
0 files were found.
=========================================
RSpec script : /Users/tim/Sites/polco3/script/rspec_runner.rb
Spec Options:
[]
=========================================
Running specs…
Command line:
["/Users/tim/.rvm/rubies/ruby-1.9.3-p392/bin/ruby", "-e", "$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)", "/Users/tim/Sites/polco3/script/rspec_runner.rb", "--require", "teamcity/spec/runner/formatter/teamcity/formatter", "--format", "Spec::Runner::Formatter::TeamcityFormatter"]
Can’t connect to master. Run zeus start first.
/Users/tim/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/file_utils.rb:53:in `block in create_shell_runner’: Command failed with status (1): [/Users/tim/.rvm/rubies/ruby-1.9.3-p392/bin...] (RuntimeError)
from /Users/tim/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `call’
from /Users/tim/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `sh’
from /Users/tim/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in `sh’
from /Applications/RubyMine.app/rb/testing/runner/specs_in_folder_runner.rb:139:in `’
from -e:1:in `load’
from -e:1:in `’
Process finished with exit code 1
May 5, 2013 at 8:45 am
Pingback: Basic Networking | Human Interaction in Healthcare, Technology and Research