# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration

require 'middleman-s3_sync'
require 'timerizer'
require 'rspec/its'
require 'rspec/support'
require 'digest/md5'
require 'cgi'

RSpec.configure do |config|
  config.run_all_when_everything_filtered = true
  config.filter_run :focus

  # Run specs in random order to surface order dependencies. If you find an
  # order dependency and want to debug it, you can fix the order by providing
  # the seed, which is printed after each run.
  #     --seed 1234
  config.order = 'random'

  config.before :all do
    Aws.config.update(
      region: 'us-east-1',
      credentials: Aws::Credentials.new('access_key_id', 'secret_access_key'),
      stub_responses: true
    )
  end
  
  # Helper method to create a mock S3 object
  def mock_s3_object(key, metadata = {})
    # Ensure key has no leading slash to match test expectations
    key = key.sub(/^\//, '')
    
    obj = double(
      key: key,
      metadata: metadata,
      etag: "\"#{Digest::MD5.hexdigest('test content')}\"",
      content_encoding: nil,
      cache_control: nil,
      website_redirect_location: nil
    )
    
    # Allow head method to return self for testing
    allow(obj).to receive(:head).and_return(obj)
    allow(obj).to receive(:put).and_return(true)
    allow(obj).to receive(:delete).and_return(true)
    
    obj
  end
  
  # Helper method to create a mock HeadObjectOutput
  def mock_head_object(metadata = {})
    double(
      metadata: metadata,
      etag: "\"#{Digest::MD5.hexdigest('test content')}\"",
      content_encoding: nil,
      cache_control: nil,
      website_redirect_location: nil
    )
  end
end
