Skip to content

abstract struct Athena::DependencyInjection::Spec::ContainerTestCase
inherits Athena::Spec::TestCase #

Base ASPEC::TestCase for tests that use the service container, such as integration tests of services.

Each test has its own ADI::Spec::MockableServiceContainer, see #container. Once the test is done, its ACTR::Service::Closeable services are closed, as they would be once a unit of work, such as a request, is done.

@[ADI::Register(public: true)]
class GreetingService
  def greet(name : String) : String
    "Hello #{name}!"
  end
end

struct GreetingServiceTest < ADI::Spec::ContainerTestCase
  def test_greet : Nil
    self.container.greeting_service.greet("George").should eq "Hello George!"
  end
end

Tip

See ADI::Spec::MockableServiceContainer for how to replace services within the container.

Note

A test case that overrides #tear_down must call super, which closes the services.

Constructors#

Methods#

#container : ADI::Spec::MockableServiceContainer#

Returns the service container of the current test.

View source

#tear_down : Nil#

Closes the ACTR::Service::Closeable services of the current test.

View source