Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated documentation.

  • Loading branch information...
commit 7cabc8b3e6a50fd6a0df664236e2407959f8c958 1 parent 4f4e35f
r0man authored

Showing 1 changed file with 53 additions and 47 deletions. Show diff stats Hide diff stats

  1. +53 47 ruby-test-mode.el
100 ruby-test-mode.el
... ... @@ -1,12 +1,13 @@
1   -;;; ruby-test.el --- Test runner for ruby unit tests.
  1 +;;; ruby-test.el --- An Emacs minor mode for Behavioural and Test
  2 +;;; Driven Development in Ruby.
2 3
3   -;; Caspar Florian Ebeling <florian.ebeling@gmail.com>, 2007-12-06
  4 +;; Authors:
  5 +;;
  6 +;; Caspar Florian Ebeling <florian.ebeling@gmail.com>
  7 +;; Roman Scherer <roman.scherer@gmx.de>
  8 +;;
4 9 ;; This software can be redistributed. GPL v2 applies.
5 10
6   -;; todo
7   -
8   -;;; Commentary:
9   -
10 11 ;; This mode provides commands for running ruby tests. The output is
11 12 ;; shown in separate buffer '*Ruby-Test*' in ruby-test
12 13 ;; mode. Backtraces from failures and errors are marked, and can be
@@ -25,7 +26,18 @@
25 26 ;; Using the command `ruby-test-run-test-at-point', you can run test
26 27 ;; cases separately from others in the same file.
27 28
28   -;;; History:
  29 +;; Keybindings:
  30 +;;
  31 +;; C-cr - Runs the current buffer's file as an unit test or an rspec
  32 +;; example.
  33 +;;
  34 +;; C-cp - Runs the unit test or rspec example at the current buffer's
  35 +;; point.
  36 +;;
  37 +;; C-ct - Toggle between implementation and test/example files.
  38 +
  39 +;; History:
  40 +;;
29 41 ;; - 09.02.08, Clickable backtrace added.
30 42 ;; - 02.03.08, Rails support, by Roman Scherer
31 43 ;; - 06.06.08, Bugfixes
@@ -41,12 +53,6 @@
41 53 ;; changes into the project's root directory, so relative
42 54 ;; paths are handled correctly. (Roman Scherer)
43 55
44   -;;; Code:
45   -
46   -;; These key bindings are global, since they should be visible in
47   -;; other windows operating on the file named by variable
48   -;; `ruby-test-last-run'.
49   -
50 56 (defgroup ruby-test nil
51 57 "Minor mode providing commands and helpers for Behavioural and
52 58 Test Driven Development in Ruby."
@@ -141,7 +147,7 @@ non-nil."
141 147 (let ((result nil))
142 148 (dolist (item ls)
143 149 (if (funcall fn item)
144   - (setq result (cons item result))))
  150 + (setq result (cons item result))))
145 151 (reverse result)))
146 152
147 153 (defalias 'find-all 'select)
@@ -174,13 +180,13 @@ current buffer (if that's a test; another open buffer which is a
174 180 test; or the last run test (if there was one)."
175 181 (let ((files))
176 182 (if (buffer-file-name)
177   - (setq files (cons (buffer-file-name) files)))
  183 + (setq files (cons (buffer-file-name) files)))
178 184 (setq files (append
179   - (mapcar
180   - (lambda (win-name) (buffer-file-name (window-buffer win-name)))
181   - (window-list))))
  185 + (mapcar
  186 + (lambda (win-name) (buffer-file-name (window-buffer win-name)))
  187 + (window-list))))
182 188 (if (boundp 'ruby-test-last-run)
183   - (nconc files (list ruby-test-last-run)))
  189 + (nconc files (list ruby-test-last-run)))
184 190 (setq ruby-test-last-run (car (select 'ruby-test-any-p (select 'identity files))))))
185 191
186 192 (defun ruby-test-find-file-hook ()
@@ -207,7 +213,7 @@ second element."
207 213 (goto-line line)
208 214 (message "%s:%s" (current-buffer) (point))
209 215 (if (re-search-backward ruby-test-search-testcase-re nil t)
210   - (match-string 1))))
  216 + (match-string 1))))
