Skip to content

Latest commit

 

History

History
149 lines (121 loc) · 6.17 KB

README.org

File metadata and controls

149 lines (121 loc) · 6.17 KB

Ruby layer

img/ruby.png

Table of Contents

Description

This layer provides support for the Ruby language with the following feature:

  • version manager (rbenv, rvm or chruby)
  • test runner (ruby-test and rspec)
  • linter (rubocop)
  • interactive REPL and code navigation (robe)

Install

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.

This layer supports two different Ruby modes: Emacs’ built-in Ruby Mode and 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:

(defun dotspacemacs-configuration-layers ()
   '((ruby :variables ruby-enable-enh-ruby-mode t)))

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):

  • 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
  • rubocop is required for rubocop integration

You can install the gems in the context of your current project by adding them to the Gemfile, e.g.:

gem 'pry'

or on the command line (please refer to your ruby version manager specific documentation for details and caveats):

gem install pry

Ruby version management

This layer supports RVM, Rbenv, and Chruby. You can choose the default version manager by setting the variable ruby-version-manager in your dotfile, for example:

(defun dotspacemacs-configuration-layers ()
   '((ruby :variables ruby-version-manager 'rvm)))

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.

Test runner

This layer supports both RSpec and ruby-test test runners (frameworks). By default ruby-test is used, to change to another frameworks set the layer variable ruby-test-runner.

Example to set the test runner to RSpec:

(defun dotspacemacs-configuration-layers ()
   '((ruby :variables ruby-test-runner 'rspec)))

Tip: You can enable different test runners for different projects by using directory local variables.

Key bindings

Ruby (enh-ruby-mode, robe, inf-ruby, ruby-tools)

Key bindingDescription
SPC m 'toggle quotes of current string (only built-in mode)
SPC m {toggle style of current block (only built-in mode)
SPC m g ggo to definition (robe-jump)
SPC m h dgo to Documentation
SPC m s fsend function definition
SPC m s Fsend function definition and switch to REPL
SPC m s istart REPL
SPC m s rsend region
SPC m s Rsend region and switch to REPL
SPC m s sswitch to REPL
SPC m x 'Change symbol or ” string to ’
SPC m x "Change symbol or ’ string to ”
SPC m x :Change string to symbol
%evil-matchit jumps between blocks

RuboCop

Key bindingDescription
SPC m r r fRuns RuboCop on the currently visited file
SPC m r r FRuns auto-correct on the currently visited file
SPC m r r dPrompts from a directory on which to run RuboCop
SPC m r r DPrompts for a directory on which to run auto-correct
SPC m r r pRuns RuboCop on the entire project
SPC m r r PRuns auto-correct on the project

Tests

RSpec-mode

When ruby-test-runner equals rspec.

Key bindingDescription
SPC m t arun all specs
SPC m t brun current spec file
SPC m t crun the current spec file and subsequent ones
SPC m t emark example as pending
SPC m t frun method
SPC m t lrun last failed spec
SPC m t mrun specs related to the current buffer
SPC m t rre-run last spec
SPC m t trun spec at pointer

Ruby-test-mode

When ruby-test-runner equals ruby-test.

Key bindingDescription
SPC m t brun test file
SPC m t trun test at pointer