1

我正在尝试为 rspec-puppet 测试编写测试。

该模块具有以下树:

 |-- manifests
    |   `-- test_file.pp
    |-- Rakefile
    `-- spec
        |-- classes
        |-- defines
        |   `-- test_file_spec.rb
        |-- fixtures
        |   |-- manifests
        |   |   `-- site.pp
        |   `-- modules
        |       `-- test
        |           |-- files -> ../../../../files
        |           |-- lib -> ../../../../lib
        |           |-- manifests -> ../../../../manifests
        |           `-- templates -> ../../../../templates
        |-- functions
        |-- hosts
        `-- spec_helper.rb 

运行“rake rspec”时出现以下错误

(in /etc/puppetlabs/puppet/modules/offshore/test)
rake aborted!
no such file to load -- rspec/core/rake_task
/etc/puppetlabs/puppet/modules/offshore/test/Rakefile:2
(See full trace by running task with --trace)

当我运行“rake spec --trace”时,它会给出以下信息:

rake aborted!
no such file to load -- rspec/core/rake_task
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/etc/puppetlabs/puppet/modules/offshore/test/Rakefile:2
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2382:in `load'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2382:in `raw_load_rakefile'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2016:in `load_rakefile'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2067:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2015:in `load_rakefile'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1999:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2067:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1997:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

有人可以帮我设置吗?

4

1 回答 1

0

您需要Gemfile在模块的根目录中包含以下内容:

source 'http://rubygems.org'

group :test do
  gem 'rake'
  gem 'puppet', ENV['PUPPET_VERSION'] || '~> 3.4.0'
  gem 'puppet-lint'
  gem 'rspec-puppet', :git => 'https://github.com/rodjek/rspec-puppet.git'
  gem 'puppet-syntax'
  gem 'puppetlabs_spec_helper'
  gem 'simplecov'
  gem 'metadata-json-lint'
end

然后运行bundle install

然后运行bundle exec rake spec

还有一个有用的工具puppet-retrospec可以自动将规范添加到现有模块:https ://github.com/logicminds/puppet-retrospec ,这可能会对您有所帮助。

于 2015-07-07T13:52:10.160 回答