![](/img/trans.png)
[英]Rspec controller test - how to pass arguments to a method I'm testing
[英]RSpec / Rails - How do I test that a method in ApplicationController is called (when I'm testing a subclassed controller)?
标题说明了一切。
我有一个控制器动作,我在其中执行一些操作,然后调用ApplicationController
定义的方法。
我如何测试它被调用?
controller.should_receive(:the_method_name)
不起作用。
ApplicationController.should_receive(:the_method_name)
不起作用。
什么是正确的语法?
谢谢。
我想你可以使用匿名控制器来测试你的ApplicationController,查看文档。
使用AnonymousController作为Gerep建议并调用controller.should_receive(:the_method_name)
应该这样做。
测试中的位置对于让测试成功通过非常重要。 举个例子:
describe 'my test' do
before do
controller.should_receive(:the_method)
get :action
end
it { should render_template(:your_template) }
end
这个例子应该传递并测试调用:the_method
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.