Minitest Helper Tests
Rails provides the ActionView::TestCase class, which is a subclass of ActiveSupport::TestCase 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:
| 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 status info behind ... |
Get Rails 5 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.