Skip to content

Instantly share code, notes, and snippets.

@cesarandreu
Created November 15, 2014 00:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cesarandreu/d7fa6dc4cb4f8297955f to your computer and use it in GitHub Desktop.
Save cesarandreu/d7fa6dc4cb4f8297955f to your computer and use it in GitHub Desktop.
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
Copy link
Author

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