我正在尝试编写 Ubuntu 16.04 docker 映像的基本测试。我的测试环境也是 Ubuntu 16.04,我已经安装了这个ruby-serverspec
包。
require "serverspec"
require "docker_image"
describe "Dockerfile" do
before(:all) do
image = Docker::Image.build_from_dir('..')
set :os, family: :debian
set :backend, :docker
set :docker_image, image.id
end
it "installs the right version of Ubuntu" do
expect(os_version).to include("Ubuntu 14")
end
def os_version
command("lsb_release -a").stdout
end
end
目前这是一个故意失败的测试,因为它检查 Ubuntu 14,但它甚至没有达到失败。
$ rspec /test/spec/localhost/my_spec.rb
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- docker_image (LoadError)
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /test/spec/localhost/my_spec.rb:4:in `<top (required)>'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1361:in `load'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1361:in `block in load_spec_files'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1359:in `each'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1359:in `load_spec_files'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:106:in `setup'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:92:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:78:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:45:in `invoke'
from /usr/bin/rspec:4:in `<main>'
我不知道如何Docker::Image
正确地要求类模块。搜索路径对我来说仍然是一门魔法。我怎样才能让这个测试按预期失败?