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 support for RSpec to previews as test cases #1408

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thutterer
Copy link
Contributor

@thutterer thutterer commented Jun 28, 2022

What are you trying to accomplish?

I've noticed that the (Experimental) Previews as test cases don't support RSpec yet, because of how it builds the class name in which it expects the preview:

# Note: `#rendered_preview` expects a preview to be defined with the same class
# name as the calling test, but with `Test` replaced with `Preview`:
#
# MyComponentTest -> MyComponentPreview etc.

What approach did you choose and why?

This PR adds support for RSpec by checking self.respond_to?(:described_class) and if so, using "#{self.described_class}Preview" as the preview class name.

Anything you want to highlight for special attention from reviewers?

  • I haven't added a note about this to the docs. Not sure if that is needed in this case, because if you follow the naming conventions, it will just work.
  • I haven't touched any tests. Not sure how RSpec compatibility is handled in the project.
  • I haven't added myself to the docs/index.md as I hope #1383 gets merged before this one (or eventually).

@thutterer thutterer requested a review from as a code owner Jun 28, 2022
@thutterer thutterer force-pushed the rspec_preview_test_cases branch from 859d5af to 4e0cb29 Compare Jun 28, 2022
@thutterer thutterer force-pushed the rspec_preview_test_cases branch from 4e0cb29 to 7ed426c Compare Jun 28, 2022
Copy link
Contributor

@joelhawksley joelhawksley left a comment

Wonderful! To little surprise, I'd love to see a test for this ❤️. IMO we should add example rspec tests to the example app. Would you mind doing so in this PR? Just a single test that uses render_preview is sufficient for now, but IMO we should expand what we have for the sake of example.

@@ -9,6 +9,10 @@ title: Changelog

## main

* Add support for RSpec to previews as test cases
Copy link
Contributor

@joelhawksley joelhawksley Jul 5, 2022

Choose a reason for hiding this comment

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

Suggested change
* Add support for RSpec to previews as test cases
* Add support for `render_preview` in RSpec tests.

@thutterer
Copy link
Contributor Author

@thutterer thutterer commented Jul 6, 2022

IMO we should add example rspec tests to the example app. Would you mind doing so in this PR?

Good idea, I'll do that 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants