spec/archive/verifier_spec.rb in heirloom-0.5.0rc3 vs spec/archive/verifier_spec.rb in heirloom-0.5.0rc4

- old
+ new

@@ -2,37 +2,69 @@ describe Heirloom do before do @config_mock = double 'config' - @logger_mock = double 'logger' + @logger_stub = stub 'logger', :debug => true @s3_mock = double 's3_mock' - @config_mock.should_receive(:logger).and_return(@logger_mock) + @config_mock.stub :logger => @logger_stub @verifier = Heirloom::Verifier.new :config => @config_mock, :name => 'heirloom-name' end - it "should return false if a bucket does not exist" do - Heirloom::AWS::S3.should_receive(:new). - with(:config => @config_mock, - :region => 'us-west-1'). - and_return @s3_mock - @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1'). - and_return nil - @logger_mock.should_receive(:debug) - @verifier.buckets_exist?(:bucket_prefix => 'bucket123', - :regions => ['us-west-1']).should be_false + context "verifying all buckets exist" do + before do + Heirloom::AWS::S3.should_receive(:new). + with(:config => @config_mock, + :region => 'us-west-1'). + and_return @s3_mock + Heirloom::AWS::S3.should_receive(:new). + with(:config => @config_mock, + :region => 'us-east-1'). + and_return @s3_mock + end + it "should return false if a bucket does not exist in a region" do + @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1'). + and_return nil + @s3_mock.should_receive(:get_bucket).with('bucket123-us-east-1'). + and_return 'an s3 bucket' + @verifier.buckets_exist?(:bucket_prefix => 'bucket123', + :regions => ['us-west-1', 'us-east-1']). + should be_false + end + + it "should true if all buckets exist" do + @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1'). + and_return 'an s3 bucket' + @s3_mock.should_receive(:get_bucket).with('bucket123-us-east-1'). + and_return 'an s3 bucket' + @verifier.buckets_exist?(:bucket_prefix => 'bucket123', + :regions => ['us-west-1', 'us-east-1']). + should be_true + end end - it "should true if all buckets exist" do - Heirloom::AWS::S3.should_receive(:new). - with(:config => @config_mock, - :region => 'us-west-1'). - and_return @s3_mock - @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1'). - and_return 'an s3 bucket' - @logger_mock.should_receive(:debug) - @verifier.buckets_exist?(:bucket_prefix => 'bucket123', - :regions => ['us-west-1']).should be_true + context "verifying a single bucket exist" do + it "should return true if the given bucket does not exist in the region" do + Heirloom::AWS::S3.should_receive(:new). + with(:config => @config_mock, + :region => 'us-west-1'). + and_return @s3_mock + @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1'). + and_return 'an s3 bucket' + @verifier.bucket_exists?(:bucket_prefix => 'bucket123', + :region => 'us-west-1').should be_true + end + + it "should return false if the given bucket does not exist in the region" do + Heirloom::AWS::S3.should_receive(:new). + with(:config => @config_mock, + :region => 'us-west-1'). + and_return @s3_mock + @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1'). + and_return 'an s3 bucket' + @verifier.bucket_exists?(:bucket_prefix => 'bucket123', + :region => 'us-west-1').should be_true + end end end