Basic Networking | Writing About Healthcare and Technology

Getting up and running with Ruby 2.0, Rails 4, Rspec, Guard and Zeus in Rubymine

I recently decided to switch to using Rails for a new project from Sails.js (I’ll detail the reasons in another post), and decided to take advantage of the latest-and-greatest. Ruby 2.0 is officially released and Rails 4 is on rc1, so I figured it’d be worth some small headaches to just jump on the bandwagon now, rather than using 3.x and attempting to port in all the nice things Rails 4 provides.

Having worked with Rails for the last year, and getting more and more comfortable with rspec as time goes on, I decided to start this project the “right way” and do TDD.  To that end, I decided to start the app by installing rspec, guard and zeus to make sure I have a fast test suite.  The following is the adventure these gems took me on as I attempted to get them all playing nice with Rails 4.

So to start, I installed the gems (and associated gems):


source ''

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 4.0.0.rc1'

gem 'pg', '~> 0.15'

group :development, :test do
  gem 'rspec-rails', '~> 2.13'
  gem 'guard-rspec', '~> 3.0'

group :test do
  gem 'capybara', '~> 2.1'
  gem 'rb-fsevent', '~> 0.9'
  gem 'growl', '~> 1.0'
  gem 'factory_girl_rails', '~> 4.2'
  gem 'simplecov', '~> 0.7'
  gem 'database_cleaner', '~> 0.9'
  gem 'faker', '~> 1.1'
  gem 'capybara-webkit', '~> 0.14'
  gem 'zeus'
  gem 'guard-zeus'

`bundle install` that and we’re off to the fun parts.  I started off following this post from pivotallabs:  I’m going to recap it here so it’s all in one place:

Create a `script` directory, and in it create the following file:

This will be used to configure RSpec within Zeus to play nice with Rubymine (since Rubymine brings a lot of its own libraries and packages).

Next, we need to start zeus with the correct RUBYLIB environment variable, again to account for Rubymine:

To finish setting up RSpec within Rubymine, we need to update the default configuration to use the new runner we just created.

Go into your Run/Debug configurations, select “Defaults”, then “Rspec”.  Check the box that says “Use custom RSpec runner script:”, and in the text field that becomes editable enter the appropriate path to the runner script we created; e.g. “/path/to/my/project/script/rspec_runner.rb”.

Now that we have zeus and RSpec set up to play nicely within Rubymine, the last step is to set up Guard to automatically run our tests when we change a file.  A good SO answer provides some steps for that; I’ll reiterate them here as well:

To start, create a new run configuration by selecting “IRB Console”, and fill in the “IRB Script” line with the path to your rspec bin file.  If you’re using RVM on OS X, it’ll be something like: “/Users/pragone/.rvm/gems/ruby-2.0.0-p0@example-app/bin/guard”.  Set the working directory to the project’s root directory, and you’re off to the races!

The one downside is that I still haven’t found a nice way to *start* zeus within Rubymine; I still start it in the console (using our new script/start_zeus script: `ruby script/start_zeus`); after that, however, I just run the “Guard” configuration we created in the last step.

After all this, however, I still ran into problems.  In the end, it was a misconfiguration in my spec_helper.rb file that was causing problems.  Specifically, I had `require ‘rspec/autorun’` in there, and it should’ve been removed.  I’ve attached my spec_helper.rb and Guardfile for reference here:

  • Thomas Le

    I am using RubyMine on ubuntu 12.04 with Ruby 2.0.0p0 and rails 4.0.0. When I try to run the start_zeus in the script directory I get this.

    script/start_zeus:2: unknown regexp options – RbyM

    script/start_zeus:2: syntax error, unexpected tLABEL


    … ^ (this is pointing at the / near “:/opt”)

    script/start_zeus:2: unknown regexp options – RbyM

    script/start_zeus:2: syntax error, unexpected tIDENTIFIER, expecting keyword_do or ‘{‘ or ‘(‘

    …e-5.4/rb/testing/patch/bdd zeus start

    … ^ (this is pointing at the space between zeus and start)

    Does this not work with the latest version of everything? I might just go back to using the built in rspec running in rubymine. I am just learning about BDD/TDD and want to use the best tools available. inside RM seems to work well.

    I found this post by searching for simplecov. I was trying to get that to work but it doesn’t seem to either.