Chef Exec Rspec错误:未初始化的常量Chef :: ReservedNames :: Win32 :: Security

时间:2019-07-04 15:31:34

标签: chef

我正在编写代码以在Windows服务器上运行资源“ windows_task”。 “首席执行员rspec”抛出错误。

我试图在资源“ windows_task”上运行单元测试,但失败了。是否有任何解决方案或解决方法。我的工作站是一台EC2 Linux服务器,但是尝试测试Windows的资源。

recipes/default.rb

windiows_task 'client' do
  run_level :highest
  command 'ipconfig.exe'
  user 'SYSTEM'
  frequency :hourly
  frequency_modifier 20
end

spec/unit/recipes/default_spec.rb

require 'spec_helper'
describe 'windows_test::default' do
  context 'when all attributes are default to windows' do
    let(:chef_run) do
      runner = ChefSpec::ServerRunner.new(platform: 'windows', version: '2012R2')
      runner.converge(described_recipe)
  end
  it 'converges successfully' do
     expect { chef_run }.to_not raise_error
  end
 end
 at_exit {ChefSpec::Coverage.report!}
end

实际结果是失败而不是成功:

失败:

   1) windows_test::default when all attributes are default to windows converges successfully.
   Failure/Error: expect { chef_run }.to_not raise_error

   expected no Exception, got #<NameError: uninitialized contstant Chef::Win32::Security
   Did you mean? SecurityError> with backtrace:
     # /tmpchefspec20190704-../cookbooks.windows_test/recipes/dafault.rb:35:in `from file`
    ----
    ----
Finished in 0.73 seconds
1 example, 1 failure

1 个答案:

答案 0 :(得分:0)

由于您的帖子中缺少一些信息,因此很难准确地找出问题所在,但似乎您缺少依赖项。

我建议您重新访问您的spec_helper文件,以确保您的require() chefspecchef红宝石。