Created
October 31, 2011 01:37
-
-
Save anonymous/1326710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
$stderr = stderr_orig | |
end | |
#$stderr.read | |
#binding.pry | |
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