pezra / rspec-mode

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

Trouble using rspec-mode with docker #192

Open miguelbernadi opened 4 years ago

miguelbernadi commented 4 years ago

I'm trying to run the specs with rspec-mode against docker but it always fails as it tries to run the specs locally (bundler not installed locally). I also can't figure how to get some more verbose output to debug if my config may be wrong.

Setup is as follows:

~/docker-projects/
  |- docker-compose.yml
  |- project_1
    |- Dockerfile
    |- spec/
    |- .dir-locals.el
  |- project-2
    |- Dockerfile
    |- spec/
    |- .dir-locals.el

Each of the projects is a separate git repository and they are put in this order manually (no submodules or anything similar). The projects interdepend, so we have a single docker-compose.yml for all of it.

I'm setting the variables in the dir-locals for each project as recommended in the README.

.dir-locals.el of project_1:

;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")

((rspec-compilation-mode
  (rspec-docker-file-name . Dockerfile)
  (rspec-docker-cwd . /var/lib/app-user/project_1/current)
  (rspec-docker-container . project_1)
  (rspec-use-docker-when-possible . t)))

I'm setting rspec-docker-file-name as it seems to be necessary to detect the docker support (by skimming the code) which is not documented in the README. Also in my case, as the docker-compose.yml is outside the project root I'm overwriting it for the Dockerfile, which is present. I got the warning about unsafe dir-locals and accepted it, so I'm not expecting the error to be there.

Any idea on what may be wrong or how to further debug the issue? Toggling from spec to implementation works and I assume all other features do work as well.

dgutov commented 4 years ago

Dockerfile should be "Dockerfile", it's a string. Same for rspec-docker-container. But you should be getting a more obvious error because of that.

Where does Gemfile reside? Check that (rspec-project-root) returns the correct directory in each case.

miguelbernadi commented 4 years ago

There is a Gemfile for each project next to each Dockerfile. I've updated the strings to use quotes as you mentioned but it still does not work.

I wasn't sure how to run (rspec-project-root) so I did it in a scratch buffer opened in the root of my project. I run:

(rspec-mode)
(rspec-project-root)

and it returned the path to the root of my project (~/docker-projects/project_1/).

pedz commented 4 years ago

Escape colon M-: and then type in the lisp you want to evaluate. Many variables are buffer specific so start while in the buffer where you are doing your work.

On Feb 15, 2020, at 9:32 AM, Miguel Bernabeu Diaz notifications@github.com wrote:

There is a Gemfile for each project next to each Dockerfile. I've updated the strings to use quotes as you mentioned but it still does not work.

I wasn't sure how to run (rspec-project-root) so I did it in a scratch buffer opened in the root of my project. I run:

(rspec-mode) (rspec-project-root) and it returned the path to the root of my project (~/docker-projects/project_1/).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pezra/rspec-mode/issues/192?email_source=notifications&email_token=AAASST3EYY7GKFNPQ3AO42LRDADJRA5CNFSM4KVYNHMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL3PD4Y#issuecomment-586609139, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAASST67ZY2NM43245NVPK3RDADJRANCNFSM4KVYNHMA.

miguelbernadi commented 4 years ago

@pedz Thanks for the tip!

Just run it in the buffer where I was failing to run the specs and it returned the project root properly.

dgutov commented 4 years ago

Then I can recommend edebug-ing rspec--docker-wrapper.

dgutov commented 4 years ago

BTW, you might want to try https://github.com/bibendi/dip. It's a semi-transparent wrapper for docker and docker-compose.

Configuring rspec-mode for use with it is pretty trivial:

(setq rspec-spec-command "dip rspec")
(setq rspec-use-bundler-when-possible nil)

(Or do that in .dir-locals.el).