How to call a different post to a different controller in Rails Functional Test
I want to make a post request to a different controller inside my functional test which is intended 开发者_JAVA百科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.
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
[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.]
精彩评论