1
我想寫一個Ubuntu 16.04泊塢窗圖像的基本測試。 我的測試環境的Ubuntu 16.04還和我已經安裝了ruby-serverspec
包。Dockerfile測試要求的指令無法找到正確的模塊
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
類模塊。 搜索路徑對我來說仍然是一門黑色藝術。我如何才能使這個測試失敗,如預期的那樣?
您沒有實際使用serverspec在所有的代碼。你可能應該刪除它。但是,您使用specinfra作爲docker後端。 –