Git Product home page Git Product logo

testrspec's Introduction

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-commands-rspec
#         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 when running specs

Sublime does not allow input in the output panel, so if you add binding.pry, tests get stuck waiting on input.

To work around this, you can disable the debugger by modifying TestRSpec configuration:

  "env": {
    "DISABLE_PRY": "true"
  },

Alternatively, use pry-remote.

Hide inline errors

By default inline error messages will be displayed whenever a spec fails. To disable them set show_errors_inline global setting to false.

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",

Spring is not used

Make sure you have both spring and spring-commands-rspec in your Gemfile.

If you use binstubs, you also need to run

bundle exec spring binstub rspec

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.

testrspec's People

Contributors

astrauka avatar olegsmelov avatar pawurb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.