LoginSignup
11

More than 5 years have passed since last update.

Emacs内からrspecテストをiTerm上で走らせる設定

Posted at

specを編集→行指定でrspecコマンド実行,というサイクルが多いので,Emacsからキーバインド一発で実行できるようにした.
出力結果はiTermで見たいので,Emacs内でrspecコマンドを実行するのではなくapplescriptを使ってiTermにコマンドを書き出させるようにしている.

ruby-config.el
(defun execute-rspec ()
  (interactive)
  (do-applescript (format "tell application \"iTerm\"
  activate
  tell current session of current terminal
    write text \"bundle exec rspec %s:%s\"
  end tell
  end tell
  tell application \"System Events\"
    keystroke return
  end tell"
  buffer-file-name (line-number-at-pos))))

(define-key ruby-mode-map (kbd "C-c r") 'execute-rspec)

実行するとbundle exec /path/to/some_spec.rb:10のようなコマンドがiTerm上で実行される

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11