4

While it is easy to run the whole test suite with projectile-rails, this takes too much time. I'd like to be able to run the current test (i.e., the test point is located in) with a shortcut. Is this possible?

itsjeyd
  • 14,586
  • 3
  • 58
  • 87
ckruse
  • 457
  • 3
  • 12

2 Answers2

3

Assuming rspec:

Install rspec-mode, which will activate itself automatically in ruby-mode or enh-ruby-mode then you can use C-c,s to run rspec-verify-single which will run the test at point.

Jordon Biondo
  • 12,332
  • 2
  • 41
  • 62
  • Is there something similiar for `ActionController::TestCase`? – ckruse Dec 05 '14 at 07:57
  • I do not know but writing your own wouldn't be hard, from what I see all you need to do is write code that gets the name of the test at point. then do something like this: `(let ((default-directory (get-project-root-from-projectile))) (compile (format "rake test %s %s" (expand-file-name (buffer-file-name)) (get-your-test-name))))` – Jordon Biondo Dec 06 '14 at 02:46
1

This way it works:

(defun get-current-test-name ()
  (save-excursion
    (let ((pos)
          (test-name))
      (re-search-backward "test \"\\([^\"]+\\)\" do")
      (setq test-name (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
      (concat "test_" (replace-regexp-in-string " " "_" test-name)))))


(defun run-test-at-point ()
  (interactive)
  (let ((root-dir (projectile-project-root)))
    (compile (format "ruby -Ilib:test -I%s/test %s -n %s" root-dir (expand-file-name (buffer-file-name)) (get-current-test-name)))))
ckruse
  • 457
  • 3
  • 12