如何在 Rspec 中存根载波? [英] How to stub carrierwave in Rspec?

查看:22
本文介绍了如何在 Rspec 中存根载波?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存根carrierwave 以防止它在我的测试期间获取网络上的图像.我将如何存根以实现这一目标?

I want to stub carrierwave to prevent it from fetch images on the web during my tests. How would I stub things to achieve this?

我的爬虫解析远程网页,并将一个图片网址保存到模型中.Carrierwave 将在保存操作期间自动获取该图像.它运作良好.

My crawler parses a remote web page, and saves one image url into the model. Carrierwave will fetch that image automatically during the save operation. It works well.

但是我有一个关于页面解析的测试,每次都会下载文件,导致测试速度变慢.

However I have a test about the parsing of pages, and every-time it will download the file, which slows down the testing.

更新:

我按如下方式安装上传器(在预先存在的回形针列中)

I mount the uploader as the following (in the pre-existing paperclip column)

mount_uploader :image, TopicImageUploader, :mount_on => :image_file_name

我试图存根以下内容,但都没有奏效:

I tried to stub the following, but neither worked:

Topic.any_instance.stub(:store_image!)
Topic.any_instance.stub(:store_image_file_name!)
Topic.any_instance.stub(:store_image_remote_url!)

推荐答案

TopicImageUploader.any_instance.stub(:download!)

这篇关于如何在 Rspec 中存根载波?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