2017-03-29 40 views
0

我试图为我的remote_file资源之一编写rspec。但我没有成功。
我的概念是使用remote_file它应该下载一个zip文件的远程文件。远程下载后,rspec会发生什么。无法解决远程文件资源的rspec问题

这是我的资源声明:

remote_file zip_file_location do 
    source http://google.com 
    mode '0754' 
    action :create 
end​ 

这是我的RSpec测试:

it 'creates a remote_file ' do 
    expect(chef_run).to create_remote_file(::File.join(Chef::Config[:file_cache_path], 'sonarqube-5.6.6.zip')) 
end 

回答

0

这是你的资源

remote_file 'sonarqube-5.6.6.zip' do 
source 'http://google.com/' 
action :create 
mode 00755 
end 

,这是rspec的为您的资源

it 'creates a remote_file ' do 
    expect(chef_run).to create_remote_file('sonarqube-5.6.6.zip').with(
     source: "http://google.com", 
     mode: 00755 
) 
end 

如果你想有从属性/ default.rb配置值已保存的文件的位置,你必须在你的rspec的文件嘲笑这样的:

describe 'lecturio_ds::webfrontend' do 
    context 'When all attributes are default, on an unspecified platform' do 
    let(:chef_run) do 
    ChefSpec::SoloRunner.new do |node| 
     node.set['file_cache_path'] = '/tmp' 
    end.converge(described_recipe) 
    end 
# place for your spec 
end 

之后,你可以验证它create_remote_file('/tmp/sonarqube-5.6.6.zip')

我不明白你为什么在你的rspec文件File.join那里使用。

+0

@gig我给它需要安装 – pandey

+0

Rspec的就像是你的代码进行单元测试远程文件的路径,也就是在你的愿望目录结束没有真正的文件。 – glg

0

对于这个工作我几个原因,我修改了代码,通过给远程文件,它帮我解决rspec的期望完全zip文件位置

帮我解决rspec的

remote_file 'Download zip file'do 
 
Path zip_file_location 
 
source http://google.com 
 
mode '0754' 
 
action :create 
 
end​ 
 

 

 
it 'creates a remote_file ' do 
 
expect(chef_run).to create_remote_file('Download remote file') 
 
end
路径