(This was written regarding the RubyMine 4.0 EAP but it probably applies to many of the earlier versions as well.)

When you Run > Edit Configurations in RubyMine you can create a number of different configurations. One of these is a regular Ruby script which can be useful for running such tasks as guard. You select the full path to the *.rb file and then you click the Share configuration check box. You might wonder how you express those paths as relative to the project path; after all you want to share the configuration with your teammates and their paths won't likely match your own.

Well it turns out there's no secret sauce to make this work; RubyMine will substitute the macro value $PROJECT_DIR$ if the script's path is relative to the project you currently have open. In the UI you'll see the fully expanded path, but when you commit your shared project settings the macro value is what is actually recorded in the *.xml file. When your teammates pull down your shared configurations it will be relative to their project's path.

So to get Guard (with Spork) running in RubyMine I did the following:

  1. Created a run_guard.rb file in my project's root
  2. #./run_guard.rb  
    exec 'guard'
  3. RubyMine: Run > Edit Configurations
  4. Hit the + and add a new Ruby script
  5. Name it Guard, select the full path to the run_guard.rb, select the Bundler tab, check run in the context of Bundler (for good measure)
  6. .idea is correctly in my .gitignore file... but the shared configs live under .idea/sharedConfigurations/
  7. git add -f .idea/sharedConfigurations/Guard.xml and commit, push

Run the new Guard configuration and you'll see it display in one of the output panes at the bottom of the screen by default. When you save your specs it will automatically run as normal (but beware that ⌘S saves all files).

We also found out that pry statements in your RubyMine hosted Guard process won't allow you to interact with the running test session; instead the process will just hang.

Update: some more useful RSpec information with RubyMine:

Built in spec task: If your spec task is dying because you've configured a DRb server via Guard (using Spork) and you don't plan on running the built-in Spork task within RubyMine you'll need to make some changes to your Spork.prefork block and add an environment variable for the Guard script itself (Run > Edit Configurations) named "RUBYMINE_HOME" and point it to your RubyMine's application path (i.e. for me its /Applications/RubyMine EAP.app/). Now when Guard is running your built-in rspec task can execute without dying.

growlnotify: if you still want Growl notifications for your RubyMine hosted Guard you may need to sudo ln -s /usr/local/bin/growlnotify /usr/bin/growlnotify.