0

I want to run my rails rspec test on docker. If I open Cli via docker desktop and write

-bundle exec rspec spec

my tests run. What I want is, to run my tests with a command in makefile which up my image and run this command

2 Answers 2

1

I was able to run tests with the code

docker-compose run ${IMAGE_NAME} bundle exec rspec spec

Sign up to request clarification or add additional context in comments.

Comments

0

I generally run unit tests on the host before I build Docker containers. I do not include tests inside the image.

gem install bundler:2.2.26
bundle exec rspec
docker build -t myapp:20210824
docker run -d -p 8000:8000 myapp:20210824

In a Makefile context, I'd have these as separate steps, but I would not have these hard depend on each other.

.PHONY: rspec docker-build docker-run
all: rspec docker-build
run: rspec docker-run
DOCKER_TAG := latest

.bundled: Gemfile Gemfile.lock
        bundle install
        touch "$@"

rspec: .bundled
        bundle exec rspec

docker-build: .docker-build
.docker-build:
        docker build -t myapp:$(DOCKER_TAG) .
        touch "$@"

docker-run: .docker-build
        docker run -p 8000:8000 myapp:$(DOCKER_TAG)

clean:
        rm -f .bundled .docker-build

Note that this path does not require docker exec or a running container, and you can safely include the spec directory in a .dockerignore file to omit it from the image.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.