Instantly share code, notes, and snippets.

Embed
What would you like to do?
FakeS3 automation for rspec
test:
s3_endpoint: localhost
s3_force_path_style: true
s3_port: 10001
use_ssl: false
access_key_id: key
secret_access_key: secret
class FakeS3Server
require 'fakes3'
def initialize(pid)
@pid = pid
end
def self.up
pid = spawn("bundle exec fakes3 --port 10001 --root #{Rails.root.join('fakes3')}")
@@instance = FakeS3Server.new(pid)
return @@instance
end
def self.down
@@instance.down if defined? @@instance
end
def down
if @pid
Process.kill("SIGINT", @pid)
Process.waitpid2(@pid)
@pid = nil
end
end
end
# Make sure you have the fakes3 gem installed
group :test do
gem 'fakes3'
end
# Require support/fakes3 which has the FakeS3Server class, you can save the file anywhere you want
# Call up before and down after
require 'support/fakes3_server'
RSpec.configure do |config|
config.before(:suite) { FakeS3Server.up }
config.after(:suite) { FakeS3Server.down }
end
@cesarandreu

This comment has been minimized.

Owner

cesarandreu commented Nov 15, 2014

You'll also need to create a fakes3 folder in your project root. Anything you save or get will be in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment