如何在Rspec-Puppet中模拟自定义类型

时间:2014-04-14 12:30:04

标签: mocking tdd puppet

由于实施了this问题的答案,我可以使用custom typesrspec-puppet进行测试。

但是,我想避免在custom folder mocking的每个木偶模块中为cystom types创建符号链接。

问题是如何在Rspec-Puppet中模拟自定义木偶类型。

我找到了关于模仿自定义木偶Function的{​​{3}},但我正在寻找一个模拟Puppet Custom Types的示例。

Puppet Code

class vim::ubuntu::config {
  custom_multiple_files { 'line_numbers':
    ensure     => 'present',
    parent_dir => '/home',
    file_name  => '.vimrc',
    line       => 'set number';
  }
}

Rspec-puppet代码

require 'spec_helper'

describe "vim::ubuntu::config" do
  ?
end

1 个答案:

答案 0 :(得分:2)

寻找嘲笑示例的好地方是Puppet自己的unit tests的集合。

我不确定是否有需要考虑的专业,但在Puppet的规范测试中,模拟效果如下:

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中,模拟/存根多了involvedrspec-puppet可能需要这样做。