| 1 |
;;; rails-rake.el --- emacs-rails integraions with rake tasks. |
| 2 |
|
| 3 |
;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com> |
| 4 |
|
| 5 |
;; Authors: Dmitry Galinsky <dima dot exe at gmail dot com>, |
| 6 |
;; Peter Rezikov <crazypit13 at gmail dot com> |
| 7 |
;; Keywords: ruby rails languages oop |
| 8 |
;; $URL: svn+ssh://rubyforge/var/svn/emacs-rails/trunk/rails-spec.el $ |
| 9 |
;; $Id: rails-spec.el 117 2007-03-25 23:37:37Z dimaexe $ |
| 10 |
|
| 11 |
;;; License |
| 12 |
|
| 13 |
;; This program is free software; you can redistribute it and/or |
| 14 |
;; modify it under the terms of the GNU General Public License |
| 15 |
;; as published by the Free Software Foundation; either version 2 |
| 16 |
;; of the License, or (at your option) any later version. |
| 17 |
|
| 18 |
;; This program is distributed in the hope that it will be useful, |
| 19 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
;; GNU General Public License for more details. |
| 22 |
|
| 23 |
;; You should have received a copy of the GNU General Public License |
| 24 |
;; along with this program; if not, write to the Free Software |
| 25 |
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 26 |
|
| 27 |
(defvar rails-spec:all-files "spec" |
| 28 |
"All spec files/directories in project") |
| 29 |
|
| 30 |
(defun rails-spec:runner () |
| 31 |
"Command, that run specs." |
| 32 |
(if (file-exists-p (rails-core:file "script/spec")) |
| 33 |
(rails-core:file "script/spec") |
| 34 |
"rspec")) |
| 35 |
|
| 36 |
(defvar rails-spec:last-run nil |
| 37 |
"Spec and arguments of last run.") |
| 38 |
|
| 39 |
(defun rails-spec:run (files &optional options) |
| 40 |
"Rerun previous spec run." |
| 41 |
(setf rails-spec:last-run (cons files options)) |
| 42 |
(rails-script:run (rails-spec:runner) |
| 43 |
(list options files) |
| 44 |
'rails-test:compilation-mode)) |
| 45 |
|
| 46 |
(defun rails-spec:run-current (fail-fast) |
| 47 |
"Run spec for the current controller/model/mailer." |
| 48 |
(interactive "P") |
| 49 |
(let* ((type (rails-core:buffer-type)) |
| 50 |
(spec (cond |
| 51 |
((find type '(:model :mailer :rspec-fixture)) |
| 52 |
(rails-core:rspec-model-file (rails-core:current-model))) |
| 53 |
((find type '(:controller :helper :view)) |
| 54 |
(rails-core:rspec-controller-file (rails-core:current-controller))) |
| 55 |
((find type '(:rspec-model :rspec-controller :rspec-lib)) |
| 56 |
(buffer-file-name)) |
| 57 |
((eql type :lib) |
| 58 |
(rails-core:rspec-lib-file (rails-core:current-lib)))))) |
| 59 |
(if spec |
| 60 |
(let ((options (if fail-fast "--fail-fast" ""))) |
| 61 |
(rails-spec:run spec options)) |
| 62 |
(message "No spec found for %s" (buffer-file-name))))) |
| 63 |
|
| 64 |
(defun rails-spec:run-all (fail-fast) |
| 65 |
"Run spec for all files in project (rails-spec:all-files variable)" |
| 66 |
(interactive "P") |
| 67 |
(let ((options (if fail-fast "--fail-fast" ""))) |
| 68 |
(rails-spec:run (rails-core:file rails-spec:all-files) options))) |
| 69 |
|
| 70 |
(defun rails-spec:run-last () |
| 71 |
"Rerun previous spec run." |
| 72 |
(interactive) |
| 73 |
(when rails-spec:last-run |
| 74 |
(rails-spec:run (car rails-spec:last-run) (cdr rails-spec:last-run)))) |
| 75 |
|
| 76 |
(defun rails-spec:run-this-spec () |
| 77 |
"Run spec where the point is" |
| 78 |
(interactive) |
| 79 |
(rails-spec:run (buffer-file-name) (concat "--line " (substring (what-line) 5)))) |
| 80 |
|
| 81 |
(provide 'rails-spec) |