pezra / rspec-mode

An RSpec minor mode for Emacs
257 stars 112 forks source link

Add `rspec-after-verification-hook` #152

Closed ajvargo closed 6 years ago

ajvargo commented 7 years ago

This hook will be run as the last compilation-finish-function at the end of having run rspec-verify or its variants.

This should handle the use case for #130. It follows the advice of those comments making the generic hook.

dgutov commented 7 years ago

Thanks. Have you tried doing what @ignacy requested using this hook?

ajvargo commented 7 years ago

I didn't do exactly what @ignacy asked for, but I did exercise it with my own setup by using it to put a failure count in the mode line.

(defvar ajv-rspec-cached-fail-count nil)
;; Not sure I need this one. Definitely need the one below for ajv-rspec-mode-line
(put 'ajv-rspec-cached-fail-count 'risky-local-variable t)

(defvar ajv-rspec-mode-line
  '(:eval
    (cond ((null ajv-rspec-cached-fail-count)
           (propertize " RSpec Failures: ?" 'face 'font-lock-comment-face))
          ((> ajv-rspec-cached-fail-count 0)
           (propertize (concat " RSpec Failures: " (int-to-string ajv-rspec-cached-fail-count)) 'face 'font-lock-warning-face))
          (t (propertize " RSpec Failures: -" 'face 'font-lock-constant-face))))
  "Mode line format for RSpec error count.")
(put 'ajv-rspec-mode-line 'risky-local-variable t)

(defun ajv-rspec-update-cached-fail-count ()
  (setq ajv-rspec-cached-fail-count (length rspec-last-failed-specs)))

(add-to-list 'mode-line-misc-info 'ajv-rspec-mode-line 'APPEND)
(add-hook 'rspec-after-verification-hook 'ajv-rspec-update-cached-fail-count)

I'll probably be following this up w/ a PR for before-verification. It'd be nice to clear the value when verification starts. (Or, if you are down w/ it, I can add it to this one.)

dgutov commented 7 years ago

Or, if you are down w/ it, I can add it to this one.

Sure.

ajvargo commented 7 years ago

Added the before hook. Corrected docstring indentation. We'll see if I got it right this time. Oi.

kzkn commented 6 years ago

It seems that the development of this feature has stopped. I want to use this feature. May I take over the development of this feature and make a new PR from my fork?

ajvargo commented 6 years ago

@kzkn Please do. I kept meaning to answer about the last arg being nil and never did. :(

kzkn commented 6 years ago

thanks. I'm gonna do it! :)

ajvargo commented 6 years ago

Closing in favor of #171