Rspec 在chefspec中打开存根文件

Rspec 在chefspec中打开存根文件,rspec,chef-infra,chefspec,Rspec,Chef Infra,Chefspec,您好,我正在使用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:/

您好,我正在使用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
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)>'
1)wordpress::Centos 6.5上的默认值包括
失败/错误:end.converge('wordpress::default')
收到:存在吗?意料之外的争论
应为:(“/var/chef/cache/wp secrets.php”)
得到:(“/tmp/d20140617-479-1gqb2lc/cookbooks/chefignore”)
如果消息可能与其他参数一起接收,请先存根一个默认值。
#./spec/centos/default_spec.rb:10:in'block(2层)in'
#./spec/centos/default_spec.rb:20:in“块(2层)in”

您需要保留原始通话:

在ChefSpec 3中:

File.stub(:exist?)。并调用\u original
File.stub(:exist?).with('/path/to/File')。和_return('…'))
在ChefSpec 4中:

allow(File).接收(:exist?)并调用\u original
允许(文件).to接收(:存在?).with('/path/to/File')。并返回('…'))

这也帮助我删除了对RSpec的弃用警告。谢谢
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)>'