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):
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”.
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: