O'Reilly logo

Rails 4 Test Prescriptions by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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
post :create, project: {name: ​"Runway"​, tasks: ​"start something:2"​}
assert_redirected_to projects_path
assert_equal ​"Runway"​, assigns[:action].project.name
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 previously. The post method triggers the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required