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 Helper Tests

Rails provides the ActionView::TestCase class, which is a subclass of ActiveSupport::TestCase specifically designed to load enough of the Rails controller structure to enable helpers to be called and tested. Let’s look at the Minitest version of the name_with_status helper tests:

minitest/01/gatherer/test/helpers/projects_helper_test.rb
 
require ​'test_helper'
 
 
class​ ProjectsHelperTest < ActionView::TestCase
 
 
test ​"project name with status info"​ ​do
 
project = Project.new(name: ​"Project Runway"​)
 
project.stubs(:on_schedule?).returns(true)
 
actual = name_with_status(project)
 
expected = ​"<span class='on_schedule'>Project Runway</span>"
 
assert_dom_equal expected, actual
 
end
 
 
test ​"project name ...

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