如何在Rails功能测试中将不同的帖子调用到不同的控制器 [英] How to call a different post to a different controller in Rails Functional Test

查看:60
本文介绍了如何在Rails功能测试中将不同的帖子调用到不同的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的功能测试内针对另一个控制器发出不同的控制器的发布请求.但是ActiveController类中的post方法仅采用要调用的方法,而没有采用要调用的控制器名称.有什么想法如何调用其他控制器吗?

I want to make a post request to a different controller inside my functional test which is intended for a particular controller. However the post method in ActiveController class just takes the method to be called, it doesn't take the controller name to be called. Any ideas how to invoke a different controller?

推荐答案

使用

When you create tests for controllers using ActiveSupport::TestCase, you can set which controller to test when you don't want it inferred.

因此您可以在当前控制器的测试中添加另一个类,将控制器设置为在新类中针对该控制器进行测试,并实现您的测试用例.

So you could add another class to your test for the current controller, set the controller to test against within the new class, and implement your test cases.

您没有提供代码,所以我无法提供编码解决方案,但这是有关在RSpec下测试控制器上所有方法的博客文章:

You didn't provide code so I can't provide a coded solution but here's a blog post regarding testing all methods on controller under RSpec: http://blog.wolfman.com/articles/2007/7/28/rspec-testing-all-actions-of-a-controller

[个人而言,我离开了RSpec/TestUnit来进行控制器测试,而不仅仅是路线检查和模糊测试.对于涉及系统多个部分的东西,我非常喜欢集成测试(例如Cucumber).]

[Personally, I moved away from RSpec/TestUnit for controller tests beyond route checks and fuzzy testing. I much prefer integration testing (e.g. Cucumber) for something that involves multiple parts of the system.]

这篇关于如何在Rails功能测试中将不同的帖子调用到不同的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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