fake-aws-sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Using this, rather than "gemspec", so that "bundle console" works
4
+ gem "fake-aws-sdk", :path => ".", :require => "fake_aws"
5
+
6
+ group :test do
7
+ gem "rake"
8
+ gem "rspec", "~> 2.11.0"
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mike Williams
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # FakeAWS
2
+
3
+ A fake implementation of the AWS Ruby SDK, for testing.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fake-aws-sdk'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fake-aws-sdk
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+
5
+ task "default" => "spec"
6
+
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.pattern = 'spec/**/*_spec.rb'
9
+ t.rspec_opts = ["--colour", "--format", "nested"]
10
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fake_aws/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "fake-aws-sdk"
8
+ gem.version = FakeAWS::VERSION
9
+ gem.authors = ["Mike Williams"]
10
+ gem.email = ["mdub@dogbiscuit.org"]
11
+ gem.description = %q{Fake implementation of AWS SDK}
12
+ gem.summary = gem.description
13
+ gem.homepage = "http://github.com/cogent/fake-aws-sdk"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ end
@@ -0,0 +1 @@
1
+ require "fake_aws"
@@ -0,0 +1,20 @@
1
+ require "fake_aws/s3/object_collection"
2
+
3
+ module FakeAWS
4
+ module S3
5
+
6
+ class Bucket
7
+
8
+ def initialize(name)
9
+ @name = name
10
+ @objects = ObjectCollection.new(self)
11
+ end
12
+
13
+ attr_reader :name
14
+ attr_reader :objects
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,28 @@
1
+ require "fake_aws/s3/s3_object"
2
+ require "forwardable"
3
+
4
+ module FakeAWS
5
+ module S3
6
+
7
+ class ObjectCollection
8
+
9
+ def initialize(bucket)
10
+ @bucket = bucket
11
+ @objects = Hash.new do |h, key|
12
+ h[key] = S3Object.new(self, key)
13
+ end
14
+ end
15
+
16
+ def [](key)
17
+ key = key.to_s
18
+ @objects[key]
19
+ end
20
+
21
+ extend Forwardable
22
+
23
+ def_delegators :@objects, :count
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,42 @@
1
+ module FakeAWS
2
+ module S3
3
+
4
+ class S3Object
5
+
6
+ def initialize(bucket, key)
7
+ @bucket = bucket
8
+ @key = key
9
+ end
10
+
11
+ attr_reader :bucket
12
+ attr_reader :key
13
+
14
+ def write(data)
15
+ data = data.read if data.respond_to?(:read)
16
+ @data = data
17
+ end
18
+
19
+ def read
20
+ must_exist!
21
+ @data
22
+ end
23
+
24
+ def content_length
25
+ must_exist!
26
+ @data.length
27
+ end
28
+
29
+ def exists?
30
+ !!@data
31
+ end
32
+
33
+ private
34
+
35
+ def must_exist!
36
+ raise KeyError unless exists?
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,2 @@
1
+ require "fake_aws/s3/bucket"
2
+ require "fake_aws/s3/s3_object"
@@ -0,0 +1,3 @@
1
+ module FakeAWS
2
+ VERSION = "0.0.1"
3
+ end
data/lib/fake_aws.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "fake_aws/version"
2
+
3
+ require "fake_aws/s3"
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+
3
+ require "fake_aws/s3/bucket"
4
+
5
+ describe FakeAWS::S3::Bucket do
6
+
7
+ let(:bucket) { described_class.new("foo") }
8
+
9
+ it "has a name" do
10
+ bucket.name.should eq("foo")
11
+ end
12
+
13
+ let(:objects) { bucket.objects }
14
+
15
+ describe "#objects" do
16
+
17
+ it "starts empty" do
18
+ objects.count.should be_zero
19
+ end
20
+
21
+ end
22
+
23
+ describe "#objects['key']" do
24
+
25
+ it "returns an S3Object" do
26
+ objects["foo"].should be_kind_of(FakeAWS::S3::S3Object)
27
+ end
28
+
29
+ it "always returns the same S3Object" do
30
+ objects["foo"].should equal(objects["foo"])
31
+ end
32
+
33
+ it "converts Symbol keys to String" do
34
+ objects["foo"].should equal(objects[:foo])
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,88 @@
1
+ require "spec_helper"
2
+
3
+ require "fake_aws/s3/bucket"
4
+ require "fake_aws/s3/s3_object"
5
+
6
+ describe FakeAWS::S3::S3Object do
7
+
8
+ let(:bucket) { FakeAWS::S3::Bucket.new("test-bucket") }
9
+
10
+ let(:object) { FakeAWS::S3::S3Object.new(bucket, "test-object") }
11
+
12
+ subject { object }
13
+
14
+ describe "#key" do
15
+ it "returns the object key" do
16
+ subject.key.should eq("test-object")
17
+ end
18
+ end
19
+
20
+ context "before it has been written" do
21
+
22
+ it { should_not exist }
23
+
24
+ describe "#read" do
25
+
26
+ it "raises a KeyError" do
27
+ lambda { object.read }.should raise_error(KeyError)
28
+ end
29
+
30
+ end
31
+
32
+ describe "#content_length" do
33
+
34
+ it "raises a KeyError" do
35
+ lambda { object.content_length }.should raise_error(KeyError)
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+
42
+ context "after being written" do
43
+
44
+ let(:data) { "foobarbaz" }
45
+
46
+ before do
47
+ object.write(data)
48
+ end
49
+
50
+ it { should exist }
51
+
52
+ describe "#read" do
53
+
54
+ it "returns the data written" do
55
+ object.read.should eq(data)
56
+ end
57
+
58
+ end
59
+
60
+ describe "#content_length" do
61
+
62
+ it "returns the size of data written" do
63
+ object.content_length.should eq(data.length)
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ describe "#write" do
71
+
72
+ context "with an IO object" do
73
+
74
+ let(:data) { "stream-of-stuff" }
75
+
76
+ before do
77
+ object.write(StringIO.new(data))
78
+ end
79
+
80
+ it "saves the streamed data" do
81
+ object.read.should eq(data)
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1 @@
1
+ require "aws-sdk"
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fake-aws-sdk
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Mike Williams
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Fake implementation of AWS SDK
15
+ email:
16
+ - mdub@dogbiscuit.org
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - fake-aws-sdk.gemspec
27
+ - lib/fake-aws-sdk.rb
28
+ - lib/fake_aws.rb
29
+ - lib/fake_aws/s3.rb
30
+ - lib/fake_aws/s3/bucket.rb
31
+ - lib/fake_aws/s3/object_collection.rb
32
+ - lib/fake_aws/s3/s3_object.rb
33
+ - lib/fake_aws/version.rb
34
+ - spec/fake-aws/s3/bucket_spec.rb
35
+ - spec/fake-aws/s3/s3_object_spec.rb
36
+ - spec/spec_helper.rb
37
+ homepage: http://github.com/cogent/fake-aws-sdk
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ segments:
49
+ - 0
50
+ hash: 4095608689954055844
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ hash: 4095608689954055844
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.24
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Fake implementation of AWS SDK
67
+ test_files:
68
+ - spec/fake-aws/s3/bucket_spec.rb
69
+ - spec/fake-aws/s3/s3_object_spec.rb
70
+ - spec/spec_helper.rb