我正在尝试测试我是否能够捕获这些 AWS 异常:
begin
s3_client = S3Client.new
s3_file = s3_client.write_s3_file(bucket, file_name, file_contents)
rescue AWS::Errors::ServerError, AWS::Errors::ClientError => e
# do something
end
我的 Rspec 3 代码:
expect_any_instance_of(S3Client).to receive(:write_s3_file).and_raise(AWS::Errors::ServerError)
但是当我测试这个存根时,我得到一个 TypeError:
exception class/object expected
我必须包含 AWS::Errors::ServerError 吗?如果是这样,我该怎么做?我正在使用 aws-sdk-v1 gem。
谢谢。