211 217
212 218 (defun ruby-test-implementation-filename (&optional filename)
213 219 "Returns the implementation filename for the current buffer's
@@ -243,32 +249,32 @@ as `ruby-test-run-file'"
243 249 (let ((filename (ruby-test-find-file)))
244 250 (let ((test-file-buffer (get-file-buffer filename)))
245 251 (if (and filename
246   - test-file-buffer)
247   - (save-excursion
248   - (set-buffer test-file-buffer)
249   - (let ((line (line-number-at-pos (point))))
  252 + test-file-buffer)
  253 + (save-excursion
  254 + (set-buffer test-file-buffer)
  255 + (let ((line (line-number-at-pos (point))))
250 256 (setq default-directory (or (ruby-test-rails-root filename) (ruby-test-ruby-root filename)))
251 257 (compilation-start (ruby-test-command filename line))))
252   - (message ruby-test-not-found-message)))))
  258 + (message ruby-test-not-found-message)))))
253 259
254 260 (defun ruby-test-command (filename &optional line-number)
255 261 "Return the command to run a unit test or a specification
256 262 depending on the filename."
257 263 (let (command options)
258 264 (cond
259   - ((ruby-test-spec-p filename)
  265 + ((ruby-test-spec-p filename)
260 266 (setq command (or (ruby-test-rspec-executable filename) spec))
261 267 (setq category "spec")
262 268 (if line-number
263   - (setq options (cons "--line" (cons (format "%d" line-number) options)))))
  269 + (setq options (cons "--line" (cons (format "%d" line-number) options)))))
264 270 ((ruby-test-p filename)
265 271 (setq command (or (ruby-test-ruby-executable) "ruby"))
266 272 (setq category "unit test")
267 273 (if line-number
268   - (let ((test-case (ruby-test-find-testcase-at filename line-number)))
269   - (if test-case
270   - (setq options (cons filename (list (format "--name=%s" test-case))))
271   - (error "No test case at %s:%s" filename line-number)))))
  274 + (let ((test-case (ruby-test-find-testcase-at filename line-number)))
  275 + (if test-case
  276 + (setq options (cons filename (list (format "--name=%s" test-case))))
  277 + (error "No test case at %s:%s" filename line-number)))))
272 278 (t (message "File is not a known ruby test file")))
273 279 (format "%s %s %s" command (mapconcat 'identity options " ") filename)))
274 280
@@ -279,21 +285,21 @@ if any of the directories in FILENAME is tested to t by
279 285 evaluating the ROOT-PREDICATE."
280 286 (if (funcall root-predicate filename)
281 287 filename
282   - (and
283   - filename
  288 + (and
  289 + filename
284 290 (not (string= "/" filename))
285   - (ruby-test-project-root
286   - (file-name-directory
  291 + (ruby-test-project-root
  292 + (file-name-directory
287 293 (directory-file-name (file-name-directory filename)))
288 294 root-predicate))))
289   -
  295 +
290 296 (defun ruby-test-project-root-p (directory candidates)
291 297 "Returns t if one of the filenames in CANDIDATES is existing
292 298 relative to the given DIRECTORY, else nil."
293 299 (let ((found nil))
294 300 (while (and (not found) (car candidates))
295   - (setq found
296   - (file-exists-p
  301 + (setq found
  302 + (file-exists-p
297 303 (concat (file-name-as-directory directory) (car candidates))))
298 304 (setq candidates (cdr candidates)))
299 305 found))
@@ -320,20 +326,20 @@ relative, it is assumed to be somewhere in `PATH'."
320 326 (if (not (buffer-file-name (get-buffer test-file)))
321 327 (error "%s" "Cannot find spec relative to non-file buffer"))
322 328 (let ((executables (copy-sequence ruby-test-rspec-executables)))
323   - (if (ruby-test-rails-root test-file)
324   - (add-to-list 'executables (concat (ruby-test-rails-root test-file)
325   - "script/spec")))
326   - (setq executables (mapcar 'ruby-test-expand-executable-path
327   - executables))
  329 + (if (ruby-test-rails-root test-file)
  330 + (add-to-list 'executables (concat (ruby-test-rails-root test-file)
  331 + "script/spec")))
  332 + (setq executables (mapcar 'ruby-test-expand-executable-path
  333 + executables))
328 334 (let ((spec (car (select 'file-readable-p executables))))
329 335 spec)))
330 336
331 337 (defun ruby-test-ruby-executable ()
332 338 "Returns the ruby binary to be used."
333   - (car (select 'file-readable-p
334   - (select 'identity
335   - (mapcar 'ruby-test-expand-executable-path
336   - ruby-test-ruby-executables)))))
  339 + (car (select 'file-readable-p
  340 + (select 'identity
  341 + (mapcar 'ruby-test-expand-executable-path
  342 + ruby-test-ruby-executables)))))
337 343
338 344 (defun ruby-test-ruby-root (filename)
339 345 "Returns the Ruby project directory for the given FILENAME,

0 comments on commit 7cabc8b

Please sign in to comment.
Something went wrong with that request. Please try again.