运行嵌套的食谱? | Chefspec

时间:2018-05-15 16:57:37

标签: unit-testing nginx chef chefspec

我正在尝试为cookbook Nginx运行chefspec测试,它与其他一些像bar一样在同一目录中。对于我的InSpec测试,在kitchen test中运行../../Nginx,其中包含.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

1 个答案:

答案 0 :(得分:0)

我建议你改写你的帖子来实际添加一个问题......我找不到任何问题,所以我不确定你在问什么:)所以我会回答最有可能的两个问题你可能要问的事情:

1)如何在特定食谱中运行所有测试?

这很简单,您只需稍微修改rspec命令,如下所示:

rspec ./spec/

您当然可以指定其他文件夹。我相信默认情况下,rspec会运行在该文件夹中找到的任何文件,这些文件以_spec.rb结尾(也是子文件夹)。

2)导致<NoMethodError: undefined method '[]' for nil:NilClass>的原因是什么?

这是一个Ruby错误,如果您尝试在某处使用某个变量,但是该变量尚未设置,您将获得该错误。检查你的食谱/测试,并确保你没有在没有设置的情况下使用某个厨师属性。错误跟踪可能有助于确定这是什么。

我希望这有帮助!

相关问题