未定义的局部变量或方法 – 使用Beaker测试Puppet模块

我对这一切都很陌生。 我正在尝试使用Beaker测试一个木偶模块。 我一直这样:

NoMethodError: undefined method `describe' for #Beaker::TestCase:0x007fd6f95e6460 /Users/user1/beaker/Puppet/puppet-files/spec/classes/unit_spec.rb:3 /Users/user1/.rvm/gems/ruby-2.2.7/gems/beaker-3.24.0/bin/beaker:9 /Users/user1/.rvm/gems/ruby-2.2.7/bin/ruby_executable_hooks:15 /Users/user1/.rvm/gems/ruby-2.2.7/bin/ruby_executable_hooks:15. This is the command that I'm running - "beaker --hosts myhost.yaml --pre-suite spec". 

我的unit_spec.rb包含:

  require 'puppetlabs_spec_helper/rake_tasks' describe 'application' do context 'applied to supported operating system' do on_supported_os.each do |os, facts| context "#{os}" do let(:facts) do facts end context "without any parameters" do let(:params) {{ }} it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('files') } end end end end context 'applied to unsupported operating system' do describe 'ubuntu-14-x86_64' do let(:facts) {{ :osfamily => 'Debian', :operatingsystem => 'Ubuntu' }} it { is_expected.to raise_error(Puppet::Error, /Ubuntu not supported/) } end end end 

任何帮助将非常感激! 顺便说一下,我正在使用’puppetlabs_spec_helper / rake_tasks’,因为当我刚使用’spec_helper’时,它给了我一个错误,它无法“加载这样的文件”,即使它在那里。

另外,我试过了

 RSpec.Describe 

这也没有解决问题。 我收到以下错误 –

  NameError: undefined local variable or method `on_supported_os' for #Class:0x007f92a61d5e58 

我意识到这可能是一个RSpec Puppet问题,因为这个模块以前是通过木偶RSpec测试的,但是现在我正在尝试使用Beaker测试并且不太确定如何完全实现它!

您正在混合基于单元和VM的测试。

  • rspec-puppet (和rspec-puppet- on_supported_os )用于基于目录的unit testing。 它们不需要VM,可以为您提供有关模块语法和逻辑的快速反馈。

  • beaker和推荐的beaker-rspec附加组件,提供完整的端到端测试function,使用实际的VM,并测试完整的堆栈部署(如测试中所定义)。

现有模块的主要入口点通常是rake。 使用rake -T查看模块中现有的rake任务。 在一个编写良好的模块中,它应该具有rspec-puppet(通常称为spec )和烧杯(通常称为beakeracceptance )的任务。

如果它是您自己的模块,您也可能需要查看新的Puppet Development Kit以在单个安装程序中获取最重要的工具。