Minitest and Views

In Rails and Minitest, view testing takes place inside the controller or integration tests. Here’s an example from the projects controller:

minitest/01/gatherer/test/controllers/projects_controller_test.rb
​ 
test ​"the index method displays all projects correctly"​ ​do​
​ 
on_schedule = Project.create!(due_date: 1.year.from_now,
​ 
name: ​"On Schedule"​,
​ 
tasks: [Task.create!(completed_at: 1.day.ago, size: 1)])
​ 
behind_schedule = Project.create!(due_date: 1.day.from_now,
​ 
name: ​"Behind Schedule"​,
​ 
tasks: [Task.create!(size: 1)])
​ 
get :index
​ 
assert_select(​"#project_​#{on_schedule.id}​ .on_schedule"​)
​ 
assert_select(​"#project_​#{behind_schedule.id}​ .behind_schedule" ...

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.