我陷入了一个chefspec测试,该测试进入我的lwrp下面并断言它创建了一个目录。
describe 'mw-tomcat::chefspec' do
let(:chef) do
ChefSpec::SoloRunner.new(step_into: ['mw_tomcat_tree']) do |node|
node.set['mw']['domain'] = domain
node.set['mw']['gemrepo'] = gemrepo
end
end
let(:chef_run) { chef.converge(described_recipe) }
it 'creates the catalina_base directory' do
expect(chef_run).to create_directory('/apps/bweb/apps/instance1')
end
done
如果我取消注释下面的行,则测试有效,但在尝试从 new_resource.settings 获取值时失败
action :create do
settings = new_resource.settings
catalina_base=settings['catalina_base']
#catalina_base='/apps/bweb/apps/instance1'
directory "#{catalina_base}" do
mode 0755
owner settings['user']
group settings['group']
recursive true
action :create
end
end
chefspec 有没有办法传入上面的 new_resource 值?
谢谢你的帮助。
爱德华
*更新
它失败并显示以下消息:
[2015-08-21T19:25:02+01:00] DEBUG: resources for generic directory resource enabled on node include: [Chef::Resource::Directory]
[2015-08-21T19:25:02+01:00] DEBUG: resources that survived replacement include: [Chef::Resource::Directory]
[2015-08-21T19:25:02+01:00] DEBUG: resources for generic directory resource enabled on node include: [Chef::Resource::Directory]
[2015-08-21T19:25:02+01:00] DEBUG: resources that survived replacement include: [Chef::Resource::Directory]
[2015-08-21T19:25:02+01:00] DEBUG: resources for generic directory resource enabled on node include: [Chef::Resource::Directory]
[2015-08-21T19:25:02+01:00] DEBUG: resources that survived replacement include: [Chef::Resource::Directory]
[2015-08-21T19:25:02+01:00] DEBUG: resources for generic directory resource enabled on node include: [Chef::Resource::Directory]
[2015-08-21T19:25:02+01:00] DEBUG: resources that survived replacement include: [Chef::Resource::Directory]
[2015-08-21T19:25:02+01:00] DEBUG: resources for generic link resource enabled on node include: [Chef::Resource::Link]
[2015-08-21T19:25:02+01:00] DEBUG: resources that survived replacement include: [Chef::Resource::Link]
[2015-08-21T19:25:02+01:00] DEBUG: resources for generic link resource enabled on node include: [Chef::Resource::Link]
[2015-08-21T19:25:02+01:00] DEBUG: resources that survived replacement include: [Chef::Resource::Link]
[2015-08-21T19:25:02+01:00] INFO: Processing directory[] action create (/home/we_edqui/mw-chef-repo/cookbooks/mw-tomcat/providers/tree.rb line 51)
[2015-08-21T19:25:02+01:00] INFO: Processing directory[/bin] action create (/home/we_edqui/mw-chef-repo/cookbooks/mw-tomcat/providers/tree.rb line 77)
[2015-08-21T19:25:02+01:00] INFO: Processing directory[/conf] action create (/home/we_edqui/mw-chef-repo/cookbooks/mw-tomcat/providers/tree.rb line 77)
[2015-08-21T19:25:02+01:00] INFO: Processing directory[/lib] action create (/home/we_edqui/mw-chef-repo/cookbooks/mw-tomcat/providers/tree.rb line 77)
[2015-08-21T19:25:02+01:00] INFO: Processing directory[/logs] action create (/home/we_edqui/mw-chef-repo/cookbooks/mw-tomcat/providers/tree.rb line 77)
[2015-08-21T19:25:02+01:00] INFO: Processing directory[/temp] action create (/home/we_edqui/mw-chef-repo/cookbooks/mw-tomcat/providers/tree.rb line 77)
[2015-08-21T19:25:02+01:00] INFO: Processing directory[/webapps] action create (/home/we_edqui/mw-chef-repo/cookbooks/mw-tomcat/providers/tree.rb line 77)
[2015-08-21T19:25:02+01:00] INFO: Processing directory[/work] action create (/home/we_edqui/mw-chef-repo/cookbooks/mw-tomcat/providers/tree.rb line 77)
[2015-08-21T19:25:02+01:00] INFO: Processing link[/lib/BESTFilter] action create (/home/we_edqui/mw-chef-repo/cookbooks/mw-tomcat/providers/tree.rb line 109)
creates the catalina_base directory (FAILED - 1)
Failures:
1) mw-tomcat::chefspec creates the catalina_base directory
Failure/Error: expect(chef_run).to create_directory('/apps/bweb/apps/instance1')
expected "directory[/apps/bweb/apps/instance1]" with action :create to be in Chef run. Other directory resources:
directory[]
directory[/bin]
directory[/conf]
directory[/lib]
directory[/logs]
directory[/temp]
directory[/webapps]
directory[/work]
# ./spec/default_spec.rb:68:in `block (2 levels) in <top (required)>'
Finished in 0.80061 seconds (files took 4.72 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/default_spec.rb:67 # mw-tomcat::chefspec creates the catalina_base directory