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
25 PictureIO::LocalPicture.subdirs.is_a?(Array).should be_true
28 it 'カレント、サムネ、水平反転、垂直反転、水平垂直反転が返る' do
29 PictureIO::LocalPicture.subdirs.size.should eq 5
30 PictureIO::LocalPicture.subdirs.include?('').should eq true
31 PictureIO::LocalPicture.subdirs.include?('v').should eq true
32 PictureIO::LocalPicture.subdirs.include?('h').should eq true
33 PictureIO::LocalPicture.subdirs.include?('vh').should eq true
34 PictureIO::LocalPicture.subdirs.include?('thumbnail').should eq true
38 describe 'ファイル存在確認に於いて' do
41 context 'ファイルがあるとき' do
43 File.open @path + 'exist', 'w' do |f|
46 @io.exist?('exist').should be_true
49 context 'ファイルがないとき' do
51 @io.exist?('not.exist').should be_false
56 describe 'ファイル取得に於いて' do
58 File.open @path + 'test.get', 'w' do |f|
61 File.open @path + 'v/testsub.get', 'w' do |f|
65 context 'ベースディレクトリから取るとき' do
67 @io.get('test.get').should match /basedata/
70 context 'サブディレクトリvから取るとき' do
72 @io.get('testsub.get', 'v').should match /subdata/
75 context '例外が発生するとき' do
77 File.stub(:open).with(any_args()).and_raise(StandardError)
78 @io.get('test.get').should be_false
83 describe 'ファイル作成に於いて' do
85 File.open @path + 'test.put', 'w' do |f|
89 context 'ベースディレクトリに作成するとき' do
91 @io.put('created', 'create.put')
94 File.exist?(@path + 'create.put').should be_true
96 it 'createdが書きこまれている' do
97 d = File.open(@path + 'create.put').read
98 d.should match /create/
101 context '既存ファイルを更新するとき' do
103 @io.put('overwrited', 'test.put')
105 it 'overwritedが書きこまれている' do
106 d = File.open(@path + 'test.put').read
107 d.should match /overwrited/
110 d = File.open(@path + 'test.put').read
111 d.should_not match /already/
114 context 'サブディレクトリhに作成するとき' do
116 @io.put('subdirtest', 'testsub.put', 'h')
119 File.exist?(@path + 'h/testsub.put').should be_true
121 it 'subdirtestが書きこまれている' do
122 d = File.open(@path + 'h/testsub.put').read
123 d.should match /subdirtest/
126 context '例外が発生するとき' do
128 File.stub(:open).with(any_args()).and_raise(StandardError)
129 @io.put('bindata', 'test.put').should be_false
134 describe 'ファイル削除に於いて' do
136 File.open @path + 'test.del', 'w' do |f|
139 File.open @path + 'thumbnail/testsub.del', 'w' do |f|
143 context 'ベースディレクトリから削除するとき' do
145 @io.delete('test.del')
146 File.exist?(@path + 'test.del').should be_false
149 context 'サブディレクトリthumbnailから削除するとき' do
151 @io.delete('testsub.del', 'thumbnail')
152 File.exist?(@path + 'thumbnail/testsub.del').should be_false
155 context '例外が発生するとき' do
157 File.stub(:delete).with(any_args()).and_raise(StandardError)
158 @io.delete('test.del.not.exist').should be_false