如何测试double,mock或stub控制器端对象(How to test double, mock or stub controller side object)
我正在编写一个控制器测试,我想验证Controller1的call_dashboard_function。
class Controller1 < ApplicationController before_action :init_dashb def call_dashboard_function @dashb.do_something! end def init_dashb @dashb ||= Dashboard.new(current_user) end end class Dashboard #... this is a facade class end
实际测试:
test "should do something" do sign_in @user patch :call_dashboard_function end
问题是我不想测试仪表板类,因为我有一个单独的测试。 所以我想模拟,存根等等这类行为
如果我从外面访问,那将很容易。 但我无法从控制器外部看到仪表板类。
I'm writing a controller test, and I wanted to verify Controller1's call_dashboard_function.
class Controller1 < ApplicationController before_action :init_dashb def call_dashboard_function @dashb.do_something! end def init_dashb @dashb ||= Dashboard.new(current_user) end end class Dashboard #... this is a facade class end
Actual test:
test "should do something" do sign_in @user patch :call_dashboard_function end
The problem is I don't want to test the dashboard class, since I have a separated test for it. So I'd like to mock, stub, etc this class behavior
That would be easy if I had access from outside. But I can't see dashboard class from outside the controller.
原文:https://stackoverflow.com/questions/40708887
最满意答案
是的,一切都发生在AuthorizeRequest期间,因为这允许在ProcessRequest之前将请求重写为静态文件(如果缓存)。
Yes, everything happens during AuthorizeRequest, as this permits the request to be rewritten to a static file (if cached) prior to ProcessRequest.
相关问答
更多-
是的,一切都发生在AuthorizeRequest期间,因为这允许在ProcessRequest之前将请求重写为静态文件(如果缓存)。 Yes, everything happens during AuthorizeRequest, as this permits the request to be rewritten to a static file (if cached) prior to ProcessRequest.
-
避免不惜一切代价直接使用System.Drawing - 它充满了内存泄漏,并发问题和编码错误 。 ImageResizer为您处理和避免这些问题,并提供Watermarking插件以及SampleOverlay示例插件,以向您展示如果Watermark无法满足您的需求,可以安全地创建自己的插件。 如果我想要获得Bitmap结果,您可以将typeof(Bitmap)作为'destination'参数传递给ImageJob,并从.Result属性访问Bitmap实例。 其他后果: 除非将其置于finally( ...
-
您应该检查事件委托类型。 来自msdn : 公共事件EventHandler AuthorizeRequest 因此, AuthorizeRequest委托是EventHandler 。 来自msdn : public delegate void EventHandler(Object sender,EventArgs e) AuthorizeRequest参数: 对象发送者 EventArgs e You should check event delegate type. From msdn: publi ...
-
使用ImageResizer.Net,您可以为宽度指定(?w = 96)和height =(&h = 96)并决定缩放模型,例如(&mode = max) 但是,您无法指定最大尺寸,您可以尝试使用文件格式(格式= gif | png | jpg)或/和质量(q = 50(0..100))来查找一系列图像的最佳设置 有关更多信息,请访问http://imageresizing.net/docs/basics 谢谢 巴蒂尔 With ImageResizer.Net you can specify with ( ...
-
尝试在ImageResizer中实现IVirtualImageProvider(Trying to implement IVirtualImageProvider in ImageResizer)[2021-06-03]
好吧,看起来我找到了自己的解决方案。 这是问题所在: return (virtualPath.StartsWith("assets", StringComparison.OrdinalIgnoreCase) StartsWith将始终返回false,因为virtualPath将以我的主机名开头。 切换到Contains()语句可以完美地工作。 很棒的插件,顺便说一下! Well, looks like I found my own solution. Here's the problem: return ... -
是的,disckcache文件夹是自定义为/ images /而不是/ imagecache / 通过升级到ImageResizer 3.4.1(从3.3或3.4)和随附的更新的DiskCache插件修复了此问题。 Yes, the disckcache folder was customised to /images/ instead of /imagecache/ This issue was fixed by upgrading to ImageResizer 3.4.1 (from 3.3 or 3 ...
-
ImageResizer .eps支持(ImageResizer .eps support)[2022-03-07]
ImageResizer不支持.eps,但Ghostscript支持。这是PdfRenderer的基础。 我建议修改/分支PdfRenderer以引入.eps支持。 我们没有任何计划正式支持这一点,但我们肯定会将添加了该功能的pull请求合并到PdfRenderer。 我们的大部分努力(re:pdf)将在PdfiumRenderer上进行 ,后者具有更好的特性。 ImageResizer doesn't support .eps, but Ghostscript does, which underlies ... -
重复imageresizer水印(Repeat imageresizer watermark)[2022-05-19]
不,不支持此功能。 您可以创建一个插件,可以很容易地在背景上平铺图像 - 但是从BuilderExtension继承并覆盖PostRenderBackground 。 为什么不使用CSS呢? No, this feature isn't supported. You could create a plugin that tiles an image on the background pretty easily, though - inherit from BuilderExtension and over ... -
ImageResizer错误(ImageResizer error)[2024-02-22]
您在提供代码之前使用过logo.InputStream (可能用于其他工作)。 在using语句之前,您可以再次读取图像或将建议的异常放在下面的代码中 logo.InputStream.Seek(0, SeekOrigin.Begin); You have used logo.InputStream before provided code (maybe for other job). You can read image again or as exception suggested put below ... -
扫描仪仍然添加exif旋转数据。 请分享您的诊断页面,以便我们了解您在做什么。 通常你会添加&autorate=true或全局设置它:
请参见: 如何在ImageResizer中使用autorotate插件 ImageResizer旋转问题 为什么ImageResizer自动旋转图像垂直拍摄并显示水平 Scanners still add exif rotation data. Please sha ...