未定义的局部变量或方法 - 使用 Beaker 测试 Puppet 模块 [英] Undefined local variable or Method - Testing Puppet Modules using Beaker
问题描述
我对这一切都很陌生.我正在尝试使用 Beaker 测试木偶模块.我一直收到这个:
I'm quite new to all of this. I am trying to test out a puppet module using Beaker. I keep getting this:
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 包含这个:
My unit_spec.rb contains this:
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' 时,它给了我一个错误,即使它在那里也无法加载此类文件".
Any help would be much appreciated! Btw, I am using 'puppetlabs_spec_helper/rake_tasks' due to the fact that when I just used 'spec_helper' it gave me an error that it could not "load such file" even though it was there.
另外,我也尝试过
RSpec.Describe
这也没有解决问题.我收到以下错误 -
That did not fix the issue either. I get the following error -
NameError: undefined local variable or method `on_supported_os' for #Class:0x007f92a61d5e58
我意识到这可能是 RSpec Puppet 的问题,因为该模块之前已通过 Puppet RSpec 进行过测试,但是现在我正在尝试使用 Beaker 进行测试,但不太确定如何完全实现!
I realise that this might be an RSpec Puppet issue, as this module was previously tested through puppet RSpec, however now I am trying to test using Beaker and not quite sure how to fully achieve that!
推荐答案
您正在混淆基于单元和基于 VM 的测试.
You're mixing up unit- and VM-based testing.
rspec-puppet(和 rspec-puppet-facts'
on_supported_os
) 用于基于目录的单元测试.它们不需要虚拟机,可以为您提供有关模块语法和逻辑的快速反馈.
rspec-puppet (and rspec-puppet-facts'
on_supported_os
) are for catalog-based unit testing. They do not require a VM, and can give you quick feedback on syntax, and logic of your module.
beaker,以及推荐的 beaker-rspec 附加组件,提供完整的端到端测试功能,使用实际的虚拟机,并测试完整的堆栈部署(定义在你测试).
beaker, and the recommended beaker-rspec add-on, provide full end-to-end testing capabilities, using actual VMs, and testing a complete stack deploy (as defined in you tests).
现有模块的主要入口点通常是 rake.使用 rake -T
查看模块中现有的 rake 任务.在一个编写良好的模块中,它应该有 rspec-puppet(通常称为 spec
)和 beaker(通常称为 beaker
或 acceptance
)的任务>).
The main entry point for existing modules is usually rake. Take a look at the existing rake tasks in the module using rake -T
. In a well-written module it should have tasks for both rspec-puppet (usually called spec
), and beaker (often called beaker
, or acceptance
).
如果它是您自己的模块,您可能还想查看新的 Puppet 开发工具包,在单个安装程序中获取最重要的工具.
If it is your own module, you also might want to look into the new Puppet Development Kit to get the most important tools in a single installer.
这篇关于未定义的局部变量或方法 - 使用 Beaker 测试 Puppet 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!