Skip to content

Instantly share code, notes, and snippets.

@ajvargo
Created November 22, 2019 17:38
Show Gist options
  • Save ajvargo/0e0e119029cd6e2c2716702e77ef03b1 to your computer and use it in GitHub Desktop.
Save ajvargo/0e0e119029cd6e2c2716702e77ef03b1 to your computer and use it in GitHub Desktop.
Setup rspec mode so it works with nix and direnv (in emacs)
;;; 0 - install `direnv' on your machine and active it for lello
;;; `cd lello && direnv allow'
;;; 1 - Install `rspec-mode' and configure
;; allows the test finder to not choke on `lib' stuff
(setq rspec-primary-source-dirs '("app"))
;; if you want to run specs from dired
(add-hook 'dired-mode-hook 'rspec-dired-mode)
;; rspec-mode doesn't pick up `.rspec-local' yet so just add what you want to use here.
;; If you don't, it'll just grab `.rspec'
(setq rspec-command-options "--format progress")
(setq rspec-use-opts-file-when-available nil)
;;; 2 - Install and configure `direnv'
;; turn it on
(direnv-mode)
;; tell it about rspec
(add-to-list 'direnv-non-file-modes 'rspec-compilation-mode)
;; when you get tired of the massive messages in minibuffer
(setq direnv-always-show-summary nil)
(setq direnv-show-paths-in-summary nil)
;;; 3 - Advanced tweaks
;; I wanted to get rid of a lot of the spec noise b/c of deprecation
;; warnings and other stuff. The rspec run is async, so you get text
;; back in chunks, so cleaning it was it goes sometimes leaves
;; strangely truncated lines.
;;
;; As such, I wait until the test run is complete, and then remove
;; noise. Its a bit strange, but works for now. It is a nice visual
;; indicator tests are done.
(defun filter-rspec-static (buffer _desc)
(with-current-buffer buffer
(if (eq major-mode 'rspec-compilation-mode)
(flush-lines "Passing 'script'\\|DEPRECATION WARNING\\|To enable\\|not currently running\\|This is a default setting to speed\\|Both Author and its :state machine have defined" (point-min) (point-max)))))
(add-to-list 'compilation-finish-functions 'filter-rspec-static2)
;;;;; SETUP ABOVE w/ use-package
;;; This is the minimal to get things working
(use-package rspec-mode
:after ruby-mode
:ensure t
:config
(setq rspec-primary-source-dirs '("app")))
(use-package direnv
:ensure t
:config
(add-to-list 'direnv-non-file-modes 'rspec-compilation-mode)
(direnv-mode))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment