Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Running tests with Zeus in RubyMine

Travis Grathwell
Tuesday, February 5, 2013

(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'
end

Yes 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: zeus_setup

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.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

9 Comments

  1. Sebastian says:

    Thanks for the clear instructions, I was looking for exactly this.

    February 21, 2013 at 10:36 pm

  2. Julie says:

    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

  3. Rasheed Abdul-Aziz
    Rasheed Abdul-Aziz says:

    This mixed with auto-rerun must be fantastic.

    March 11, 2013 at 8:42 pm

  4. Ole says:

    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

  5. Brian Butz
    Brian Butz says:

    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

  6. Eckhard Rotte says:

    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

  7. Joe S says:

    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

  8. Tim Booher says:

    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

  9. Pingback: Basic Networking | Human Interaction in Healthcare, Technology and Research

Add New Comment Cancel reply

Your email address will not be published.

Travis Grathwell

Travis Grathwell
San Francisco

Recent Posts

  • [Standup][SF] 07/24/12: W doesn’t always mean Wednesday
Subscribe to Travis's Feed

Author Topics

rspec (1)
ruby (1)
rubymine (1)
zeus (1)
sf (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >