Class: Dockerspec::RSpec::Resources::ItsContainer
- Inherits:
-
Object
- Object
- Dockerspec::RSpec::Resources::ItsContainer
- 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
-
#container ⇒ Docker::Container
Gets the selected container object.
-
#initialize(container_name, compose) ⇒ Dockerspec::RSpec::Resource::ItsContainer
constructor
Constructs a
its_containerobject. -
#restore_rspec_context(opts = nil) ⇒ Object
Restores the testing context.
-
#to_s ⇒ String
Gets the description for the
its_containerresource.
Methods included from Dockerspec::Runner::ConfigHelpers
Constructor Details
#initialize(container_name, compose) ⇒ Dockerspec::RSpec::Resource::ItsContainer
Constructs a its_container object.
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
#container ⇒ Docker::Container
Gets the selected container object.
This method is used in Dockerspec::Runner::ConfigHelpers to get information from the selected container.
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
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_s ⇒ String
Gets the description for the its_container resource.
124 125 126 |
# File 'lib/dockerspec/rspec/resources/its_container.rb', line 124 def to_s "\"#{@container_name}\" container" end |