Testing controllers with Minitest

99miles picture 99miles · Sep 4, 2012 · Viewed 16.4k times · Source

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.

Answer

blowmage picture blowmage · Sep 4, 2012

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