Skip to content

Instantly share code, notes, and snippets.

@febuiles
Created December 29, 2011 05:03
Show Gist options
  • Save febuiles/1532024 to your computer and use it in GitHub Desktop.
Save febuiles/1532024 to your computer and use it in GitHub Desktop.
Run Rails spec files inside Emacs, looking for fast specs first.
(defun fast-spec-file(file)
(gsub (gsub file "app/" "spec/fast/") ".rb" "_spec.rb"))
(defun run-spec()
"Runs the specs for the buffer where this is called.
The spec lookup works like this:
1. For foo.rb it'll look for spec/fast/[models|controllers|...]/foo_spec.rb
2. If (1) fails it will run `rspec-verify`."
(interactive)
(let* ((file-name (buffer-file-name))
(fast-spec (fast-spec-file file-name)))
(if
(file-exists-p fast-spec) (rspec-run-single-file fast-spec)
(rspec-verify))))
(defun gsub (string search-string replace &optional regexp-flag)
"Replaces the occurences of `search-string` in `string` with `replace`."
(with-temp-buffer
(insert string)
(goto-char (point-min))
(let ((search-function (if regexp-flag 're-search-forward 'search-forward)))
(while (funcall search-function search-string nil t)
(replace-match replace))
(buffer-string))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment