Class: Dockerspec::RSpec::Resources::ItsContainer

Inherits:
Object
  • Object
show all
Includes:
Dockerspec::Runner::ConfigHelpers
Defined in:
lib/dockerspec/rspec/resources/its_container.rb

Overview

This generates the object to use within its_container calls.

Constant Summary collapse

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.

<<-EOE
.freeze

Instance Method Summary collapse

Methods included from Dockerspec::Runner::ConfigHelpers

#parse_log, #stderr, #stdout

Constructor Details

#initialize(container_name, compose) ⇒ Dockerspec::RSpec::Resource::ItsContainer

Constructs a its_container object.

Parameters:



65
66
67
68
# File 'lib/dockerspec/rspec/resources/its_container.rb', line 65

def initialize(container_name, compose)
  @container_name = container_name
  @compose = compose
end

Instance Method Details

#containerDocker::Container

Gets the selected container object.

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

Returns:

  • (Docker::Container)

    The container object.

Raises:



113
114
115
# File 'lib/dockerspec/rspec/resources/its_container.rb', line 113

def container
  @compose.container
end

#restore_rspec_context(opts = nil) ⇒ Object

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:

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

Returns:

  • void



95
96
97
98
# 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_sString

Gets the description for the its_container resource.

Returns:

  • (String)

    The description.



124
125
126
# File 'lib/dockerspec/rspec/resources/its_container.rb', line 124

def to_s
  "\"#{@container_name}\" container"
end