Is it impossible to use Guard with RubyMine?

For some inexplicable reason, RubyMine autosaves every change you make and so every key stroke will trigger Guard to run your tests! And the most ridiculous thing is that there's apparently no way to disable this autosaving "feature". I'm just wondering, RubyMine seems to be a very popular editor among Rails developers and Guard seems to be an indispensable tool used to automate testing. Since Guard is impossible to use reasonably with RubyMine, how do people deal with automating their tests with RubyMine?


Im using RubyMine with Guard all day, and in fact, some parts of Guard have been developed in RubyMine itself.

You can configure the auto-safe behavior by going to RubyMine > Preferences in the menu and enter sync in the search box, then select System Settings from the list.

The picture shows my settings and these works fine. You may also want to disable Save files on frame deactivation, to only save a file on a manual save.

I prefer to use Guard from the terminal, but you can configure RubyMine to run Guard directly by adding a Run configuration by selecting Run > Edit configurations from the menu:

Now you can add a new configuration by clicking on the plus sign + and select IRB console:

Now name the configuration Guard, enter the path to Guard into IRB script and set the project working directory. You may want to enter your Guard arguments as IRB arguments, like different Guard groups, etc.

I found my path to Guard by opening the terminal, changed into the project working directory and entered which guard, which results in /Users/michi/.rvm/gems/ruby-1.9.3-p194/bin/guard for my Ruby 1.9.3-p194 SDK managed by RVM.

Next you need to check the Run the script in context of the bundle in the Bundler tab.

Now press OK and you have a brand new run configuration. Before starting Guard, you should configure the interactor to simple by adding

interactor :simple

to your Guardfile. Now you can run (or even debug) Guard directly within RubyMine:


When you run guard with RubyMine for tests, it is extremely useful to configure a separate database environment for guard spec, or else you'll experience strange issues (one process or the other freezes or gives inconsistent results.

Name your guard spec environment "ci" and create an additional entry in database.yml. I use "ci" for Continuous Automation.

Then put this in your Guardfile. The key thing is

'RAILS_ENV' => 'ci'

Here's how I have mine setup:

group :spec do
  guard :spork, :rspec_port => 1234, :cucumber_env => { 'RAILS_ENV' => 'ci' }, :rspec_env => { 'RAILS_ENV' => 'ci' } do

  # environment is 'ci'
  guard :rspec, :cli => '--drb --drb-port 1234', :version => 2, :all_after_pass => false, :notification => true, :environment => 'ci' do
    watch(%r{^lib/(.+).rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
    watch('spec/spec_helper.rb')  { "spec" }
  # Rails example
    watch(%r{^app/(.+).rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
    watch(%r{^lib/(.+).rb$})                           { |m| "spec/lib/#{m[1]}_spec.rb" }
    watch(%r{^app/controllers/(.+)_(controller).rb$})  do |m|

    watch(%r{^spec/support/(.+).rb$})                  { "spec" }
    watch('config/routes.rb')                          { "spec/routing" }
    watch('app/controllers/application_controller.rb')  { "spec/controllers" }
    # Capybara request specs
    watch(%r{^app/views/(.+)/.*.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }

I then run

bundle exec guard -g spec

I also don't mind having RubyMine save files automatically every 60 seconds even if that kicks off Guard, as my a new MBP Retina does not noticeably slow down when running Guard.

BTW, Guard running specs is really great as you will find failing tests much faster than trying to run the tests yourself in RubyMine. I.e., the test basically is about done by the time my finger releases from cmd-s to save.

I run this from the terminal. I haven't tried running with RubyMine. Anybody want to comment on the advantages of doing that? I guess having the stack dump clickable would be nice.

This is a really frustrating problem, and makes it very hard to use RubyMine with guard or grunt or other task-runners.

I created a bit of a crazy workaround, but it's working well enough for me:

  1. Add an External Tool to run the venerable Unix "touch" command, which updates the modified timestamp of a file, thereby generating a filesystem event. It should look like this:
  2. Assign the External Tool a keyboard shortcut.
  3. Assign a keyboard shortcut to the Save Document command.
  4. Record a macro that runs Save Document, then the "touch" External Tool. You need to use the keyboard shortcuts you assigned because Save Document does not appear in the application's menus.
  5. Assign Cmd-S as a keyboard shortcut for your new macro.

My full blog post about this is at

Or you can add a run_guard.rb file at the root of your project with the following code:

exec 'guard'

Watch out! Rubymine has a problem with your PATH. For example, /usr/local/bin is filtered ...

Need Your Help

How to store only time; not date and time?

sql oracle time

In one field I need to store not a datetime pair, i.e. a standard Oracle date.

Refactor renaming variable in Android Studio Mac Shortcut doesn't work

android android-studio

As on right click of variable in Android Studio, for renaming all specific variable in a file, there is shortcut for Shift + F6 in this window: