title: Stubbing AWS S3 object request
body: <p>I'm trying to stub out a request to get an object in a AWS bucket. I've read their docs about stubbing requests and was only able to stub out a bucket, not an object. Here are somethings I've tried:</p>
  
  <p>Stubbing through the AWS config:</p>
  
  <pre><code>Aws.config[:s3] = {
    stub_responses: {
      list_buckets: {
        buckets: [name: "my-bucket"],
        list_objects: [key: "file.pdf"]
      }
    }
  }
  </code></pre>
  
  <p>While that got the bucket, it did not give me the object. Calling <code>s3.buckets</code> would list the bucket, but <code>s3.objects</code> would be empty.</p>
  
  <p>Stubbing through <code>webmock</code> gem:</p>
  
  <pre><code>tempfile = file_fixture('file.pdf').read
  base_uri = Regexp.new "https://my-bucket.s3.us-west-1.amazonaws.
  stub_request(:get, base_uri).to_return(status: 200, body: tempfile)
  </code></pre>
  
  <p>This still doesn't seem to work. Calling <code>bucket.objects</code> still returns an empty collection.</p>
  
  <p>The code in my controller I want to test:</p>
  
  <pre><code>s3 = Aws::S3::Resource.new
  bucket = s3.bucket("my-bucket")
  @files = {}
  
  bucket.objects.each do |item|
    @files[File.basename(item.key)] = item.presigned_url(:get)
  end
  </code></pre>
  
  <p>The goal is I want to make sure my view shows the links to the objects in my <code>@file</code> variable and I want to test that link. Any help would be greatly appreciated! I'm new to developing with AWS S3 and googlge haven't been much help. I'm using the <code>aws-sdk-s3</code> gem to work with AWS S3.</p>