Skip to content

Instantly share code, notes, and snippets.

@gnufied
Created December 6, 2012 09:14
Show Gist options
  • Save gnufied/4223167 to your computer and use it in GitHub Desktop.
Save gnufied/4223167 to your computer and use it in GitHub Desktop.
compile_rspec.el
(require 'cl) ; If you don't have it already
(defun* get-closest-gemfile-root (&optional (file "Gemfile"))
"Determine the pathname of the first instance of FILE starting from the current directory towards root.
This may not do the correct thing in presence of links. If it does not find FILE, then it shall return the name
of FILE in the current directory, suitable for creation"
(let ((root (expand-file-name "/"))) ; the win32 builds should translate this correctly
(loop
for d = default-directory then (expand-file-name ".." d)
if (file-exists-p (expand-file-name file d))
return d
if (equal d root)
return nil)))
(require 'compile)
(defun rspec-compile-file ()
(interactive)
(compile (format "cd %s;bundle exec rspec %s"
(get-closest-gemfile-root)
(file-relative-name (buffer-file-name) (get-closest-gemfile-root))
)))
(defun rspec-compile-on-line ()
(interactive)
(compile (format "cd %s;bundle exec rspec %s -l %s"
(get-closest-gemfile-root)
(file-relative-name (buffer-file-name) (get-closest-gemfile-root))
(line-number-at-pos)
)))
(add-hook 'ruby-mode-hook
(lambda ()
(local-set-key (kbd "C-c l") 'rspec-compile-on-line)
(local-set-key (kbd "C-c k") 'rspec-compile-file)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment