运行测试时,ServerSpec在Windows 7上失败

时间:2015-04-24 01:06:40

标签: ruby windows serverspec

我最近尝试使用Ruby 2.1.6 for Windows创建一个ServerSpec作业。但是,使用the following GitHub repo处的代码,我会收到以下错误。

C:\Users\PD028300\Desktop\serverspec_test\windows_spec
λ rake spec
C:/Ruby/Ruby21-x64/bin/ruby.exe -I'C:/Ruby/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rspec-support-3.2.2/lib';'C:/Ruby/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.3/lib' 'C:/Ruby/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.3/exe/rspec' --pattern 'spec/localhost/*_spec.rb'
DL is deprecated, please use Fiddle

File "C:/Windows/System32/drivers/etc/hosts"
  should be file (FAILED - 1)
  content (FAILED - 2)

Failures:

  1) File "C:/Windows/System32/drivers/etc/hosts" should be file
     On host `localhost'
     Failure/Error: it { should be_file }
     TypeError:
       no implicit conversion of Symbol into Integer
       uname -s
       MINGW32_NT-6.1

     # ./spec/localhost/hosts_spec.rb:4:in `block (2 levels) in <top (required)>'

  2) File "C:/Windows/System32/drivers/etc/hosts" content
     On host `localhost'
     Failure/Error: it(:content) { should match /localhost/ }
       expected File "C:/Windows/System32/drivers/etc/hosts" to match /localhost/
       Diff:
       @@ -1,2 +1,2 @@
       -/localhost/
       +File "C:/Windows/System32/drivers/etc/hosts"


     # ./spec/localhost/hosts_spec.rb:5:in `block (2 levels) in <top (required)>'

Finished in 5.82 seconds (files took 0.6677 seconds to load)
2 examples, 2 failures

Failed examples:

rspec ./spec/localhost/hosts_spec.rb:4 # File "C:/Windows/System32/drivers/etc/hosts" should be file
rspec ./spec/localhost/hosts_spec.rb:5 # File "C:/Windows/System32/drivers/etc/hosts" content

C:/Ruby/Ruby21-x64/bin/ruby.exe -I'C:/Ruby/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rspec-support-3.2.2/lib';'C:/Ruby/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.3/lib' 'C:/Ruby/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.3/exe/rspec' --pattern 'spec/localhost/*_spec.rb' failed

这是否与我试图描述的文件有关,因为它是Windows机器上的hosts文件?

1 个答案:

答案 0 :(得分:0)

回过头来重新创建ServerSpec文件,它仍然无法正常工作。重新阅读教程http://serverspec.org/tutorial.htmlhttps://github.com/serverspec/serverspec/blob/master/WINDOWS_SUPPORT.md后,我在spec_helper.rb中添加了OS系列设置,并开始工作。

spec_helper.rb的最终结果是:

require 'serverspec'

set :backend, :cmd
set :os, :family => 'windows'

现在我制作的规格已经奏效了!只需确保要求spec_helper