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.html
from 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
/coverage
folder on the container after you ran therspec spec
command on it, make sure you have Simplecov started on yourspec/rails_helper
file at the very top of it:Once you have you run
rspec spec
on the container, the/coverage
folder should be created and should automatically be synced to your local project folder, so you can open thecoverage/index.html
file on your browser.In case it's not automatically synced, you can use the
docker compose cp
command to copy it into your local folder:Where:
app
is your container tagapp_root_folder
is yourWORKDIR
from yourDockerfile
./coverage/index.html
is the destination folder on your local machine.Make sure you have the
/coverage
folder created on your local directory before trying to copy it from the container.