在使用ServerSpec在我的厨师食谱上运行集成测试时,我遇到了一个问题。当我今天试图运行测试时,没有做任何更改,我得到了以下错误:
tl;dr
/tmp/busser/suites/serverspec/spec_helper.rb:3:in <top (required)>': uninitialized constant SpecInfra (NameError)
> [#] ---- Begin output of kitchen verify '(default)-.+' -p ----
> [#] STDOUT: -----> Starting Kitchen (v1.2.1)
> [#] -----> Verifying <default-CentOS-70>...
> [#] Removing /tmp/busser/suites/serverspec
> [#] Uploading /tmp/busser/suites/serverspec/localhost/nodejs_spec.rb (mode=0644)
> [#] Uploading /tmp/busser/suites/serverspec/spec_helper.rb (mode=0644)
> [#] -----> Running serverspec test suite
> [#] /opt/chef/embedded/bin/ruby -I/tmp/busser/suites/serverspec -I/tmp/busser/gems/gems/rspec-support-3.0.4/lib:/tmp/busser/gems/gems/rspec-core-3.0.4/lib -S /opt/chef/embedded/bin/rspec /tmp/busser/suites/serverspec/localhost/nodejs_spec.rb --color --format documentation
> [#] /tmp/busser/suites/serverspec/spec_helper.rb:3:in `<top (required)>': uninitialized constant SpecInfra (NameError)
> [#] from /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
> [#] from /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
> [#] from /tmp/busser/suites/serverspec/localhost/nodejs_spec.rb:1:in `<top (required)>'
> [#] from /tmp/busser/gems/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load'
> [#] from /tmp/busser/gems/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `block in load_spec_files'
> [#] from /tmp/busser/gems/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `each'
> [#] from /tmp/busser/gems/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load_spec_files'
> [#] from /tmp/busser/gems/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:97:in `setup'
> [#] from /tmp/busser/gems/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:in `run'
> [#] from /tmp/busser/gems/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run'
> [#] from /tmp/busser/gems/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke'
> [#] from /tmp/busser/gems/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>'
> [#] from /opt/chef/embedded/bin/rspec:23:in `load'
> [#] from /opt/chef/embedded/bin/rspec:23:in `<main>'
> [#] /opt/chef/embedded/bin/ruby -I/tmp/busser/suites/serverspec -I/tmp/busser/gems/gems/rspec-support-3.0.4/lib:/tmp/busser/gems/gems/rspec-core-3.0.4/lib -S /opt/chef/embedded/bin/rspec /tmp/busser/suites/serverspec/localhost/nodejs_spec.rb --color --format documentation failed
> [#] Ruby Script [/tmp/busser/gems/gems/busser-serverspec-0.2.7/lib/busser/runner_plugin/../serverspec/runner.rb /tmp/busser/suites/serverspec] exit code was 1
> [#]
> [#] STDERR: >>>>>> Verify failed on instance <default-CentOS-70>.
> [#] >>>>>> Please see .kitchen/logs/default-CentOS-70.log for more details
> [#] >>>>>> ------Exception-------
> [#] >>>>>> Class: Kitchen::ActionFailed
> [#] >>>>>> Message: SSH exited (1) for command: [sh -c 'BUSSER_ROOT="/tmp/busser" GEM_HOME="/tmp/busser/gems" GEM_PATH="/tmp/busser/gems" GEM_CACHE="/tmp/busser/gems/cache" ; export BUSSER_ROOT GEM_HOME GEM_PATH GEM_CACHE; sudo -E /tmp/busser/bin/busser test']
> [#] >>>>>> ----------------------有人知道为什么会发生这种事吗?
根据评论意见:
require 'serverspec'
# require 'specinfra' #I've tried both with and without this
include SpecInfra::Helper::Exec
include SpecInfra::Helper::DetectOS
RSpec.configure do |c|
if ENV['ASK_SUDO_PASSWORD']
require 'highline/import'
c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
else
c.sudo_password = ENV['SUDO_PASSWORD']
end
end该文件是按照为使用应用程序而设置的指令进行的,并且以前使用过未更改的操作。
发布于 2014-10-06 03:34:21
Test将尝试安装最新版本的ServerSpec。不幸的是,最近有一个ServerSpec的主要版本,它可能破坏了一些东西,所以您可能需要升级您的测试。
参见http://lists.opscode.com/sympa/arc/chef/2014-10/msg00027.html上的线程
发布于 2014-10-09 18:13:09
如果使用的是serverspec 2+,则需要删除SpecInfra行并用set命令替换:
require 'serverspec'
set :backend, :exec
RSpec.configure do |c|
c.before :all do
c.path = '/sbin:/usr/sbin'
end
end
# etc关于kitchen.ci - https://github.com/test-kitchen/guide-started-git-cookbook/pull/3上的示例回购,我的最新公关中有更多信息。
发布于 2014-10-03 17:03:36
/tmp/busser/suites/serverspec/spec_helper.rb文件可能引用常量SpecInfra,但是您还没有加载任何gem或Ruby实际定义的常量,因此该常量是未定义的。
我在SpecInfra上找不到多少文档,但我想您只需在shell中运行gem install specinfra才能安装gem,然后在发生错误的文件顶部添加require 'specinfra'。这是修复这些类型错误的通常方法。
我假设spec_helper.rb是您在某个时候编写的一个文件,它是由serverspec复制到服务器上的,但我从未使用过该工具,所以我对它不太了解。您需要确保gem被安装/复制到正在运行测试的服务器上,因此您可能需要将gem添加到serverspec的某些配置文件中。
https://stackoverflow.com/questions/26183101
复制相似问题