require 'spec_helper' describe Heirloom do before do @config_double = double 'config' @logger_double = double 'logger', :debug => true, :info => true @s3_double = double 's3_double' @config_double.stub :logger => @logger_double @verifier = Heirloom::Verifier.new :config => @config_double, :name => 'heirloom-name' end context "verifying all buckets exist" do before do Heirloom::AWS::S3.should_receive(:new). with(:config => @config_double, :region => 'us-west-1'). and_return @s3_double Heirloom::AWS::S3.should_receive(:new). with(:config => @config_double, :region => 'us-east-1'). and_return @s3_double end it "should return false if a bucket does not exist in a region" do @s3_double.should_receive(:get_bucket).with('bucket123-us-west-1'). and_return nil @s3_double.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_double.should_receive(:get_bucket).with('bucket123-us-west-1'). and_return 'an s3 bucket' @s3_double.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 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_double, :region => 'us-west-1'). and_return @s3_double @s3_double.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_double, :region => 'us-west-1'). and_return @s3_double @s3_double.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