Minitest and Rails Controllers

Rails provides a different subclass of ActiveSupport::Test for testing controllers. It’s called ActionController::TestCase. Controller tests look like this:

minitest/01/gatherer/test/controllers/projects_controller_test.rb
​Line 1 
test ​"the project method creates a project"​ ​do​
​2 
post :create, project: {name: ​"Runway"​, tasks: ​"start something:2"​}
​3 
assert_redirected_to projects_path
​4 
assert_equal ​"Runway"​, assigns[:action].project.name
​5 
​end​

This test simulates a call to a controller method, skipping Rails routing, and then allows us to make assertions about what the controller does.

This test’s code is very similar to the RSpec controller test we wrote ...

Get Rails 4 Test Prescriptions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.