Building a framework-agnostic Ruby gem (and making sure it doesn't break)
2 days ago
- #automated testing
- #Ruby gem
- #framework-agnostic
- The author built a framework-agnostic Ruby gem supporting ERB, React, and Vue by using hidden HTML elements with data-native-* attributes that native apps detect via MutationObserver.
- Each framework's API is designed to feel natural: ERB uses blocks and builders, React uses components and props, and Vue follows similar patterns, all producing the same HTML output.
- To prevent regressions, automated XCUITest tests are set up for demo apps (Hotwire/ERB, React/Inertia, Vue/Inertia) that verify native UI functionality without asserting on HTML or JavaScript.
- Feedback from daily users of each framework is crucial for making the API feel right, not just technically work, as library authors may not fully grasp framework-specific nuances.
- The decision to rely on data attributes rather than framework hooks makes the gem potentially compatible with other frameworks like Sinatra, showing the abstraction is at the right layer.