2015-12-02 14:23:39 +00:00
#+TITLE : Ruby layer
2015-06-10 16:44:30 +00:00
2015-07-04 03:33:13 +00:00
[[file:img/ruby.png ]]
2015-06-10 16:44:30 +00:00
2016-03-31 02:59:55 +00:00
* Table of Contents :TOC_4_gh:noexport:
2017-05-22 14:16:12 +00:00
- [[#description ][Description ]]
2017-08-31 16:25:47 +00:00
- [[#features ][Features: ]]
2017-05-22 14:16:12 +00:00
- [[#install ][Install ]]
- [[#prerequisites ][Prerequisites ]]
- [[#ruby-version-management ][Ruby version management ]]
- [[#test-runner ][Test runner ]]
- [[#key-bindings ][Key bindings ]]
- [[#ruby-enh-ruby-mode-robe-inf-ruby-ruby-tools ][Ruby (enh-ruby-mode, robe, inf-ruby, ruby-tools) ]]
- [[#bundler ][Bundler ]]
- [[#rubocop ][RuboCop ]]
- [[#tests ][Tests ]]
- [[#rspec-mode ][RSpec-mode ]]
- [[#ruby-test-mode ][Ruby-test-mode ]]
- [[#minitest-mode ][minitest-mode ]]
2018-07-09 20:59:05 +00:00
- [[#toggles ][Toggles ]]
2017-05-22 14:16:12 +00:00
- [[#rake ][Rake ]]
2016-10-29 19:58:26 +00:00
- [[#refactor ][Refactor ]]
2017-01-04 23:14:10 +00:00
- [[#layer-options ][Layer options ]]
2015-06-10 16:44:30 +00:00
* Description
2017-08-31 16:25:47 +00:00
This layer provides support for the Ruby programming language.
** Features:
- Version manager (rbenv, rvm or chruby)
- Integration with bundler
- Test runner (ruby-test and rspec)
- Rake runner
- Linter (rubocop)
- Interactive REPL and code navigation (robe)
2015-06-10 16:44:30 +00:00
* Install
2016-01-06 05:21:55 +00:00
To use this configuration layer, add it to your =~/.spacemacs= . You will need to
add =ruby= to the existing =dotspacemacs-configuration-layers= list in this
file.
2015-06-10 16:44:30 +00:00
2015-10-15 20:52:43 +00:00
This layer supports two different Ruby modes: Emacs' built-in Ruby Mode and
2015-10-19 04:10:32 +00:00
[[https://github.com/zenspider/enhanced-ruby-mode ][enh-ruby-mode ]]. By default the built-in Ruby mode is enabled. To switch to the
=enh-ruby-mode= set =ruby-enable-enh-ruby-mode= to t:
2015-10-15 20:52:43 +00:00
#+BEGIN_SRC emacs-lisp
2015-10-19 04:10:32 +00:00
(defun dotspacemacs-configuration-layers ()
'((ruby :variables ruby-enable-enh-ruby-mode t)))
2015-10-15 20:52:43 +00:00
#+END_SRC
2015-06-10 16:44:30 +00:00
** Prerequisites
Some of the advanced features supported by this layer depend on external gems
that need to be installed in the context of your project (see below for guidance
based on your version manager):
2015-06-10 21:16:01 +00:00
- =pry= and =pry-doc= are required for *jump to definition* and *code documentation* (=robe-mode= )
- =ruby_parser= is required for *goto-step_definition* in =feature-mode=
2015-09-08 23:03:42 +00:00
- =rubocop= is required for rubocop integration
2015-06-10 16:44:30 +00:00
You can install the gems in the context of your current project by
adding them to the =Gemfile= , e.g.:
#+BEGIN_SRC ruby
gem 'pry'
#+END_SRC
or on the command line (please refer to your ruby version manager
specific documentation for details and caveats):
#+BEGIN_SRC sh
2015-06-10 21:16:01 +00:00
gem install pry
2015-06-10 16:44:30 +00:00
#+END_SRC
** Ruby version management
2017-04-25 15:42:58 +00:00
This layer supports [[https://rvm.io/ ][RVM ]], [[https://github.com/rbenv/rbenv ][Rbenv ]], and [[https://github.com/postmodern/chruby ][Chruby ]]. You can choose the default version
2015-12-06 01:40:27 +00:00
manager by setting the variable =ruby-version-manager= in your dotfile, for
example:
2015-06-10 16:44:30 +00:00
#+BEGIN_SRC emacs-lisp
2015-11-27 05:25:55 +00:00
(defun dotspacemacs-configuration-layers ()
2015-12-06 01:40:27 +00:00
'((ruby :variables ruby-version-manager 'rvm)))
2015-06-10 16:44:30 +00:00
#+END_SRC
2015-12-06 02:01:03 +00:00
When a version manager is enabled it will use the currently activated ruby
except if a =.ruby-version= file exists in which case the ruby version of
this file is used.
=rvm= will also try to look for a =.rvmrc= and =gemfile= , the priority order is
=.rvmrc= then =.ruby-version= then =gemfile= .
Note: Only one version manager at a time can be enabled.
2015-06-10 16:44:30 +00:00
2015-11-27 05:25:55 +00:00
** Test runner
2016-10-11 19:24:57 +00:00
This layer supports =RSpec= , =ruby-test= and =minitest= test runners
(frameworks). By default =ruby-test= is used, to change to another frameworks
set the layer variable =ruby-test-runner= .
2015-11-27 05:25:55 +00:00
Example to set the test runner to =RSpec= :
2015-11-10 23:42:33 +00:00
#+BEGIN_SRC emacs-lisp
2015-11-27 05:25:55 +00:00
(defun dotspacemacs-configuration-layers ()
'((ruby :variables ruby-test-runner 'rspec)))
2015-11-10 23:42:33 +00:00
#+END_SRC
2015-11-27 05:25:55 +00:00
=Tip:= You can enable different test runners for different projects by using
directory local variables.
2015-06-10 16:44:30 +00:00
* Key bindings
2015-07-29 09:58:47 +00:00
** Ruby (enh-ruby-mode, robe, inf-ruby, ruby-tools)
2015-06-10 16:44:30 +00:00
2015-10-15 20:52:43 +00:00
| Key binding | Description |
|-------------+------------------------------------------------------|
| ~SPC m g g~ | go to definition (robe-jump) |
2017-07-03 16:04:44 +00:00
| ~SPC m h h~ | show documentation for method at point (robe-doc) |
2018-02-09 11:30:50 +00:00
| ~SPC m s b~ | send buffer |
2018-05-28 14:13:54 +00:00
| ~SPC m s B~ | send buffer and switch to REPL |
2015-10-15 20:52:43 +00:00
| ~SPC m s f~ | send function definition |
| ~SPC m s F~ | send function definition and switch to REPL |
| ~SPC m s i~ | start REPL |
2018-05-19 08:37:05 +00:00
| ~SPC m s l~ | send line |
2018-05-28 14:13:54 +00:00
| ~SPC m s L~ | send line and switch to REPL |
2015-10-15 20:52:43 +00:00
| ~SPC m s r~ | send region |
| ~SPC m s R~ | send region and switch to REPL |
| ~SPC m s s~ | switch to REPL |
2016-02-29 09:23:14 +00:00
| ~SPC m x ' ~ | Change symbol or " string to ' |
2016-03-01 17:54:00 +00:00
| ~SPC m x " ~ | Change symbol or ' string to " |
2015-10-15 20:52:43 +00:00
| ~SPC m x :~ | Change string to symbol |
2017-10-18 17:44:05 +00:00
| ~SPC m x h~ | toggle hash syntax in active region |
2015-10-15 20:52:43 +00:00
| ~%~ | [[https://github.com/redguardtoo/evil-matchit][evil-matchit]] jumps between blocks |
2015-06-10 16:44:30 +00:00
2016-02-09 10:34:38 +00:00
** Bundler
| Key binding | Description |
|-------------+--------------------|
2017-03-15 16:19:35 +00:00
| ~SPC m b c~ | run bundle check |
| ~SPC m b i~ | run bundle install |
| ~SPC m b s~ | run bundle console |
| ~SPC m b u~ | run bundle update |
| ~SPC m b x~ | run bundle exec |
| ~SPC m b o~ | run bundle open |
2016-02-09 10:34:38 +00:00
2015-11-27 05:25:55 +00:00
** RuboCop
| Key binding | Description |
|---------------+------------------------------------------------------|
| ~SPC m r r f~ | Runs RuboCop on the currently visited file |
| ~SPC m r r F~ | Runs auto-correct on the currently visited file |
| ~SPC m r r d~ | Prompts from a directory on which to run RuboCop |
| ~SPC m r r D~ | Prompts for a directory on which to run auto-correct |
| ~SPC m r r p~ | Runs RuboCop on the entire project |
| ~SPC m r r P~ | Runs auto-correct on the project |
** Tests
*** RSpec-mode
When =ruby-test-runner= equals =rspec= .
2015-11-10 23:42:33 +00:00
2016-02-07 11:41:32 +00:00
| Key binding | Description |
|---------------+--------------------------------------------------------|
| ~SPC m t a~ | run all specs |
| ~SPC m t b~ | run current spec file |
| ~SPC m t c~ | run the current spec file and subsequent ones |
2016-06-07 02:19:14 +00:00
| ~SPC m t d~ | run tests in a directory |
2016-02-07 11:41:32 +00:00
| ~SPC m t e~ | mark example as pending |
| ~SPC m t f~ | run method |
| ~SPC m t l~ | run last failed spec |
| ~SPC m t m~ | run specs related to the current buffer |
| ~SPC m t r~ | re-run last spec |
| ~SPC m t t~ | run spec at pointer |
| ~SPC m t TAB~ | toggle between spec's and target's buffer |
| ~SPC m t ~~ | toggle between spec's and target's buffer find example |
2015-11-10 23:42:33 +00:00
2015-11-27 05:25:55 +00:00
*** Ruby-test-mode
When =ruby-test-runner= equals =ruby-test= .
2015-06-10 16:44:30 +00:00
| Key binding | Description |
|-------------+---------------------|
| ~SPC m t b~ | run test file |
| ~SPC m t t~ | run test at pointer |
2016-03-01 17:54:00 +00:00
2016-10-11 19:24:57 +00:00
*** minitest-mode
When =ruby-test-runner= equals =minitest= .
| Key binding | Description |
|-------------+---------------------------|
| ~SPC m t a~ | run all tests |
| ~SPC m t b~ | run current file |
| ~SPC m t r~ | repeat last test command |
| ~SPC m t s~ | run test for current file |
2018-07-09 20:59:05 +00:00
** Toggles
2018-07-09 20:59:05 +00:00
| Key binding | Description |
|-------------+------------------------------------------------------|
| ~SPC m T '~ | Toggle quotes of current string (only built-in mode) |
| ~SPC m T {~ | Toggle style of current block (only built-in mode) |
2018-07-09 20:59:05 +00:00
2016-02-29 19:24:52 +00:00
** Rake
| Key binding | Description |
|-------------+---------------------------------|
| ~SPC m k k~ | Runs rake |
| ~SPC m k r~ | Re-runs the last rake task |
| ~SPC m k R~ | Regenerates the rake cache |
| ~SPC m k f~ | Finds definition of a rake task |
2017-01-04 23:14:10 +00:00
2016-10-29 19:58:26 +00:00
** Refactor
| Key binding | Description |
|---------------+------------------------|
| ~SPC m r R m~ | Extract to method |
| ~SPC m r R v~ | Extract local variable |
| ~SPC m r R c~ | Extract constant |
| ~SPC m r R l~ | Extract to let (rspec) |
2017-01-04 23:14:10 +00:00
* Layer options
| Variable | Default value | Description |
|------------------------------------+---------------+----------------------------------------------------------------------------------------------|
| =ruby-enable-enh-ruby-mode= | =nil= | If non-nil, use `enh-ruby-mode' package instead of the built-in Ruby Mode. |
| =ruby-version-manager= | =nil= | If non nil, defines the Ruby version manager.Possible values are `rbenv', `rvm' or `chruby'. |
| =ruby-test-runner= | =ruby-test= | Test runner to use. Possible values are `ruby-test', `minitest' or `rspec'. |
| =ruby-highlight-debugger-keywords= | =t= | If non-nil, enable highlight for debugger keywords. |