1 # -*- encoding: utf-8 -*-
3 require 'local_picture'
7 @path = Rails.root + 'lib/test/temp/'
8 Dir.glob @path + '*' do |filename|
9 if File.directory?(filename)
10 Dir.glob filename do |filename2|
11 File.delete(filename2) unless File.directory?(filename2)
17 describe PictureIO::LocalPicture do
19 @path = Rails.root + 'lib/test/temp/'
20 @io = PictureIO::LocalPicture.new @path
23 describe 'ファイル存在確認に於いて' do
26 context 'ファイルがあるとき' do
28 File.open @path + 'exist', 'w' do |f|
31 @io.exist?('exist').should be_true
34 context 'ファイルがないとき' do
36 @io.exist?('not.exist').should be_false
41 describe 'ファイル取得に於いて' do
43 File.open @path + 'test.get', 'w' do |f|
46 File.open @path + 'v/testsub.get', 'w' do |f|
50 context 'ベースディレクトリから取るとき' do
52 @io.get('test.get').should match /basedata/
55 context 'サブディレクトリvから取るとき' do
57 @io.get('testsub.get', 'v').should match /subdata/
60 context '例外が発生するとき' do
62 File.stub(:open).with(any_args()).and_raise(StandardError)
63 @io.get('test.get').should be_false
68 describe 'ファイル作成に於いて' do
70 File.open @path + 'test.put', 'w' do |f|
74 context 'ベースディレクトリに作成するとき' do
76 @io.put('created', 'create.put')
79 File.exist?(@path + 'create.put').should be_true
81 it 'createdが書きこまれている' do
82 d = File.open(@path + 'create.put').read
83 d.should match /create/
86 context '既存ファイルを更新するとき' do
88 @io.put('overwrited', 'test.put')
90 it 'overwritedが書きこまれている' do
91 d = File.open(@path + 'test.put').read
92 d.should match /overwrited/
95 d = File.open(@path + 'test.put').read
96 d.should_not match /already/
99 context 'サブディレクトリhに作成するとき' do
101 @io.put('subdirtest', 'testsub.put', 'h')
104 File.exist?(@path + 'h/testsub.put').should be_true
106 it 'subdirtestが書きこまれている' do
107 d = File.open(@path + 'h/testsub.put').read
108 d.should match /subdirtest/
111 context '例外が発生するとき' do
113 File.stub(:open).with(any_args()).and_raise(StandardError)
114 @io.put('bindata', 'test.put').should be_false
119 describe 'ファイル削除に於いて' do
121 File.open @path + 'test.del', 'w' do |f|
124 File.open @path + 'thumbnail/testsub.del', 'w' do |f|
128 context 'ベースディレクトリから削除するとき' do
130 @io.delete('test.del')
131 File.exist?(@path + 'test.del').should be_false
134 context 'サブディレクトリthumbnailから削除するとき' do
136 @io.delete('testsub.del', 'thumbnail')
137 File.exist?(@path + 'thumbnail/testsub.del').should be_false
140 context '例外が発生するとき' do
142 File.stub(:delete).with(any_args()).and_raise(StandardError)
143 @io.delete('test.del.not.exist').should be_false