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

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

问题描述

我想对载波进行桩头处理,以防止它在测试期间在网络上获取图像。

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?

我的搜寻器解析一个远程网页,并将一个图像URL保存到模型中。在保存操作期间,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天全站免登陆