简体   繁体   中英

How can I properly test my gem that uses Fog Storage to download from AWS S3?

I see the Fog gem has some ability to mock but the references/examples seem to not show much in this area. I am building a gem that uses Fog Storage to download files from S3 and I'd like to implement proper tests but without requiring it to actually interact with S3 during the test-run(s). Can this be mocked out or should I create a public S3 bucket for testing?

You should be able to just do Fog.mock! in your test setup and subsequent calls will then be made in a mocked way without extra work. I'll note, however, that you need to include all interactions you might have. ie when you first start with a mocked fog connection, no directories (buckets in S3 parlance) exist, so either in the tests or in the setup you should create a directory to use for your objects. From there you should be able to create/destroy/etc without every touching S3. To be more certain, you can certainly make a point of having obviously fake S3 credentials for test environment (so that if you forgot to include the mock! call, for instance, it wouldn't run on your real stuff). Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM