#encoding: utf-8 require File.join(File.dirname(__FILE__), '..' , 'lib', 'simple_fs', 'file_pool') describe FilePool, "一般操作 " do before(:all) do @pool_path = '/tmp/file_pool' FileUtils.rm_rf @pool_path if Dir.exist? @pool_path Dir.mkdir @pool_path @pool = FilePool::Pool.new @pool_path @fixture_path = File.join(File.dirname(__FILE__), 'fixture', 'test') @fixture_md5 = '4205d2ce2399828dd37f330fd97ec648' end it '初始化' do Dir.exist?(@pool_path).should == true end it '檢查檔案是否存在(新增前)' do @pool.exist?(@fixture_md5).should == false end it '新增檔案' do file_id = @pool.puts(File.open(@fixture_path).read) file_id.should == @fixture_md5 File.exist?(File.join(@pool_path, @fixture_md5)).should == true end it '檢查檔案是否存在(新增後)' do @pool.exist?(@fixture_md5).should == true end it '刪除檔案' do @pool.delete(@fixture_md5) File.exist?(File.join(@pool_path, @fixture_md5)).should == false end end