b0VIM 7.3ô_;æÛÓÍÌ File.exist?(expected_path).should be_true subject.get(img_url).should == expected_path it "should download when not exist"do end File.unlink(expected_path) rescue nil before(:each) do let(:expected_30s_path){ '/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/aea455b4b37a2d4240a6b054a0b0d5f8/cloud_cdn_icon.jpg' } let(:expected_path){ '/tmp/Rhcf::Utils::DownloadCache/default/aea455b4b37a2d4240a6b054a0b0d5f8/cloud_cdn_icon.jpg' } describe "#get" do end end File.exist?("/tmp/b/c/d/a.jpg").should be_true expect{ subject.download!(img_url, "/tmp/b/c/d/a.jpg") }.to_not raise_error File.exist?("/tmp/b/c/d/a.jpg").should be_false File.unlink("/tmp/b/c/d/a.jpg") it "should create necessary directories and download to the given path" do end end.to_not raise_error out.should == "/tmp/b/c/d/a.jpg" out = subject.download!(img_url, "/tmp/b/c/d/a.jpg") expect do it "should return the given file path" do describe "#download!" do end end subject.filename_for(img_url).should == '/tmp/Rhcf::Utils::DownloadCache/default/aea455b4b37a2d4240a6b054a0b0d5f8/cloud_cdn_icon.jpg' it "should return a path with cache id , file name hash and file hash component" do describe "#filename_for" do end end cache_of_30s.hit?(img_url).should be_false FileUtils.rm "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/aea455b4b37a2d4240a6b054a0b0d5f8/cloud_cdn_icon.jpg" it "should return false if doesn't exist" do end end cache_of_30s.hit?(img_url).should be_false Timecop.travel(Time.now + 3600) do it "should return false if file downloaded and older then ttl" do end cache_of_30s.hit?(img_url).should be_true it "should return true if file downloaded and newer then ttl" do end cache_of_30s.hit?(img_url).should be_true cache_of_30s.filename_for(img_url).should == '/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/aea455b4b37a2d4240a6b054a0b0d5f8/cloud_cdn_icon.jpg' it "should return true if file downloaded and ttl is null" do end FileUtils.touch "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/aea455b4b37a2d4240a6b054a0b0d5f8/cloud_cdn_icon.jpg" FileUtils.mkdir_p "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/aea455b4b37a2d4240a6b054a0b0d5f8" FileUtils.rm_rf "/tmp/Rhcf::Utils::DownloadCache/cache_of_30s/aea455b4b37a2d4240a6b054ca0b0d5f8" before(:each) do describe "#hit?" do end end Rhcf::Utils::DownloadCache.hit_fname?("/dfasd/asd/as/das/d/sada", nil).should be_false it "should return false if doesn't exist" do end Rhcf::Utils::DownloadCache.hit_fname?("/etc/passwd",30 ).should be_false it "should return false if file exists and older then ttl" do end Rhcf::Utils::DownloadCache.hit_fname?("/etc/passwd", 20 * 365 * 24 * 3600 ).should be_true it "should return true if file exists and newer then ttl" do end Rhcf::Utils::DownloadCache.hit_fname?("/etc/passwd", nil).should be_true it "should return true if file exists and ttl is null" do describe "#hit_fname?" do end Rhcf::Utils::DownloadCache.should be_instance_of(Class) it "should be a class" do let(:foo_cache_of_30s){Rhcf::Utils::DownloadCache.new('cache_of_30s', 30, '/tmp/foo')} let(:cache_of_30s){Rhcf::Utils::DownloadCache.new('cache_of_30s', 30)} let(:img_url){"http://www.sunnyvision.com/images/cloud_cdn_icon.jpg"}describe Rhcf::Utils::DownloadCache dorequire 'timecop'require 'fileutils'require 'rhcf/utils/download_cache'require 'spec_helper'adž v 1øóò²vE=87ÈÀ»º‡@ î ° ¦ i a \ [ $ Ý © ƒ E ;  ú õ ô ° t l k < ô ì é Æ ” ‰ { z v eeeeeeeeend end end end it "should cache forever if ttl is null" do describe "when ttl is null" do end expect{ cache_of_30s.get("hftp://3423c434v234xd")}.to raise_error it "should raise when download problem" do end cache_of_30s.get(img_url).should == expected_30s_path it "should return absolute path to downloaded or cache file" do end IO.read(expected_30s_path).should == "oldycontent" end cache_of_30s.get(img_url).should == expected_30s_path Timecop.travel(Time.now + 3) do File.exist?(expected_30s_path).should be_true File.open(expected_30s_path, "w") {|fd| fd.write("oldycontent")} it "should not redownload files newer then ttl" do end IO.read(expected_30s_path).should_not == "oldycontent" end cache_of_30s.get(img_url).should == expected_30s_path Timecop.travel(3600) do File.exist?(expected_30s_path).should be_true File.open(expected_30s_path, "w") {|fd| fd.write("oldycontent")} it "should redownload files older then ttl" do end foo_cache_of_30s.get(img_url).should == expected_30s_path it "should download on given root path" do end File.exist?(expected_path).should be_false cache_of_30s.get(img_url).should_not == expected_path it "should download on different directory per cache_id" do end