We recently migrated an app that we have to docker, and docker-compose.
While without docker, we used to run tests using rspec spec for example, while using docker we'd do the same thing using
docker-compose run app rspec spec
Now, in the old scenario, when I wanted a report for test coverage I'd use:
open coverage/index.html
Trying this with docker doesn't work though. Trying docker-compose run app open coverage/index.html doesnt work as well. In fact there is no folder called coverage under my project.
I tried looking online left and right for any examples of simple-cov with docker but can find none. Any hints to how to get this to work would be immensly appreciated.
open
You should open the
coverage/index.htmlfrom your local folder, not from the container folder.When you say "In fact there is no folder called coverage under my project.", are you talking about the container project folder or the local project folder?
If you don't have the
/coveragefolder on the container after you ran therspec speccommand on it, make sure you have Simplecov started on yourspec/rails_helperfile at the very top of it:Once you have you run
rspec specon the container, the/coveragefolder should be created and should automatically be synced to your local project folder, so you can open thecoverage/index.htmlfile on your browser.In case it's not automatically synced, you can use the
docker compose cpcommand to copy it into your local folder:Where:
appis your container tagapp_root_folderis yourWORKDIRfrom yourDockerfile./coverage/index.htmlis the destination folder on your local machine.Make sure you have the
/coveragefolder created on your local directory before trying to copy it from the container.