zuazo / dockerspec

A small Ruby Gem to run RSpec and Serverspec, Infrataster and Capybara tests against Dockerfiles or Docker images easily.
https://rubygems.org/gems/dockerspec
Apache License 2.0
182 stars 9 forks source link

docker_compose doesn't shutdown container after describe end #8

Open estahn opened 7 years ago

estahn commented 7 years ago

Dockerspec Version

0.4.1

Ruby Version

2.4

Platform Details

Mac

Scenario

Run docker_compose from the same file in 2 different specs.

test1_spec -> docker_compose(default.yml)
test2_spec -> docker_compose(default.yml)

Steps to Reproduce

Expected Result

After describe docker_compose() do ... end the containers should shutdown.

Actual Result

Containers stay active until rspec is finished.

Possible Solution

In order to maintain backwards compatibility it might be worth to introduce a new flag shutdown for the docker_compose method.

zuazo commented 7 years ago

@estahn unfortunately, I do not think this can be fixed due to the way rspec and serverspec work.

Right now all the containers are started, then the tests are passed, and then they all stop in a third stage. I tried to change this some time ago, but it seemed impossible.

In addition to that, and even if it were possible, this would imply that you could not execute things like os[:family] out of it / before blocks. And sometimes that's the case, as commented in #2.

estahn commented 7 years ago

It appears rspec doesn't have an isolation feature similar to phpunit. I'm running it now manually in "isolation" :)

find spec -name "*_spec.rb" | xargs -I% -n1 /bin/bash -c 'MY_VAR=123 bundle exec rspec %'
zuazo commented 7 years ago

Yes, that's a good solution.

Maybe it could be possible to implement some kind of special resource, something like a docker_context do ... end to isolate the different executions of rspec&docker. I wrote it down in the TODO list. I researched how to do it some time ago, but I could not figure out how. I'm not saying it's impossible, but it does not seem like a simple task.

estahn commented 7 years ago

I tried experimenting with describe ... context but this didn't seem to work. It would be great to avoid introducing a new thing.

zuazo commented 7 years ago

With the original describe is not possible to do that. However, it does not seem possible to do it the other way either without changing the internal behavior of RSpec.