问题描述
由于实现了问题.
但是,我想避免通过mocking
cystom types
在每个人偶模块中创建到custom folder
的符号链接.
However, I would like to avoid to create a symlink to the custom folder
in every puppet-module by mocking
cystom types
.
问题是如何在Rspec-Puppet中模拟自定义人偶类型.
The question is how to mock Custom Puppet Types in Rspec-Puppet.
我发现了一个有关模拟自定义人偶的示例. c5>,但我正在寻找一个模拟Puppet Custom Types
的示例.
I have found an example regarding the mocking of a Custom Puppet Function
but I am looking for an example to mock Puppet Custom Types
.
人偶代码
class vim::ubuntu::config {
custom_multiple_files { 'line_numbers':
ensure => 'present',
parent_dir => '/home',
file_name => '.vimrc',
line => 'set number';
}
}
Rspec人偶代码
require 'spec_helper'
describe "vim::ubuntu::config" do
?
end
推荐答案
在Puppet自己的单元测试.
A good place to go looking for examples on mocking is the collection of Puppet's own unit tests.
我不确定是否需要考虑一个专业,但是在Puppet的规格测试中,模拟的工作方式如下:
I'm not sure if there are an specialties that needs to be considered, but within Puppet's spec test, the mocking works like this:
let(:type) { Puppet::Type.type(:custom_file_line) }
it "should do whatever"
type.stubs(:retrieve).returns <value>
# perhaps also needed
Puppet::Type.stubs(:type).with(:custom_file_line).returns(type)
据我了解,这是 moccha 样式模拟.在普通的rspec中,模拟/存根是涉及的, rspec-puppet
可能是必需的.
From what I understand, this is moccha style mocking. In plain rspec, mocking/stubbing is a bit more involved, which may be necessary with rspec-puppet
.
这篇关于如何在Rspec-Puppet中模拟自定义类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!