Skip to content

feat: Simpler way to test Ruby components? #1086

@harrisj

Description

@harrisj

Summary

It would be useful to be able to run Minitest against Ruby components directly (perhaps in the pre-render hook), especially if it could also still use Zeitwerk loading

Motivation

I am migrating some partials to Ruby components and I appreciate the ability to code logic in the class and methods. For instance I have a date display label that has a few formatting parameters.

It's not clear how I could write tests for this. There is a mini testing framework but it's for generated pages. I could write tests for the components but it's after site generation is over and requires a lot of deft require statements. Having a way to test them that feels more natural would be great

Guide-level explanation

Once you have written your component, you should also create tests for it! Some components may have multiple configuration options which alter behavior and be presented with different types of data.

Component tests can be written and placed in directory X. They can use Zeitwerk includes (in the same way components do) and these tests are run before site rendering to ensure they pass.

Reference-level explanation

I'm not sure of the best way to implement this.

Drawbacks

It might add complexity and not be used by many people. Maybe components should be tested through something like Storybook?

Unresolved Questions

None that I can think of. This can use data loaded into the system (or Sequel), but it may be necessary to mock or stub input arguments sometimes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions