gpt4 book ai didi

ruby - 是否可以使用 Ruby AWS SDK stub 文件上传?

转载 作者:数据小太阳 更新时间:2023-10-29 08:07:16 26 4
gpt4 key购买 nike

关闭我在 AWS Developers Guide 中发现的内容看着他们的 API Docs看起来我应该能够本地 stub upload_file。但是下面的代码不起作用,upload_file 只是返回 true

client = Aws::S3::Client.new(stub_responses: true)
client.stub_responses(:upload_file, false)

resource = Aws::S3::Resource.new(client: client)
obj = resource.bucket('foo').object('bar')

obj.upload_file(Tempfile.new('tmp')) #=> `true` when I want `false`

APIstub_responses 的第一个参数引用为 operation_name。这些示例经常使用名为 list_buckets 的操作,有时使用名为 head_bucket 的操作,但我找不到可接受的操作列表。是我读错了文档还是设置了错误的示例?

解决方法

作为解决方法,我使用 RSpec 来对方法进行 stub 。假设我在 obj 中得到相同的对象,上面的示例只需要以下内容就可以让我的测试通过

allow(obj).to receive(:upload_file).and_return(false)

最佳答案

快速查看您指出的 Api 文档后,我最好的猜测是 stub_response 只是对直接在 client 上进行的方法调用进行 stub ,这是一个实例Aws::S3::Client 类。

但是,您在 Aws::S3::Object 实例上执行 upload_fileclient.stub_reponses 不会 stub 方法。

关于ruby - 是否可以使用 Ruby AWS SDK stub 文件上传?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38575658/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com