我正在尝试使用ChefSpec运行HelloWorld类型示例。我运行了$ chef generate cookbook learn_chef2
以生成具有正确目录结构的Chef cookbook。
然后我在default.rb中创建了一个超级简单的Chef配方:
package 'ant'
package 'php5'
package 'git'
我在chef_spec.rb中的ChefSpec测试:
#require 'spec_helper'
require 'chefspec'
require 'chefspec/berkshelf'
describe 'package::install' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
it 'converges successfully' do
expect(chef_run).to install_package('ant')
end
end
然而,当我运行rspec时,我得到以下内容:
/var/lib/gems/2.1.0/gems/rspec-core-3.2.3/lib/rspec/core/formatters/progress_formatter.rb:1:in `<top (required)>': undefined method `require_rspec_core' for RSpec::Support:Module (NoMethodError)
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:1093:in `built_in_formatter'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:573:in `add_formatter'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:589:in `reporter'
from /usr/lib/ruby/vendor_ruby/rspec/core/command_line.rb:25:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:80:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:17:in `block in autorun'
我是Ruby和RSpec的新手,我确信这是一个简单的配置问题。有什么想法吗?
谢谢!
答案 0 :(得分:0)
通常你需要做的是require 'rspec'
作为第一行,但我很确定这是用你在第1行注释掉的spec_helper.rb
写的。