2017-03-29 20 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
路徑