Testing Helper Methods

Helper modules are the storage attic of Rails applications. They are designed to contain reusable bits of view logic. This might include view-specific representations of data, or conditional logic that governs how content is displayed. Helper modules tend to get filled with all kinds of clutter that doesn’t seem to belong anywhere else. Because they are a little tricky to set up for testing, helper methods often aren’t tested even when they contain significant amounts of logic. Again, in my own practice I often move this logic into dedicated presenter classes, but you’ll see a lot of code in Rails helpers you might want to unit-test.

RSpec helper tests go in spec/helpers. There’s not a whole lot of special magic here—just ...

Get Rails 5 Test Prescriptions now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.