0.06
There's a lot of open issues
Testcontainers makes it easy to create and clean up container-based dependencies for automated tests.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.0
~> 13.0
~> 1.3
~> 0.9

Runtime

 Project Readme

Testcontainers

Testcontainers is a Ruby library that provides a convenient way to run Docker containers for your tests. It is inspired by the popular Testcontainers library for Java.

This library simplifies the process of managing Docker containers during testing, making it easier to ensure a consistent and isolated environment for each test. It supports a wide range of containers, including databases, message queues, and web servers.

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add testcontainers

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install testcontainers

Usage

To use Testcontainers in your tests, first create and start a container in your test setup. For example, to run a Redis container:

container = Testcontainers::DockerContainer.new("redis:6.2-alpine").with_exposed_port(6379)
container.start

In your tests, you can now access the container's host and mapped port:

host = container.host
port = container.mapped_port(6379)

This allows you to connect to the containerized service and perform your tests. After running your tests, you can stop and delete the container:

container.stop
container.delete

For a more detailed example, please refer to the Quickstart Guide under the docs folder.

Included modules

Tescontainers contains modules that can be used instead of the generic DockerContainer for common databases and services, providing pre-configured setups and reducing the amount of boilerplate code:

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/testcontainers/testcontainers-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Testcontainers project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.