Repository navigation
Conversation
|
Maybe someone can help with the failing checks, I'm not sure what to do |
|
@23tux This looks good to me. Those checks are failing on |
Co-authored-by: Hans Lemuet <Spone@users.noreply.github.com>
|
@boardfish I added a test helper as well, could you have another look at it? Apart from the integration/system specs that require a browser (as I said, I had some problems with the setup and can't run them), all the tests pass on my machine. I added one commit to make the allocation spec more robust. And the Lint check also fails, but it doesn't seem to involve my changes. |
Co-authored-by: Hans Lemuet <Spone@users.noreply.github.com>
|
@23tux thank you for taking the time to make this contribution! In https://viewcomponent.org/best_practices.html#test-against-rendered-content-not-instance-methods, we say:
I stand by that recommendation and thus am hesitant to add any test helpers to enable testing component instance methods. There is a reason https://viewcomponent.org/best_practices.html#most-viewcomponent-instance-methods-can-be-private immediately follows the guidance above! I am happy to have my mind changed here, but for now I'm going to close this PR in favor of #2511 which cherry-picks your bug fix ❤️ |
|
@joelhawksley thanks for your detailed explanation and sorry for the delayed response. So, let me try to change your mind 😀:
So, I hope these are enough points that you'd consider merging my PR. I rebased it already on the main branch, as our own app already works with that feature in production. |
That's fair, but render_inline is still very fast compared to integration or system tests.
I disagree. If our rendered HTML is difficult to select, that can be a sign that it isn't properly accessible. We lean heavily on using accessibility labels for our UI tests to ensure that screen readers can navigate our pages effectively. Also, I've yet to document it publicly, but we use a -- I appreciate your reasoning, but will keep things as they are for now. If and when a more necessary reason is presented, I'd be happy to reconsider. ❤️ |
|
Hmm, I’m sorry to hear that. What about my other points?
I ran a quick benchmark, and on my machine a component spec with a render_inline call is, on average, about 3× slower than a spec that simply asserts on a public method. To me, that’s a strong argument in favor of this PR. Also, don’t you think the code reads cleaner - and is easier to follow - when we have clearly defined lifecycles, even if they’re only used for internal structure? I’d be totally fine with making the lifecycle methods private. In that case, I’d frame this PR not as a new feature, but as a refactoring to improve the internal structure. |
Thinking about this some more, what really underpins my opinion is philosophical: I see ViewComponents as things that accept data and return HTML (or JSON) as their input/output contracts. I do not see them as objects to pass messages to.
I'm generally hesitant to break up long methods into single-use methods, especially when the sub-methods are only used privately. Again, this is more a matter of opinion. |
What are you trying to accomplish?
t(".some_key")inside a#render?method. Think ofdef render? = items.any?anditemsis a hash of translations@virtual_pathis actually set, I can now testt(..)calls in my helper method, because the teardown hasn't happened yet.What approach did you choose and why?
#render_inmethod into methods.@view_context.instance_variable_set(:@virtual_path, virtual_path)outside of the@output_buffer.with_buffer doblock. I just hope this doesn't break anything else.Anything you want to highlight for special attention from reviewers?
assert_allocations