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
35 it 'PictureIO::Error例外が発生する' do
36 File.stub(:exist?).with(any_args()).and_raise(StandardError)
38 @io.exist?('not.exist')
39 }.should raise_error(PictureIO::Error)
44 describe 'ファイル取得に於いて' do
46 File.open @path + 'test.get', 'w' do |f|
49 File.open @path + 'v/testsub.get', 'w' do |f|
53 context 'ベースディレクトリから取るとき' do
55 @io.get('test.get').should match /basedata/
58 context 'サブディレクトリvから取るとき' do
60 @io.get('testsub.get', 'v').should match /subdata/
63 context '例外が発生するとき' do
64 it 'PictureIO::Error例外が発生する' do
65 File.stub(:open).with(any_args()).and_raise(StandardError)
67 r = @io.get('test.get')
68 }.should raise_error(PictureIO::Error)
73 describe 'ファイル作成に於いて' do
75 File.open @path + 'test.put', 'w' do |f|
79 context 'ベースディレクトリに作成するとき' do
81 @io.put('created', 'create.put')
84 File.exist?(@path + 'create.put').should be_true
86 it 'createdが書きこまれている' do
87 d = File.open(@path + 'create.put').read
88 d.should match /create/
91 context '既存ファイルを更新するとき' do
93 @io.put('overwrited', 'test.put')
95 it 'overwritedが書きこまれている' do
96 d = File.open(@path + 'test.put').read
97 d.should match /overwrited/
100 d = File.open(@path + 'test.put').read
101 d.should_not match /already/
104 context 'サブディレクトリhに作成するとき' do
106 @io.put('subdirtest', 'testsub.put', 'h')
109 File.exist?(@path + 'h/testsub.put').should be_true
111 it 'subdirtestが書きこまれている' do
112 d = File.open(@path + 'h/testsub.put').read
113 d.should match /subdirtest/
116 context '例外が発生するとき' do
117 it 'PictureIO::Error例外が発生する' do
118 File.stub(:open).with(any_args()).and_raise(StandardError)
120 @io.put('bindata', 'test.put')
121 }.should raise_error(PictureIO::Error)
126 describe 'ファイル削除に於いて' do
128 File.open @path + 'test.del', 'w' do |f|
131 File.open @path + 'thumbnail/testsub.del', 'w' do |f|
135 context 'ベースディレクトリから削除するとき' do
137 @io.delete('test.del')
138 File.exist?(@path + 'test.del').should be_false
141 context 'サブディレクトリthumbnailから削除するとき' do
143 @io.delete('testsub.del', 'thumbnail')
144 File.exist?(@path + 'thumbnail/testsub.del').should be_false
147 context '例外が発生するとき' do
148 it 'PictureIO::Error例外が発生する' do
149 File.stub(:delete).with(any_args()).and_raise(StandardError)
151 @io.delete('test.del.not.exist')
152 }.should raise_error(PictureIO::Error)