Created
December 29, 2011 05:03
-
-
Save febuiles/1532024 to your computer and use it in GitHub Desktop.
Run Rails spec files inside Emacs, looking for fast specs first.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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