免责声明:ruby和rspec非常新
我一直在尝试使用docker镜像作为我们不同项目的基础镜像构建私有仓库。我们还尝试将测试多个docker映像作为测试套件的一部分。
尽管我们有奇怪的问题rspec,但似乎测试在错误的docker计算机上运行。
当前,我们在单独的文件夹中有两个docker映像
.
??? Dockerfile
??? Gemfile
??? Gemfile.lock
??? Jenkinsfile
??? README.md
??? Rakefile
??? nodejs
? ??? 7.0
? ? ??? Dockerfile
? ? ??? README.md
? ? ??? spec
? ? ??? image_spec.rb
? ??? README.md
??? python
? ??? 2.7
? ? ??? Dockerfile
? ? ??? README.md
? ? ??? docker-entrypoint.sh
? ? ??? requirements.txt
? ? ??? spec
? ? ??? image_spec.rb
? ??? README.md
??? spec
??? spec_helper.rb
Run Code Online (Sandbox Code Playgroud)
这基本上是我们当前使用的结构,我们spec/spec_helper.rb使用默认/简单
require 'serverspec'
require 'docker'
RSpec.configure do |config|
# Use color in STDOUT
config.color = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :documentation # :progress, :html, :textmate
end
Run Code Online (Sandbox Code Playgroud)
这就是Rakefile我们正在使用的内容
require 'rake'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:rspec) do |t|
t.pattern = Dir.glob('*/*/spec/*_spec.rb')
t.rspec_opts = '--format documentation --require spec_helper --color'
end
task :default => :spec
Run Code Online (Sandbox Code Playgroud)
我们所面临的问题是,当我们运行bundle exec rake rspec的python/2.7/spec_image.rb测试失败,因为我们相信他们是在运行nodejs/7.0。当我们运行时bundle exec rspec python/2.7/spec/image_spec.rb,它将成功运行。
这也是image_spec.rb看起来像python/2.7
require 'serverspec'
require 'docker'
DOCKER_FOLDER = "python/2.7"
describe "Python/2.7 Specs" do
before :all do
add_simplejson_to_requirements
image = Docker::Image.build_from_dir(DOCKER_FOLDER, ARG: 'requirements.txt')
set :path, '/usr/local/bin:$PATH'
set :os, family: :alpine
set :backend, :docker
set :docker_image, image.id
end
#test for python version 2.7
it 'has python 2.7 installed' do
expect(command('python -c "import sys; print(sys.version_info[:])"').stdout).to include\
'2, 7'
end
it 'installs requirements.txt given as --build-arg' do
expect(command('pip install simplejson==3.6.3').stdout).to include\
'Requirement already satisfied'
end
end
Run Code Online (Sandbox Code Playgroud)
有人可以指出我们正确的方向吗?
谢谢
小智 0
如果有人发现这个旧线程,我最近在测试多个图像/容器时遇到了同样的问题。我的解决方案是添加一个调用后端方法的after(:all)块:clear
after(:all) do
# Reset the docker backend so other images/containers can be tested.
Specinfra::Backend::Docker.clear
end
Run Code Online (Sandbox Code Playgroud)
它有点臭,但它确实有效。更好的解决方案是创建您自己的后端类并从一开始就实现多图像/容器支持。
| 归档时间: |
|
| 查看次数: |
415 次 |
| 最近记录: |