RSpec-mode, Magit and Path problems in Emacs

20 Dec 2014

I have been using rspec-mode to run my specs lately. It’s nice to get the spec feedback without having to tab out to a terminal (or running a terminal in emacs). C-c ,m works great, it runs all the specs for the current buffer. More and more, I’ve been seeing the value in Magit-mode. I always loved the ease in which magit lets you choose hunks of files to commit, but I just learned that you can stage arbitrary sections of a hunk! Simply mark (highlight) the section that you want to stage for commit, and then press s in magit-status-mode. So handy!

However, after a computer restart nothing seemed to work correctly. Magit-mode was complaining that it couldn’t find the git executable. I had recently moved Apple’s /usr/bin/git to /usr/bin/git2 so that the system would use Homebrew’s version of git (I upgraded because of a vulnerability found in git clients). Turns out that my PATH variable for emacs was messed up. For future reference, the ‘path’ variable in emacs is called ‘exec-path’. PATH = exec-path. Took me way too long to figure that out. The exec path wasn’t including /usr/local/bin/, the directory that homebrew puts all it’s executables (or at least symlinks them there). The fix for this was as simple as evaluating (push "/usr/local/bin" exec-path) in an elisp scratch buffer. A more permanent fix was to add this to my ‘platform-specific.el’ file in my emacs.d:

1
2
3
4
(if (eq system-type 'darwin)
	...
	;; add homebrew (/usr/local/bin) to the exec path
	(push "/opt/local/bin" exec-path))

The error that I was seeing for rspec-mode was something like your ruby version is 2.0.0 but your gemfile specified 2.1.4. I eventually realized that the command being run in the rspec-compilation buffer was bundle exec rspec spec/path/to/specs/run. Before I had been seeing spring rspec spec/path/to/specs. Simply running spring rails server or any other spring command 1 in a terminal started up spring properly.After that rspec mode seemed to know to use spring to run the rspec commands, which solved the ruby version dependency. This could probably be solved properly via some RVM or RVM.el configuration, but hey, my specs run nicely now!

  1. Spring is a rails application preloader that makes your specs and other rails commands run much faster, and is included in rails 4. github.com/rails/spring