class Dockerspec::RSpec::Resources::ItsContainer

This generates the object to use within `its_container` calls.

Constants

NO_DOCKER_COMPOSE_MESSAGE

A message with description on how to avoid the error when you forget specifying the docker container you want to test with Docker Compose.

Public Class Methods

new(container_name, compose) click to toggle source

Constructs a `its_container` object.

@param container_name [String] The name of the container. @param compose [Dockerspec::Runner::Compose] The compose object we

working with.

@return [Dockerspec::RSpec::Resource::ItsContainer] The

`its_container` object.

@api public

# File lib/dockerspec/rspec/resources/its_container.rb, line 65
def initialize(container_name, compose)
  @container_name = container_name
  @compose = compose
end

Public Instance Methods

container() click to toggle source

Gets the selected container object.

This method is used in {Dockerspec::Runner::ConfigHelpers} to get information from the selected container.

@return [Docker::Container] The container object.

@raise [Dockerspec::RunnerError] When cannot select the container to

test.

@api public

# File lib/dockerspec/rspec/resources/its_container.rb, line 113
def container
  @compose.container
end
restore_rspec_context(opts = nil) click to toggle source

Restores the testing context.

This is required for tests to run correctly if we are testing different containers within the same tests. That is because RSpec has two stages, one in which it generates the tests and another in which it runs them.

This is called from the `before` block in the lib/dockerspec/runner/base.rb file:

“`ruby RSpec.configure do |c|

c.before(:each) do
  metadata = RSpec.current_example.metadata
  Dockerspec::Helper::RSpecExampleHelpers
    .restore_rspec_context(metadata)
end

end “`

@return void

@api public

# File lib/dockerspec/rspec/resources/its_container.rb, line 95
def restore_rspec_context(opts = nil)
  @compose.select_container(@container_name, opts)
  @compose.restore_rspec_context
end
to_s() click to toggle source

Gets the description for the `its_container` resource.

@return [String] The description.

@api public

# File lib/dockerspec/rspec/resources/its_container.rb, line 124
def to_s
  "\"#{@container_name}\" container"
end