1 # -*- encoding: utf-8 -*-
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::S3Picture do
20 @io = PictureIO::S3Picture.new @path
23 describe 'サブディレクトリに於いて' do
25 PictureIO::S3Picture.subdirs.is_a?(Array).should be_true
28 it 'カレント、サムネ、水平反転、垂直反転、水平垂直反転が返る' do
29 PictureIO::S3Picture.subdirs.size.should eq 5
30 PictureIO::S3Picture.subdirs.include?('').should eq true
31 PictureIO::S3Picture.subdirs.include?('v').should eq true
32 PictureIO::S3Picture.subdirs.include?('h').should eq true
33 PictureIO::S3Picture.subdirs.include?('vh').should eq true
34 PictureIO::S3Picture.subdirs.include?('thumbnail').should eq true
38 describe 'ファイル存在確認に於いて' do
40 AWS::S3::S3Object.stub(:exist?).with(any_args).and_return(true)
42 context 'ベースディレクトリから取るとき' do
45 AWS::S3::S3Object.should_receive(:exist?).with(testname, @path).exactly(1)
49 context 'サブディレクトリvから取るとき' do
53 AWS::S3::S3Object.should_receive(:exist?).with(subd + '/' + testname, @path).exactly(1)
54 @io.exist?(testname, subd)
57 context '例外が発生するとき' do
58 it 'PictureIO::Error例外が発生する' do
59 AWS::S3::S3Object.stub(:exist?).with(any_args()).and_raise(StandardError)
61 @io.exist?('test.get')
62 }.should raise_error(PictureIO::Error)
67 describe 'ファイル取得に於いて' do
70 context 'ベースディレクトリから取るとき' do
73 AWS::S3::S3Object.should_receive(:stream).with(testname, @path).exactly(1)
77 AWS::S3::S3Object.stub(:stream).with(any_args()).and_yield('data')
78 @io.get('test.get').should eq 'data'
81 context 'サブディレクトリvから取るとき' do
85 AWS::S3::S3Object.should_receive(:stream).with(subd + '/' + testname, @path).exactly(1)
86 @io.get(testname, subd)
90 AWS::S3::S3Object.stub(:stream).with(any_args()).and_yield('data')
91 @io.get('test.get', subd).should eq 'data'
94 context '例外が発生するとき' do
95 it 'PictureIO::Error例外が発生する' do
96 AWS::S3::S3Object.stub(:get).with(any_args()).and_raise(StandardError)
99 }.should raise_error(PictureIO::Error)
104 describe 'ファイル作成に於いて' do
107 context 'ベースディレクトリに作成するとき' do
110 AWS::S3::S3Object.should_receive(:store).with(testname, 'bindata', @path).exactly(1)
111 @io.put('bindata', testname)
114 context 'サブディレクトリvに作成するとき' do
118 AWS::S3::S3Object.should_receive(:store).with(subd + '/' + testname, 'bindata', @path).exactly(1)
119 @io.put('bindata', testname, subd)
122 context '例外が発生するとき' do
123 it 'PictureIO::Error例外が発生する' do
124 AWS::S3::S3Object.stub(:store).with(any_args()).and_raise(StandardError)
126 @io.put('bindata', 'test.put')
127 }.should raise_error(PictureIO::Error)
132 describe 'ファイル削除に於いて' do
135 context 'ベースディレクトリから削除するとき' do
138 AWS::S3::S3Object.should_receive(:delete).with(testname, @path).exactly(1)
142 context 'サブディレクトリvhから削除するとき' do
146 AWS::S3::S3Object.should_receive(:delete).with(subd + '/' + testname, @path).exactly(1)
147 @io.delete(testname, subd)
150 context '例外が発生するとき' do
151 it 'PictureIO::Error例外が発生する' do
152 AWS::S3::S3Object.stub(:delete).with(any_args()).and_raise(StandardError)
154 @io.delete('test.del.not.exist')
155 }.should raise_error(PictureIO::Error)