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) ⇒ String
Runs Docker Compose.
-
#docker_run(*opts) ⇒ Dockerspec::Runner::Docker
Runs a docker image.
-
#its_container(container, *opts) { ... } ⇒ Object
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.
589 590 591 592 593 594 |
# File 'lib/dockerspec/rspec/resources.rb', line 589 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.
547 548 549 550 551 552 |
# File 'lib/dockerspec/rspec/resources.rb', line 547 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) ⇒ String
Runs Docker Compose.
By default tries to detect the most appropriate Docker backend: native or LXC.
434 435 436 437 438 439 440 441 |
# File 'lib/dockerspec/rspec/resources.rb', line 434 def docker_compose(*opts) runner = Dockerspec::Configuration.compose_runner.new(*opts) runner.run # Disable storing Runner object on RSpec metadata, to avoid calling its # {Runner#restore_rspec_context} method that it is also called in # {ItsContainer#restore_rspec_context}: runner.to_s 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 362 |
# File 'lib/dockerspec/rspec/resources.rb', line 356 def docker_run(*opts) runner = Dockerspec::Configuration.docker_runner.new(*opts) runner.run runner.restore_rspec_context described_container(runner.container_name) runner end |
#its_container(container, *opts) { ... } ⇒ Object
Selects the container to test inside #docker_compose.
517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/dockerspec/rspec/resources.rb', line 517 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] : {} its_container = ItsContainer.new(container, compose) its_container.restore_rspec_context(container_opts) described_container(compose.container_name) describe(its_container, *opts, &block) end |