ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Test​RSpec

by astrauka ST2/ST3

RSpec plugin for Sublime Text 3

Labels ruby, testing, rspec, spec

Details

Installs

  • Total 1K
  • Win 141
  • OS X 990
  • Linux 323
Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5 Sep 4
Windows 2 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 2 1 0 0 1 0 0 0 2 0 1
OS X 2 0 0 1 0 0 1 7 1 3 3 0 0 6 5 4 2 1 3 3 1 0 1 3 4 1 5 5 10 3 7 5 2 1 10 9 3 2 1 2 3 3 4 2 3 1
Linux 1 1 0 0 0 0 1 0 0 0 0 0 0 0 2 1 0 1 0 1 0 0 1 3 0 0 0 0 1 0 1 0 0 0 1 2 0 0 0 0 2 1 0 1 0 2

Readme

Source
raw.​githubusercontent.​com

Sublime TestRSpec

RSpec plugin for Sublime Text 3

Run, navigate and create specs from Sublime editor.

Features

Motivation

I have used RubyTest plugin for some time and was not happy with it.

So I decided to create a simple to understand and develop plugin targeting only rspec.

Installation

With Package Control:

  1. Run “Package Control: Install Package” command, find and install Test Rspec plugin.
  2. Restart SublimeText editor

Manually:

  1. Clone this git repository into your packages folder (in SublimeText, Preferences -> Browse Packages to open this folder)
  2. Restart SublimeText editor

Output

Executed using sublime build tools exec command.

When preconditions are not satisfied outputs to panel.

Configuration

Read this if you want to know how Sublime package settings work.

Find settings in “Preferences -> Package Settings -> TestRSpec”

Default settings

Key bindings

Find bindings in “Preferences -> Package Settings -> TestRSpec”

Default bindings

Features

Run rspec

Executes Sublime command to run rspec. Displays output in panel.

Launch rspec for: * current line * current file * run previous spec

Command generation

# output example
# /home/user/.rbenv/bin/rbenv exec bundle exec spring rspec /home/user/dev/project/spec/models/user_spec.rb:2
#
# ProjectRoot
#   project root by ../spec
#
# SpecTarget
#   file + line
#
# Rspec
#   Environment variables
#     take from configuration
#
#   (BinRspec || RubyRspec) + SpecTarget
#
#   BinRspec
#     find /bin/rspec from project root
#
#   on ./bin/rspec not found
#     RubyRspec : (Rbenv || Rvm || SystemRuby) + Bundle + Spring
#       Rbenv on configuration
#         find $HOME/.rbenv/bin/rbenv exec
#
#       Bundle on configuration
#         check if Gemfile is present
#         bundle exec
#
#       Spring on configuration
#         check if Gemfile contains spring
#         spring

Switch between code and test

Returns all matches by file name.

Prioritizes matches by path as they are more likely the right ones such that in most cases you pick the first match.

Create spec file

Creates spec file when launched in source file.

Uses code snippet defined in settings.

Ignore binding.pry in the spec run

You add binding.pry to the code, then run the rspec and process stucks on pry debugger.

You can disable the debugger modifying the rspec command environment:

"rspec_add_to_path": "DISABLE_PRY=true",

Thanks @werdlerk for the tip!

Troubleshooting

Ruby not found

Example error:

/usr/bin/env: ruby: No such file or directory

Update package settings with path to ruby, for rbenv that's:

"rspec_add_to_path": "$HOME/.rbenv/shims",

Acknowledgments

Inspired by https://github.com/maltize/sublime-text-2-ruby-tests

Parts that are taken: * test console theme * key bindings * idea of how to switch between code and test * idea of how to run spec

Contribution

Help is always welcome. Create an issue if you need help.

Sublime Text plugin development links

Copyright and license

Copyright © 2016 @astrauka

Licensed under the MIT license.