0

我正在尝试使用 ChefSpec 运行 HelloWorld 类型的示例。我跑来$ chef generate cookbook learn_chef2生成具有正确目录结构的 Chef 食谱。

然后我在 default.rb 中创建了一个超级简单的 Chef 食谱:

package 'ant'
package 'php5'
package 'git'

还有我在 default_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 的新手,我确信这是一个简单的配置问题。有什么想法吗?

谢谢!

4

1 回答 1

0

通常你必须做的是require 'rspec'第一行,但我很确定那是写在spec_helper.rb你在第 1 行注释掉的地方。

于 2015-05-12T20:44:29.327 回答