template-context

Extract conditional logic from ERB templates into testable Plain Old Ruby Objects.

3|Updated Nov 19, 2025
One-click install
npx skills add https://github.com/meaganewaller/.dotfiles --skill template-context
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: template-context
Source: https://github.com/meaganewaller/.dotfiles/tree/main/home/.claude/skills/common/template-context
Command: npx skills add https://github.com/meaganewaller/.dotfiles --skill template-context

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the challenge of achieving branch coverage for logic embedded within ERB templates, which are often untestable by standard coverage tools.

Core Features & Use Cases

  • Extract Conditional Logic: Moves complex if/unless/ternary statements from ERB templates into dedicated Plain Old Ruby Objects (POROs).
  • Enhance Testability: Enables isolated unit testing of decision-making logic, leading to higher code quality.
  • Declarative Templates: Simplifies templates to focus on rendering data rather than executing logic.
  • Use Case: When your test suite reports 0% branch coverage for template files, use this pattern to refactor the logic into a testable PORO.

Quick Start

Apply the template-context pattern to extract conditional logic from your ERB template into a PORO.

Frequently Asked Questions about template-context

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I get branch coverage for conditional logic in ERB templates?

Extract template conditionals into a testable PORO context class to achieve full branch coverage. Move complex if/unless/ternary statements from ERB templates into isolated Plain Old Ruby Objects, update templates to call context methods, and write unit tests for the PORO.

Why does my test suite report 0% branch coverage for Rails template files?

Your test suite reports 0% branch coverage for template files because complex conditional logic is embedded directly within ERB templates, which standard coverage tools cannot test. Extracting conditionals into a PORO enables isolated unit testing of the decision-making logic.

What is the best way to refactor complex conditionals out of ERB templates?

The best way to refactor complex conditionals out of ERB templates is to create a PORO context class, move if/unless/ternary statements into dedicated methods, and update the template to call context methods, simplifying templates to focus on rendering data.

Can I use a PORO to test Rails generator templates with conditional logic?

Yes, you can use a PORO to test Rails generator templates with conditional logic. This pattern applies to scenarios involving the development of Rails generators with conditional ERB templates, allowing you to extract and unit test the template logic.

How do I write unit tests for ERB template rendering logic?

To write unit tests for ERB template rendering logic, extract the conditional logic into a PORO context class first. You can then write isolated unit tests directly against the PORO methods to verify the decision-making logic and achieve higher code quality.

When should I move template conditionals into a separate Ruby object?

You should move template conditionals into a separate Ruby object when your templates contain complex if/unless/ternary statements that need branch coverage, or when you want declarative templates that focus on rendering data rather than executing logic.