require 'spec_helper' describe Hillary::Slug::Bucket do around(:each) do |example| Fog.mock! example.run Fog.unmock! end let(:access_key){'public'} let(:secret_key){'secret'} let(:storage){Fog::Storage.new(provider: 'AWS', aws_access_key_id: access_key, aws_secret_access_key: secret_key)} let(:bucket_name){'slugbucket'} let(:bucket){storage.directories.get(bucket_name)} let(:slug_name){'g3_slug_RC2014_01_01_01_01_01.tar.gz'} let(:canonical_slug_name){'g3_slug_b26206aaf36207304d4fa583ce9837d0bdb48966.tar.gz'} let(:slug_path){'rc/' + slug_name} let(:canonical_slug_path){'dev/' + canonical_slug_name} let(:slug){bucket.files.get(slug_name)} let(:canonical_slug){bucket.files.get(canonical_slug_name)} let(:slug_file){Tempfile.new(slug_name)} let(:slug_file_path){slug_file.path} before(:each){storage.directories.create(key: bucket_name)} subject{Hillary::Slug::Bucket.new(bucket_name, access_key, secret_key)} describe '#exists?' do it 'returns false when the file does not exist' do expect(subject.exists?(canonical_slug_path)).to be_falsy end it 'returns true when the file does exist' do bucket.files.create(key: canonical_slug_path, body: StringIO.new(''), public: false) expect(subject.exists?(canonical_slug_path)).to be_truthy end end describe '#write' do it 'writes the file to the bucket with the given name' do subject.write(canonical_slug_path, slug_file_path) expect(bucket.files.get(canonical_slug_path).body).to eq('') end end describe '#copy' do it 'copies the specified file to the specified location' do subject.write(canonical_slug_path, slug_file_path) subject.copy(canonical_slug_path, slug_path) expect(bucket.files.get(slug_path)) end end end