Last active
March 18, 2020 16:34
-
-
Save masonforest/194e0cb6bb16c88e21a0 to your computer and use it in GitHub Desktop.
Test Drive Your Dockerfiles with RSpec and ServerSpec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:14.04 | |
MAINTAINER Mason Fischer <mason@thoughtbot.com> | |
RUN apt-get update && apt-get install -y nodejs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "serverspec" | |
require "docker" | |
describe "Dockerfile" do | |
image = Docker::Image.build_from_dir('.') | |
set :os, family: :debian | |
set :backend, :docker | |
set :docker_image, image.id | |
it "installs the right version of Ubuntu" do | |
expect(os_version).to include("Ubuntu 14") | |
end | |
it "installs required packages" do | |
expect(package("nodejs")).to be_installed | |
end | |
def os_version | |
command("lsb_release -a").stdout | |
end | |
end |
In the example you build the image only. I assume ServerSpec is starting the container and stopping by the end of the test. How can you pass arguments to the container such as environment variables, commands, volumes, etc?
Hello, this is my version of docker:
$ docker -v
Docker version 1.11.1
I can't using rspec and always getting this message:
$ bundle exec rspec spec
No examples found.
Finished in 0.00098 seconds (files took 1.23 seconds to load)
0 examples, 0 failures
this is my directory structure:
$ tree . ‹ruby-2.3.0›
.
├── Dockerfile
├── run
└── spec
└── Dockerfile_spec.rb
1 directory, 3 files
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tfhartmann : I add this to my specs: