Testing Helper Methods Blocks

Learn about helper method blocks with examples and the way to test them.

Helper method blocks

Sometimes helper methods take a block, which is expected to be ERB text (or the text of whatever template tool we’re using to replace ERB). One everyday use of this kind of helper is access control, in which the logic in the helper determines whether the code in the block is invoked. Blocks also are beneficial as wrapper code for HTML that might surround many different kinds of text, a rounded-rectangle effect, for example.

Helper method blocks example

Here’s a simple example of a helper that takes a block:

Get hands-on with 1200+ tech skills courses.