【发布时间】:2015-09-14 20:10:18
【问题描述】:
我使用以下 Gemfile 设置了一个新的 puppet demo 模块,当我运行一个简单的 puppet-rspec 测试时它按预期工作。
宝石文件
source 'https://rubygems.org'
if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', '3.7.5'
end
gem 'metadata-json-lint'
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0'
gem 'rspec-puppet-facts'
# rspec must be v2 for ruby 1.8.7
if RUBY_VERSION >= '1.8.7' and RUBY_VERSION < '1.9'
gem 'rspec', '~> 2.0'
end
但是,当我克隆一个现有模块 (silex) 并将 Gemfile 更新为类似于上面的样子并运行时:
bundle exec rake spec
我收到以下错误:
vagrant$ bundle exec rake spec
/usr/bin/ruby -S rspec spec/classes/init_spec.rb --color
F
Failures:
1) silex with defaults for all parameters should contain Class[silex]
Failure/Error: it { should contain_class('silex') }
Puppet::Error:
Could not find class silex for centos65-box-1 on node centos65-box-1
# ./spec/classes/init_spec.rb:5
Finished in 0.31963 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/classes/init_spec.rb:5 # silex with defaults for all parameters should contain Class[silex]
该课程存在,我已经完成了一次木偶运行。有人可以帮助我理解为什么会这样吗?
更多信息
# Tree
.
├── files
│ └── httpd.patch
├── Gemfile
├── Gemfile.lock
├── lib
│ └── facter
│ └── vendor_dir.rb
├── manifests
│ ├── backup.pp
│ ├── config.pp
│ ├── init.pp
│ ├── install.pp
│ ├── params.pp
│ └── service.pp
├── metadata.json
├── Rakefile
├── README.md
├── spec
│ ├── classes
│ │ └── init_spec.rb
│ ├── fixtures
│ │ ├── manifests
│ │ │ └── site.pp
│ │ └── modules
│ └── spec_helper.rb
├── templates
│ └── var
│ └── config
│ └── settings.json.erb
└── tests
└── init.pp
# spec_helper.rb
require 'puppetlabs_spec_helper/module_spec_helper'
require 'rspec-puppet-facts'
include RspecPuppetFacts
#init_spec.rb
require 'spec_helper'
describe 'silex' do
context 'with defaults for all parameters' do
it { should contain_class('silex') }
end
end
【问题讨论】:
-
你能在模块根目录上运行“tree”,显示 spec_helper 的内容和类规范的样子吗?
-
您需要
spec/fixtures/modules中的silex模块才能使rspec-puppet能够加载它。 -
测试一个模块似乎总是在 puppet 自动加载器变得最烦人的时候,我希望有更好的方法来处理这个问题。
-
@FelixFrank:看起来我找到了问题的根源。我需要运行
rspec-puppet-init以确保它为我的清单、模板创建必要的符号链接。等 -
@aspiringCodeArtisan 请将其添加为答案并接受!
标签: rspec puppet rspec-puppet