Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Testing View Partials" section to the Testing Guides #49193

Merged

Conversation

seanpdoyle
Copy link
Contributor

Motivation / Background

While the ActionView::TestCase class isn't marked with a :nodoc: comment to indicate that it's internal to Rails, there isn't much content in the guides that explains how to test view partials.

Libraries like view_component have built-in support for testing, including Capybara integration.

While ActionView::TestCase already integrates with rails-dom-testing, that integration could be better documented. Additionally, it wouldn't take much for consuming applications to mimic the ViewComponent testing experience for their Action View Partials.

Detail

First, link to the "Testing Rails Applications" page from the ActionView::TestCase class documentation.

Next, add a "Testing View Partials" section to the guides that expands upon the variety of tooling available to tests that inherit from ActionView::TestCase. In that section, cover topics like:

  • the render helper method
  • the rendered helper attribute reader
  • calls to assert_select with attribute placeholders
  • the document_root_element helper method
  • integration with Ruby's Pattern Matching
  • opportunities to integrate with Capybara

Additional information

Additionally, add test coverage that exercise the examples shared in the new section, including:

  • Calls to assert_select that utilize attribute placeholders
  • Ruby 3.0's Pattern Matching
  • Integration with Capybara

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@seanpdoyle seanpdoyle force-pushed the action-view-test-case-documentation branch 2 times, most recently from c93fdff to 51348d4 Compare September 8, 2023 01:11
@seanpdoyle
Copy link
Contributor Author

@skipkayhil if you're available, I would appreciate some review on these changes.

@seanpdoyle
Copy link
Contributor Author

@zzak since they're largely documentation based, would you be interested in reviewing these changes?

Motivation / Background
---

While the `ActionView::TestCase` class isn't marked with a `:nodoc:`
comment to indicate that it's internal to Rails, there isn't much
content in the guides that explains how to test view partials.

Libraries like
[view_component](https://github.com/ViewComponent/view_component/) have
[built-in support for
testing](https://viewcomponent.org/guide/testing.html), including
Capybara integration.

While `ActionView::TestCase` already integrates with
`rails-dom-testing`, that integration could be better documented.
Additionally, it wouldn't take much for consuming applications to mimic
the ViewComponent testing experience for their Action View Partials.

Details
---

First, link to the "Testing Rails Applications" page from the
`ActionView::TestCase` class documentation.

Next, add a "Testing View Partials" section to the guides that expands
upon the variety of tooling available to tests that inherit from
`ActionView::TestCase`. In that section, cover topics like:

* the `render` helper method
* the `rendered` helper attribute reader
* calls to `assert_select` with attribute placeholders
* the `document_root_element` helper method
* integration with Ruby's Pattern Matching
* opportunities to integrate with Capybara

Additional Information
---

Additionally, add test coverage that exercise the examples shared in the
new section, including:

* Calls to `assert_select` that utilize attribute placeholders
* Ruby 3.0's Pattern Matching
* Integration with Capybara
@seanpdoyle seanpdoyle force-pushed the action-view-test-case-documentation branch from 51348d4 to a9148b4 Compare September 13, 2023 13:44
Copy link
Contributor

@adrianna-chang-shopify adrianna-chang-shopify left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc changes look good on my end!

guides/source/testing.md Outdated Show resolved Hide resolved
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
@seanpdoyle
Copy link
Contributor Author

@adrianna-chang-shopify thank you for the review! If you're interested, #49194 is related and in need of review.

@rafaelfranca rafaelfranca merged commit 13b3e7d into rails:main Sep 13, 2023
4 checks passed
@zzak
Copy link
Member

zzak commented Sep 14, 2023

@seanpdoyle I'm not always able to read every notification from GitHub, in the future you can ping me on discord/slack/email 🙏

@seanpdoyle seanpdoyle deleted the action-view-test-case-documentation branch September 14, 2023 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants