Skip to content

Instantly share code, notes, and snippets.

@banister
Forked from anonymous/gist:1326710
Created October 31, 2011 01:43
Show Gist options
  • Save banister/1326715 to your computer and use it in GitHub Desktop.
Save banister/1326715 to your computer and use it in GitHub Desktop.
require "file2s3/version"
require 'fileutils'
require 'pathname'
class File2s3
S3_DIRS = %w(30days_of_uploads_to_s3 to_upload_to_s3)
def initialize(opts)
@access_key = opts[:access_key]
@secret_key = opts[:secret_key]
end
def create_dirs(scratch_dir)
scratch_dir = Pathname.new(scratch_dir) unless scratch_dir.class == Pathname
FileUtils.mkdir_p(scratch_dir) unless scratch_dir.directory?
S3_DIRS.each do |d|
dir = scratch_dir + Pathname.new(d)
unless dir.directory?
FileUtils.mkdir(dir)
$stderr.puts "Created S3 Directory: #{dir}"
end
end
end
end
require 'spec_helper'
def capture_stderr
stderr_orig = $stderr
$stderr = StringIO.new
begin
yield
ensure
output = $stderr.string
$stderr = stderr_orig
end
output
end
describe File2s3 do
before(:each) do
@f2s3 = File2s3.new(access_key: 'acckey', secret_key: 'seckey')
@scratch_dir = Dir.mktmpdir('scratch_dir')
end
it "should return a list of scratch folder dirs" do
File2s3::S3_DIRS.should == [ "30days_of_uploads_to_s3",
"to_upload_to_s3" ]
end
it "should output the created directories to STDERR" do
output = capture_stderr do
@f2s3.create_dirs(@scratch_dir)
$stderr.read
end
output.should == 'some dir name'
end
end
[file2s3 (master)]$ rspec .
.F
Failures:
1) File2s3 should output the created directories to STDERR
Failure/Error: output.should == 'some dir name'
expected: "some dir name"
got: "" (using ==)
# ./spec/file2s3_spec.rb:31:in `block (2 levels) in <top (required)>'
Finished in 1.42 seconds
2 examples, 1 failure
Failed examples:
rspec ./spec/file2s3_spec.rb:26 # File2s3 should output the created directories to STDERR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment