Add ActionView::TestCase DSL generator #614
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #570, #494
Motivation
Tests that inherit from
ActionView::TestCase
have the respective helpers they are testing dynamically included when the test is instantiated.Basically, this is what Rails does:
Implementation
The implementation is straight forward. We gather all tests that inherit from
ActionView::TestCase
, instantiate the constant with a fake test name to trigger the helpers inclusion and then create the RBI including all of the helper ancestors that were dynamically included.Concerns
The big challenge for this work is that we currently do not require any test files. In order to actually have this work, we would need to be requiring all test files, which is why I wanted to bring this up for discussion before we move forward.
Alternative
The alternative implementation would be to not require test files, but to try to figure out the RBIs based on the helpers alone. This also breaks some fundamental assumptions of Tapioca and requires some thought. Namely,
UsersHelper
, but generatingUsersHelperTest
). This requires changes in the DSL generatorActionView::TestCase
test also exists. If we create a test RBI for each helper, we're pretty much guaranteed to generate unnecessary RBIs. We could try to find out whether a test exists, but then that will involve figuring out the right file paths, which is not necessarily enforced (you can put tests for a helper in the wrong path and they'll still run)Please, let me know your thoughts about the tradeoffs and how you think we should move forward.
Tests
See included tests.