【问题标题】:Executing chef test from a rakefile从 rakefile 执行厨师测试
【发布时间】:2015-11-22 00:38:49
【问题描述】:

我有一些可以通过以下命令运行的主厨单元测试:chef exec rspec

但是,我正在尝试从 TeamCity 运行这些,并且我使用的是 rakefile。当我尝试执行 rakefile 时,测试文件中的 require 'chefspec' 行会导致错误 "cannot load such file -- chefspec (LoadError)"

我知道 chefspec 已安装。我是 Ruby、chefspec、rspec 的新手。我知道提到了一个 gemspec 文件,我尝试在可以运行命令 chef exec rspec 的目录中创建一个来执行测​​试。但是,当我尝试运行bundle install 时,我收到错误Could not locate Gemfile or .bundle/ directory。安装 ruby​​ 时是否有 gemfile 的默认位置?在这一点上我很迷茫。

C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire': 无法加载此类文件 -- chefspec (LoadErr 要么) 来自 C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from D:/../spec/octopus_tentacle_spec.rb:1:in' 来自 C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in load' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:inblock in load_ 规格文件' 来自 C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in each' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:inload_spec_file ' 来自 C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in setup' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:inrun' 来自 C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in run' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:ininvoke' 来自 C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/exe/rspec:4:in <top (required)>' from C:/Ruby22/bin/rspec:23:inload' 来自 C:/Ruby22/bin/rspec:23:in &lt;main&gt;'

【问题讨论】:

    标签: ruby rspec rake teamcity chefspec


    【解决方案1】:

    gemspec 文件通常在您创建 Ruby gem 时使用,其中包含有关您正在创建的 Gem 的元数据。

    当您使用bundle install 时,它需要目录中的Gemfile。 Gemfile 用作目录中项目所需 gem 的清单文件。 chef exec 可能正在寻找此文件,并且仅适用于此处指定的 gem。

    尝试使用内容创建Gemfile

    source 'https://rubygems.org'
    
    gem 'rspec'
    gem 'chefspec'
    

    您应该在文件中列出您正在使用的其他 gem。 然后运行bundle install

    【讨论】:

    • 感谢您的回复,哈桑。我创建了一个名为chefspec.gemfile 的文件并使用了您提到的内容。但是,当我从文件位置运行 bundle install 时,我仍然收到错误 Could not locate Gemfile or .bundle/ directory
    • 文件名在这里我相信很重要,默认情况下它必须是Gemfile。如果您希望将其保留为chefspec.gemfile,那么您将需要在运行bundle install 时传递文件的位置。不知道它在windows上是否相同。另请注意,您将始终必须为需要 gemfile 的命令定义 BUNDLE_GEMFILE。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    相关资源
    最近更新 更多