Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
windows上的测试规范测试异常_Windows_Chef Infra_Test Kitchen_Serverspec - Fatal编程技术网

windows上的测试规范测试异常

windows上的测试规范测试异常,windows,chef-infra,test-kitchen,serverspec,Windows,Chef Infra,Test Kitchen,Serverspec,使用chef generate cookbook hello命令时,生成的serverspecspec\u helper.rb文件将无法与Test Kitchen 1.4.1和windows一起使用 kitchen verify命令将在windows平台上抛出以下命令: C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:98:in `spawn

使用
chef generate cookbook hello
命令时,生成的serverspec
spec\u helper.rb
文件将无法与Test Kitchen 1.4.1和windows一起使用

kitchen verify
命令将在windows平台上抛出以下命令:

C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:98:in `spawn': No such file or directory - /bin/sh -c ls\ /etc/arch-release (Errno::ENOENT)
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:98:in `spawn_command'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:13:in `block in run_command'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:133:in `with_env'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:12:in `run_command'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/detect_os.rb:13:in `run_command'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/detect_os/arch.rb:3:in `detect'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/detect_os.rb:5:in `detect'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:24:in `block in detect_os'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:23:in `each'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:23:in `detect_os'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:9:in `os'
    from C:/Users/vagrant/AppData/Local/Temp/verifier/suites/serverspec/windows_spec.rb:4:in `<top (required)>'
C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:98:in'spawn':没有这样的文件或目录-/bin/sh-C ls\/etc/arch发行版(Errno::enoint)
来自C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:98:in'spawn_command'
来自C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:13:in`block in run_命令'
来自C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:133:in'with_env'
来自C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/backend/exec.rb:12:in'run_command'
来自C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/detect_os.rb:13:in'run_command'
来自C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/SPEC INFRA-2.37.5/lib/specinfra/helper/detect\u os/arch.rb:3:在“检测”中
来自C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/detect_os.rb:5:in“detect”
来自C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:24:“检测中的块”
来自C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:23:in'each'
来自C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:23:in'detect_os'
来自C:/Users/vagrant/AppData/Local/Temp/verifier/gems/gems/specinfra-2.37.5/lib/specinfra/helper/os.rb:9:in'os'
来自C:/Users/vagrant/AppData/Local/Temp/verifier/suites/serverspec/windows_spec.rb:4:in`'

将测试厨房
spec\u helper.rb
文件更改为针对windows进行测试,并相应地设置后端和操作系统,解决了以下问题:

require 'serverspec'

if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil?
  set :backend, :exec
else
  set :backend, :cmd
  set :os, family: 'windows'
end
然后,您可以针对不同的平台进行测试,例如:

require 'spec_helper'

case os[:family]
when 'windows'
  describe file('C:\Users\vagrant\foo.txt') do
    it { should be_file }
  end
when 'darwin' # mac os x
  describe file('/user/vagrant/foo.txt') do
    it { should be_file }
  end
when 'ubuntu'
  describe file('/home/vagrant/foo.txt') do
    it { should be_file }
  end
end