Testing controllers with Minitest

独自空忆成欢 提交于 2019-12-06 20:16:23

问题


I'm trying to find examples of testing controllers with Minitest, but I've only found a couple and the just verify what template is rendered and that 'success' is returned. That doesn't seem very helpful to me. Is Minitest used to test controllers?

The Railscast ( http://railscasts.com/episodes/327-minitest-with-rails ) and a couple other posts I've found seem to do model tests with Minitest and integration tests with Capybara.

What about controller tests? Can they be tested with Minitest? If so, are there any real-world examples that actually test the actions? It seems very odd that I can't find any after literally hours of searching.

I know this is vague, but I'm trying to decide if I should go with RSpec or Minitest, but without having a clue how to truly test a controller with Minitest, I'm not seeing how it's even really an option, yet I keep reading some general rave reviews about it.


回答1:


Yes, you can use Minitest to test a controller. Testing a controller using Minitest is no different than testing a controller using Test::Unit. Any examples you find, like the Rails Guide, are supported.

http://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers



来源:https://stackoverflow.com/questions/12256533/testing-controllers-with-minitest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!