Module: Dockerspec::RSpec::Resources
- Defined in:
- lib/dockerspec/rspec/resources.rb,
lib/dockerspec/rspec/resources/its_container.rb
Overview
Some resources included inside RSpec::Core::ExampleGroup to build and run Docker containers.
Load the Test Engine You Want to Use
If you want to run Serverspec tests, you need
to require the dockerspec/serverspec
path:
require 'dockerspec/serverspec'
If you want to run Infrataster
tests, you need to require the dockerspec/infrataster
path:
require 'dockerspec/infrataster'
Of course, you can load both engines:
require 'dockerspec/serverspec'
require 'dockerspec/infrataster'
RSpec Settings
dockerfile_path
: The dockerfile path.rm_build
: Whether to remove the build after the run.log_level
: Log level to use by default.docker_wait
: Seconds to wait before running the tests.container_name
: Docker container to test with Docker Compose.
All the RSpec settings are optional.
Defined Under Namespace
Classes: ItsContainer
Instance Method Summary collapse
-
#described_container(value = nil) ⇒ Symbol
Sets or gets the latest run container name.
-
#described_image(value = nil) ⇒ String
Sets or gets the latest run container name.
-
#docker_build(*opts) ⇒ Dockerspec::Builder
Builds a Docker image.
-
#docker_compose(*opts) ⇒ Dockerspec::Runner::Compose
Runs Docker Compose.
-
#docker_run(*opts) ⇒ Dockerspec::Runner::Docker
Runs a docker image.
-
#its_container(container, *opts, &block) ⇒ Dockerspec::Runner::Compose
Selects the container to test inside #docker_compose.
Instance Method Details
#described_container(value = nil) ⇒ Symbol
Sets or gets the latest run container name.
Used to call the Infrataster #server method.
581 582 583 584 585 586 |
# File 'lib/dockerspec/rspec/resources.rb', line 581 def described_container(value = nil) # rubocop:disable Style/ClassVars @@described_container = value unless value.nil? # rubocop:enable Style/ClassVars @@described_container.to_sym end |
#described_image(value = nil) ⇒ String
Sets or gets the latest run container name.
This can be used to avoid adding a tag to the build image.
539 540 541 542 543 544 |
# File 'lib/dockerspec/rspec/resources.rb', line 539 def described_image(value = nil) # rubocop:disable Style/ClassVars @@described_image = value unless value.nil? # rubocop:enable Style/ClassVars @@described_image end |
#docker_build(*opts) ⇒ Dockerspec::Builder
Builds a Docker image.
The image can be build from a path or from a string.
See the Builder::ConfigHelpers documentation for more information about the available RSpec resource helpers.
207 208 209 210 211 212 |
# File 'lib/dockerspec/rspec/resources.rb', line 207 def docker_build(*opts) builder = Dockerspec::Builder.new(*opts) builder.build described_image(builder.id) builder end |
#docker_compose(*opts) ⇒ Dockerspec::Runner::Compose
Runs Docker Compose.
By default tries to detect the most appropriate Docker backend: native or LXC.
433 434 435 436 |
# File 'lib/dockerspec/rspec/resources.rb', line 433 def docker_compose(*opts) runner = Dockerspec::Configuration.compose_runner.new(*opts) runner.run end |
#docker_run(*opts) ⇒ Dockerspec::Runner::Docker
Runs a docker image.
See the Serverspec Resource Types documentation to see the available resources.
By default tries to detect the most appropriate Docker backend: native or LXC.
356 357 358 359 360 361 |
# File 'lib/dockerspec/rspec/resources.rb', line 356 def docker_run(*opts) runner = Dockerspec::Configuration.docker_runner.new(*opts) runner.run described_container(runner.container_name) runner end |
#its_container(container, *opts, &block) ⇒ Dockerspec::Runner::Compose
Selects the container to test inside #docker_compose.
510 511 512 513 514 515 516 517 518 519 |
# File 'lib/dockerspec/rspec/resources.rb', line 510 def its_container(container, *opts, &block) compose = Runner::Compose.current_instance if compose.nil? raise ItsContainerError, ItsContainer::NO_DOCKER_COMPOSE_MESSAGE end container_opts = opts[0].is_a?(Hash) ? opts[0] : {} compose.select_container(container, container_opts) described_container(compose.container_name) describe(ItsContainer.new(container), *opts, &block) end |