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?
-
There is an open issue for this: http://youtrack.jetbrains.com/issue/RUBY-9903. – CrazyCoder Aug 16 '12 at 22:14
-
I'd personally rather have no auto save at all. Sometimes, especially with vim strokes, you may mistakenly add an extra character somewhere in the current file while switching to another and not notice. Usually tests catch this but one time in a .js file I had deployed an appended "z" at the very end and didn't catch it until doing cross-browser testing whereby IE barfed on it. – Ted Feb 08 '13 at 01:09
-
@Dave I think instead of "inexplicable", yiinewbie meant to say "frustrating" :) – Jared Beck Nov 11 '14 at 15:26
5 Answers
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:
Enjoy!

- 7,460
- 17
- 52
- 85

- 5,481
- 1
- 22
- 21
-
Great, thanks! For some reason, saving my files in RubyMine doesn't trigger guard to rerun my tests. Any idea why? – alecmce Dec 21 '12 at 23:07
-
1@alecmce You should [add proper Readline support](https://github.com/guard/guard/wiki/Add-proper-Readline-support-to-Ruby-on-Mac-OS-X) to your Ruby installation. – Netzpirat Dec 26 '12 at 14:38
-
@Netzpirat Thanks for that... sadly though, having installed Readline, now neither RubyMine nor the commandline works correctly :-/ I can now only run all tests... – alecmce Jan 02 '13 at 22:03
-
1@alecmce Did you install the proper file system notification library as described in the [efficient filesystem handling](https://github.com/guard/guard#efficient-filesystem-handling) section? – Netzpirat Jan 03 '13 at 12:48
-
@Netzpirat Many thanks. I had screwed up a dependency (and as it happens, was also having an rvm glitch). I'm relatively new to Ruby, this post and your comments has been a huge help. – alecmce Jan 03 '13 at 18:52
-
@Netzpirat Great answer. I'd suggest also checking the "Single Instance Only" box to make sure that only once instance of Guard runs. Otherwise, with database and other side effects things can get very messy. – Sim Oct 27 '13 at 00:23
-
If you also would like to fix the inverted color issue, see: http://stackoverflow.com/questions/16392264/change-rubymine-rspec-color – Dan K.K. Nov 05 '13 at 09:02
-
@alecme correct link to [add proper Readline support](https://github.com/guard/guard/wiki/Add-Readline-support-to-Ruby-on-Mac-OS-X) – max Nov 12 '13 at 13:30
-
2Confirming that this still works with Rubymine 6 and the most current guard gem. Awesome answer. – Amal Chaudhuri Mar 16 '14 at 16:01
-
-
6This still works for RubyMine 7. I just want to add that for those using RBEnv `which guard` will return the path for the shim/wrap/alias that RBEnv uses, you have to inspect your gems folder to find the proper guard script that is actual ruby code. In my case, the (ruby) guard script was in: `~/.rbenv/versions/
/lib/ruby/gems/1.9.1/gems/guard-1.0.3/bin/guard` – damianmr Jan 06 '15 at 19:26 -
2
-
This answer does not seem to work for me, I still get change a single character in my spec file without Guard automatically running, I wish it would just run when I clicked Ctrl+S to save my changes. – David Cruwys Aug 08 '17 at 01:42
-
I'm using simplecov and I also want to see code coverage integrated in rubymine. How do I set up guard and rubymine to continually update what is covered in rubymine? – David West Oct 19 '17 at 21:40
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
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+.rb$})
watch(%r{^config/initializers/.+.rb$})
watch('spec/spec_helper.rb')
watch(%r{app/models/.+\.rb})
watch(%r{app/views/.+\.haml})
watch('Gemfile')
watch('Gemfile.lock')
watch('test/test_helper.rb')
end
# environment is 'ci'
guard :rspec, :cli => '--drb --drb-port 1234', :version => 2, :all_after_pass => false, :notification => true, :environment => 'ci' do
watch(%r{^spec/.+_spec.rb$})
watch(%r{^lib/(.+).rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^spec/.+_spec.rb$})
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|
["spec/routing/#{m[1]}_routing_spec.rb",
"spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
"spec/acceptance/#{m[1]}_spec.rb",
"spec/requests/#{m[1]}_spec.rb"]
end
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" }
end
end
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.

- 12,553
- 12
- 72
- 116
-
I like to use `locate \*/bin/guard` since it's an easy way to display all installations of the binary guard file in your system :) – Steve Benner Nov 18 '13 at 09:20
-
I have no idea why, but this solved a bunch of I/O and sqlite locking exceptions for me. – Joe Essey Sep 01 '14 at 15:44
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:
- 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:
- Assign the External Tool a keyboard shortcut.
- Assign a keyboard shortcut to the Save Document command.
- 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.
- Assign Cmd-S as a keyboard shortcut for your new macro.
My full blog post about this is at http://singlebrook.com/blog/saving-files-in-rubymine

- 1,685
- 2
- 13
- 20
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 ...

- 2,558
- 2
- 17
- 8
I run it as a Gem
command which alto allows me to tap into Bundler at the same time so Guard's version is correct for the project.

- 661
- 8
- 14