Skip to content

Instantly share code, notes, and snippets.

@vargonaut
Created May 3, 2016 22:35
Show Gist options
  • Select an option

  • Save vargonaut/bff23b4e085ab0ecf5ec38349bdc514e to your computer and use it in GitHub Desktop.

Select an option

Save vargonaut/bff23b4e085ab0ecf5ec38349bdc514e to your computer and use it in GitHub Desktop.
Get RSpec mode working w/ Vagrant
(defun vagrant-rspec-spec-file-for (orig-fun a-file-name)
"Convert file name from local to vagrant"
(apply orig-fun (list (replace-regexp-in-string "^.+/spec" "/vagrant/spec" a-file-name))))
(with-eval-after-load 'rspec-mode
(setq rspec-spec-command "vrspec"
rspec-command-options "--format=progress --no-profile"
rspec-use-bundler-when-possible nil
rspec-use-opts-file-when-available nil)
(advice-add 'rspec-spec-file-for :around #'vagrant-rspec-spec-file-for)

Setup

Install RSpec mode

In emacs, M-x package-install rspec-mode[RET]

Install override code

Add the elisp to your start-up sometime after rspec is loaded. This overrides an interal method of the mode so we can munge the path. Set the options to your liking. I ignore the opts file and bundler to make all this easier on myself.

Install script

In shell, assuming $HOME/bin is in your path:

mv vrspec ~/bin/
chmod +x ~/bin/vrspec

Eval/reload things

Basic Usage

In emacs in a spec file:

C-c , s ; run the spec at point. If on describe/context, will run that set
C-c , v ; run file
C-c , a ; run all specs. Won't work with this setup
C-c , C-h ; see what commands are bound to keys. No warranties expressed or implied.

In result buffer

g ; re-runs
q ; hide buffer
h ; get command list
#!/usr/bin/env bash
# This should be in $PATH and executable
dir=`pwd`
dir=${dir#$HOME/dev/}
vm=${dir%/*}
ssh -t $vm "/bin/bash -l -c 'bin/rspec $*'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment