Created
November 15, 2014 00:25
-
-
Save cesarandreu/d7fa6dc4cb4f8297955f to your computer and use it in GitHub Desktop.
FakeS3 automation for rspec
This file contains hidden or 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
test: | |
s3_endpoint: localhost | |
s3_force_path_style: true | |
s3_port: 10001 | |
use_ssl: false | |
access_key_id: key | |
secret_access_key: secret |
This file contains hidden or 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
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 |
This file contains hidden or 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
# Make sure you have the fakes3 gem installed | |
group :test do | |
gem 'fakes3' | |
end |
This file contains hidden or 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll also need to create a
fakes3
folder in your project root. Anything you save or get will be in there.