【发布时间】:2018-05-15 16:57:36
【问题描述】:
我正在尝试为食谱 Nginx 运行 chefspec 测试,它与 bar 之类的其他一些目录位于同一目录中。对于我的 InSpec 测试,在 ../../Nginx 中运行 kitchen test,其中包含我的 .kitchen.yml 文件。
我提到bar 食谱的原因是它是我.kitchen.yml 中运行列表中的第一个。我运行bar,然后它也调用了其他一些,Nginx 在食谱中更进一步。
希望这有点道理。
这是我在终端中的错误消息
[2018-05-15T12:45:57-04:00] WARN: Port 8889 not available
nginx::default
Nginx
Converges successfully (FAILED - 1)
Failures:
1) nginx::default Nginx Converges successfully
Failure/Error: expect { chef_run }.to_not raise_error
expected no Exception, got #<NoMethodError: undefined method `[]' for nil:NilClass> with backtrace:
# /var/folders/pj/c4gpnwws6n7gb7x_plpv9hzc0000gp/T/chefspec20180515-32598-1um8wa6file_cache_path/cookbooks/nginx/recipes/_configure.rb:23:in `from_file'
# /var/folders/pj/c4gpnwws6n7gb7x_plpv9hzc0000gp/T/chefspec20180515-32598-1um8wa6file_cache_path/cookbooks/nginx/recipes/default.rb:324:in `from_file'
# ./spec/unit/recipes/default_spec.rb:10:in `block (3 levels) in <top (required)>'
# ./spec/unit/recipes/default_spec.rb:13:in `block (4 levels) in <top (required)>'
# ./spec/unit/recipes/default_spec.rb:13:in `block (3 levels) in <top (required)>'
# ./spec/unit/recipes/default_spec.rb:13:in `block (3 levels) in <top (required)>'
Finished in 4.08 seconds (files took 1.98 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/unit/recipes/default_spec.rb:12 # nginx::default Nginx Converges successfully
我正在使用的命令
Josh:nginx josh$ chef exec rspec spec/unit/recipes/default_spec.rb --format d
我的测试文件
超级基本,直到它运行,然后我才能使用我的完整测试列表。
require 'chefspec'
describe 'nginx::default' do
context 'Nginx' do
let(:chef_run) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) }
it 'Converges successfully' do
expect { chef_run }.to_not raise_error
end
end #end context Nginx
end # end describe nginx::default
【问题讨论】:
-
Chefspec 不运行整个食谱,它运行单独的食谱。在您的情况下,您只测试
nginx::default并且它失败了 - 可能是由于缺少一些环境/依赖项。 -
@SzymonSzypulski 谢谢,它调用了其中的 2 个其他食谱。有没有我可以运行的测试来查看它是否调用了所有内容?食谱应该可以正常工作,因为当我进入几个目录并运行
kitchen converge时,它可以正常工作,因为这个食谱/食谱是运行列表的一部分
标签: unit-testing nginx chef-infra chefspec