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 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.