您好正在使用 chefspec 进行测试,我发现以下错误。
在/cookbook/wordpress/recipes/default.rb
wp_secrets = Chef::Config[:file_cache_path] + '/wp-secrets.php'
if File.exist?(wp_secrets)
salt_data = File.read(wp_secrets)
else
require 'open-uri'
salt_data = open('https://api.wordpress.org/secret-key/1.1/salt/').read
open(wp_secrets, 'wb') do |file|
file << salt_data
end
end
当我运行 ChefSpec 时,我得到:
1) wordpress::default on Centos 6.5 includes depends recipes
Failure/Error: end.converge('wordpress::default')
Errno::ENOENT:
No such file or directory @ rb_sysopen - /var/chef/cache/wp-secrets.php
# /tmp/d20140617-408-1rx47um/cookbooks/wordpress/recipes/default.rb:77:in `from_file'
# ./spec/centos/default_spec.rb:10:in `block (2 levels) in <top (required)>'
# ./spec/centos/default_spec.rb:20:in `block (2 levels) in <top (required)>'
当我添加一个存根时default_spec.rb
before do
File.stub(:exist?)
.with("#{Chef::Config[:file_cache_path]}/wp-secrets.php")
.and_return(true)
end
我收到此错误:
1) wordpress::default on Centos 6.5 includes depends recipes
Failure/Error: end.converge('wordpress::default')
<File (class)> received :exist? with unexpected arguments
expected: ("/var/chef/cache/wp-secrets.php")
got: ("/tmp/d20140617-479-1gqb2lc/cookbooks/chefignore")
Please stub a default value first if message might be received with other args as well.
# ./spec/centos/default_spec.rb:10:in `block (2 levels) in <top (required)>'
# ./spec/centos/default_spec.rb:20:in `block (2 levels) in <top (required)>'