textmate / ruby.tmbundle

TextMate support for Ruby
178 stars 91 forks source link

Provide API for running Ruby executables like rspec, rubocop etc. #102

Closed noniq closed 7 years ago

noniq commented 8 years ago

This is a feature request. I’ll be happy to provide a PR for this, but I want to discuss the feature in advance to see if it makes sense.

Running Ruby executables like rspec or rubocop turns out to be rather complicated nowadays: You need to support binstubs, Gemfiles and bundle exec, maybe RVM or rbenv, …

Currently, various bundles implement something along this lines on their own, reinventing the wheel again and again. See the discussion in #99 for an example. Other bundles that come to my mind are (and I wouldn’t be surprised if there are more):

I think this functionality – “reliably run a Ruby executable” – should be provided by the Ruby bundle as a public API to be used by other bundles (note that it’s possible for bundles to require other bundles).

Before implementing this I want to discuss two questions:

Here’s my suggestion on how to implement the feature:

  1. Look for a binstub (e.g. bin/rubocop, bin/rspec, …) and use it, if present. (This is especially important for projects using preloaders like Spring.)
  2. Check if a Gemfile (or a Gemfile.lock?) exists and contains an entry for the executable’s gem. If so, run the executable with bundle exec …
  3. Assume that the executable is installed globally and in the search path, so just run it via it’s name (with the project directory as working dir, to make sure rbenv is happy). If the corresponding environment variable (TM_RUBOCOP, TM_RSPEC, …) is set, use this as name instead.

Comments and feedback welcome! (Especially from RVM users as this is something I don’t use myself. Do we need any special steps to make this work smoothly with RVM?)

noniq commented 7 years ago

Closed via #104