pezra / rspec-mode

An RSpec minor mode for Emacs
257 stars 112 forks source link

Support using a relative path #177

Closed terlar closed 5 years ago

terlar commented 6 years ago

Sometimes it is not feasible to use the full path, either when using bin-stub wrappers going to docker images and other cases. This provides an option to opt-out from the absolute paths.

My current use case is bin-stubs that take care of executing the tests within docker through docker exec to achieve faster speeds. I guess one option would be to set rspec-docker-cwd and rspec-docker-command but it is nice to have something that works everywhere without special config.

dgutov commented 6 years ago

Okay then.

Now, is this variable supposed to be mutually exclusive with the use of docker or vagrant?

terlar commented 6 years ago

I guess so, or there could perhaps be a case where someone wants to run with a relative path inside Docker and Vagrant. I haven't looked into how the command for those are constructed, but if it is just a simple command + path I guess there is a case where you could rely on the workdir inside the container/vagrant and then use a relative path.

jscheid commented 5 years ago

Hi, this change would also be useful to me (I'm running in Vagrant but through a custom script that does things like setting up RVM correctly, so can't use the normal Vagrant support). This change looks good to me and looks almost exactly like the one I made in my local tree as a workaround. Would be great if it could be merged :-) Thanks for a really useful package!

dgutov commented 5 years ago

@jscheid So have you tried this exact code?

I was wondering whether the code paths could be united, like if rspec is run from the project-root directory within both vagrant and docker environments, they could just use relative paths as well. The use case for absolute paths is less clear to me overall.

jscheid commented 5 years ago

I haven't run this branch but my workaround looks pretty much the same, except it's not configurable:

(defun rspec--shell-quote-local (file)
  (let ((remote (file-remote-p file))
        (docker (rspec-docker-p))
        (vagrant (rspec-vagrant-p)))
    (shell-quote-argument
     (cond
      (remote (substring file (length remote)))
      (docker (replace-regexp-in-string (regexp-quote (rspec-project-root))
                                         rspec-docker-cwd file))
      (vagrant (replace-regexp-in-string (regexp-quote (rspec-project-root))
                                         rspec-vagrant-cwd file))
      (t
       (file-relative-name file (rspec-project-root)))))))

I agree with you that relative paths could be hardwired to replace absolute paths like in my workaround, I don't recall ever using absolute paths with rspec.

dgutov commented 5 years ago

OK, thank you.

I'll merge this now, hopefully someone will have time to look into just using relative paths later.