spec/s3_spec.rb in massive_sitemap-writer-s3-0.0.1.rc2 vs spec/s3_spec.rb in massive_sitemap-writer-s3-0.0.1.rc3
- old
+ new
@@ -1,24 +1,49 @@
require "spec_helper"
+require "fileutils"
describe MassiveSitemap::Writer::S3 do
- let(:service) { }
- let(:bucket) { "example" }
- let(:writer) { MassiveSitemap::Writer::S3.new(service, bucket) }
+ let(:object) { mock('object', :"content=" => [], :save => nil) }
+ let(:objects) { mock('objects', :find_all => [], :build => object) }
+ let(:bucket) { mock('bucket', :objects => objects) }
+ let(:service) { mock('service', :buckets => mock('buckets', :find => bucket)) }
+ let(:writer) { MassiveSitemap::Writer::S3.new(s3_options) }
+ let(:s3_options) { Hash.new(:access_key_id => "ak", :secret_access_key => "sa", :bucket => "bucket") }
- it "works" do
- # writer.close_stream(stream)
-
+ before do
+ ::S3::Service.stub(:new).and_return(service)
end
describe "initialize" do
- # @stream_ids.clear
- it "doesn't take streams ids from disk" do
+ it "creates service" do
+ ::S3::Service.should_receive(:new).with(s3_options).and_return(service)
+ writer
end
+
+ it "get S3 object service" do
+ bucket.should_receive(:objects).and_return(objects)
+ writer
+ end
end
describe "close_stream" do
- it "uploads to amazon" do
- end
+ let(:filename) { "sitemap.xml.gz" }
+ before do
+ writer.init!
+ end
+
+ after do
+ FileUtils.rm(filename)
+ end
+
+ it "uploads to amazon" do
+ objects.should_receive(:build).with(filename).and_return(object)
+ writer.close!
+ end
+
+ it "retries on fails" do
+ object.should_receive(:"content=").once().and_raise
+ object.should_receive(:"content=").once().and_return(true)
+ writer.close!
+ end
end
end
-