Simplecov with docker

330 Views Asked by At

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

1

There are 1 best solutions below

0
On

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 the rspec spec command on it, make sure you have Simplecov started on your spec/rails_helper file at the very top of it:

require 'simplecov'
SimpleCov.start

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 the coverage/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:

docker compose cp app:/app_root_folder/coverage/index.html ./coverage/index.html

Where:

  • app is your container tag
  • app_root_folder is your WORKDIR from your Dockerfile
  • ./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.

mkdir coverage