Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing controllers with Minitest

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.

like image 722
99miles Avatar asked Sep 04 '12 03:09

99miles


People also ask

How do you run a Minitest test?

To run a Minitest test, the only setup you really need is to require the autorun file at the beginning of a test file: require 'minitest/autorun' . This is good if you'd like to keep the code small. A better way to get started with Minitest is to have Bundler create a template project for you.

How do I test a controller in Ruby on rails?

The currently accepted way to test rails controllers is by sending http requests to your application and writing assertions about the response. Rails has ActionDispatch::IntegrationTest which provides integration tests for Minitest which is the Ruby standard library testing framework.

What is Minitest in Ruby on rails?

What is Minitest? Minitest is a testing suite for Ruby. It provides a complete suite of testing facilities supporting test-driven development (TDD), behavior-driven development (BDD), mocking, and benchmarking. It's small, fast, and it aims to make tests clean and readable.


1 Answers

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

like image 164
blowmage Avatar answered Sep 18 '22 15:09

blowmage