justanotheruser1019
justanotheruser1019

Reputation: 47

Cannot execute rake rspec unit tests with docker compose

When I execute rake spec against this rake file, docker compose turns up, then it shuts down before the unit tests are executed. If I remove the last command that runs docker-compose down it works fine

How do I modify the script so it can run docker-compose up --detach, then run the unit tests, then run docker-compose down after the unit tests are completed?

I tried adding a sleep and that didn't work as well.

In my Rakefile:

Spec::Core::RakeTask.new(:spec)

# start docker compose.
# we use the system command to wait until docker compose is up and running before starting unit tests
system("docker-compose up --detach")

# run unit tests
task :default => :spec

# stop docker compose
system("docker-compose down")

Upvotes: 0

Views: 150

Answers (1)

Lam Phan
Lam Phan

Reputation: 3811

I think your problem not about docker but about rake. Rake (like make) allows you to add dependencies to a task, and we can use the dependency links to arrange the order of tasks:

task :docker_up do
 system("docker-compose up --detach")
end

task :docker_down do
 system("docker-compose down")
end

task :default => [:docker_up, :spec, :docker_down]

here is the topic you can learn about how to use rake

Upvotes: 0

Related Questions