class Dockerspec::Engine::Specinfra

The Specinfra (Serverspec) testing engine implementation.

Public Class Methods

new(runner) click to toggle source

Constructs a testing engine to use Specinfra (used by Serverspec).

@param runner [Dockerspec::Runner::Base] The class that is being used

to run the Docker Containers.

@return [Dockerspec::Engine::Specinfra] The engine.

@api public

Calls superclass method Dockerspec::Engine::Base::new
# File lib/dockerspec/engine/specinfra.rb, line 39
def initialize(runner)
  super
  @backend = nil
end

Public Instance Methods

before_running() click to toggle source

Sets the Specinfra configuration.

  • Resets the internal Specinfra backend reference.

  • Sets the chosen container name with Docker Compose.

  • Sets the `:family`.

@return void

@api private

# File lib/dockerspec/engine/specinfra.rb, line 55
def before_running
  if @backend.nil?
    @backend = Backend.new(backend_name)
    @backend.reset
  end
  setup_container_name
  setup_family
end
restore() click to toggle source

Restores the Specinfra backend instance to point to this object's container.

This is used to avoid Serverspec running against the previous started container if you are testing multiple containers at the same time.

@return void

@api private

# File lib/dockerspec/engine/specinfra.rb, line 86
def restore
  @backend.restore
  setup_container_name
  setup_family
end
when_running() click to toggle source

Saves the Specinfra backend reference internally to restore it later.

@return void

@api private

# File lib/dockerspec/engine/specinfra.rb, line 71
def when_running
  @backend.save
end

Protected Instance Methods

backend_name() click to toggle source

Gets the Specinfra backend name from the runner.

@return [String] The backend name.

@api private

# File lib/dockerspec/engine/specinfra.rb, line 101
def backend_name
  @runner.backend_name
end
setup_container_name() click to toggle source

Selects the container to test.

@return void

@api private

# File lib/dockerspec/engine/specinfra.rb, line 124
def setup_container_name
  return unless options.key?(:container)
  @backend.restore_container(options[:container])
end
setup_family() click to toggle source

Sets up the OS family.

@return void

@api private

# File lib/dockerspec/engine/specinfra.rb, line 112
def setup_family
  return unless options.key?(:family)
  ::Specinfra.configuration.os(family: options[:family])
end