serverspec命令返回空字符串

时间:2015-08-17 20:47:24

标签: ruby rspec docker

我正在尝试使用rspec,serverspec和docker-api gems测试Dockerfile。在大多数情况下,我的测试都在通过,但是使用command方法的所有测试都失败并返回空白字符串,无论我提供什么命令。

代码可以在GitHub找到,但最突出的文件如下:

我的Dockerfile:

# Dockerfile for nginx with configurable persistent volumes

# Select nginx as the base image
FROM nginx

# Mount configurable persistent volumes
VOLUME ["/etc/nginx/sites-enabled", "/etc/nginx/certs", "/etc/nginx/conf.d", "/var/log/nginx", "/var/www/html"]

# Expose both HTTP and HTTPS ports
EXPOSE 80 443

# ENTRYPOINT
ENTRYPOINT ["service", "nginx", "start"]

的Gemfile:

source 'https://rubygems.org'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

group :development, :test do
  gem 'specinfra',  '~> 2.12.7'
  gem 'serverspec', '~> 2.8.2'
  gem 'docker-api', '~> 1.21.4'
  gem 'rspec',      '~> 3.2.0'
end

规格:

require 'serverspec'
require 'docker'

Excon.defaults[:ssl_verify_peer] = false

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 Debian' do
    expect(os_version).to include('Debian GNU/Linux 7')
  end

  describe package('nginx') do
    it { should be_installed }
  end

  describe service('nginx') do
    it { should be_enabled }
    it { should be_running }
  end

  describe command('nginx -V') do
    its(:stdout) { should include('http_ssl_module') }
    its(:stdout) { should include('http_gzip_static_module') }
  end

  describe port(80) do
    it { should be_listening }
  end

  describe port(443) do
    it { should be_listening }
  end

  def os_version
    command('lsb_release -a').stdout
  end
end

我知道我正在使用旧版本的宝石,但我无法使用最新版本。如果它与OS X有任何关联,那么使用boot2docker。我从运行我的规范得到的结果是:

Failures:

  1) Dockerfile installs the right version of Debian
     Failure/Error: expect(os_version).to include('Debian GNU/Linux 7')
       expected "" to include "Debian GNU/Linux 7"

     # ./spec/dockerfile_spec.rb:16:in `block (2 levels) in <top (required)>'

  2) Dockerfile Command "nginx -V" stdout should include "http_ssl_module"
     Failure/Error: its(:stdout) { should include('http_ssl_module') }
       expected "" to include "http_ssl_module"

     # ./spec/dockerfile_spec.rb:29:in `block (3 levels) in <top (required)>'

  3) Dockerfile Command "nginx -V" stdout should include "http_gzip_static_module"
     Failure/Error: its(:stdout) { should include('http_gzip_static_module') }
       expected "" to include "http_gzip_static_module"

     # ./spec/dockerfile_spec.rb:30:in `block (3 levels) in <top (required)>'

0 个答案:

没有答案