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

Merged
merged 6 commits into from
Jul 18, 2022

Conversation

thutterer
Copy link
Contributor

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:
https://github.com/github/view_component/blob/1a2e39d044f2be8c4dd18fe14d4aa5a3812b79f0/lib/view_component/render_preview_helper.rb#L13-L16

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 Prevent adding existing autoload_paths #1383 gets merged before this one (or eventually).

@thutterer thutterer requested a review from a team as a code owner June 28, 2022 13:23
@thutterer thutterer force-pushed the rspec_preview_test_cases branch 2 times, most recently from 4e0cb29 to 7ed426c Compare June 28, 2022 13:39
Copy link
Member

@joelhawksley joelhawksley left a comment

Choose a reason for hiding this comment

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

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.

docs/CHANGELOG.md Outdated Show resolved Hide resolved
@thutterer
Copy link
Contributor Author

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 👍🏼

@thutterer thutterer requested a review from Spone as a code owner July 11, 2022 20:01
@thutterer thutterer force-pushed the rspec_preview_test_cases branch 2 times, most recently from 4c2c84d to 5251fea Compare July 11, 2022 20:26
@thutterer
Copy link
Contributor Author

Excuse the 👊🏼 -pushing but I've added the rspec-rails gem and made it so that appraisal rake spec runs all rspec tests.

For now there is only one rspec file covering the fix in this PR. I've added :nocov: comments around the code that is covered with RSpec.

@joelhawksley Should I go ahead and enable this also on CI by running rake test spec instead of rake in the test job?

@joelhawksley
Copy link
Member

For now there is only one rspec file covering the fix in this PR. I've added :nocov: comments around the code that is covered with RSpec.

@thutterer yes, let's enable this on CI and remove the :nocov:. Simplecov should collate all of the builds to include the Rspec coverage.

@thutterer
Copy link
Contributor Author

@joelhawksley

let's enable this on CI and remove the :nocov:. Simplecov should collate all of the builds to include the Rspec coverage.

Done, test coverage back to 100% 💚 I had to move the rspec-rails gem into the top-level Gemfile for rake spec to work without appraisal.

Gemfile Outdated Show resolved Hide resolved
@joelhawksley joelhawksley merged commit 5b9dad7 into ViewComponent:main Jul 18, 2022
@joelhawksley
Copy link
Member

Fantastic! Thanks so much for adding this support ❤️

@thutterer thutterer deleted the rspec_preview_test_cases branch July 19, 2022 07:03
claudiob pushed a commit to claudiob/view_component that referenced this pull request Dec 22, 2023
* Add rspec-rails gem

* Add support for render_previews in RSpec tests

* Enable RSpec tests on CI

* Update lib/view_component/render_preview_helper.rb

* Update lib/view_component/render_preview_helper.rb

* Update Gemfile

Co-authored-by: Joel Hawksley <joelhawksley@github.com>
claudiob pushed a commit to claudiob/view_component that referenced this pull request Jan 3, 2024
* Add rspec-rails gem

* Add support for render_previews in RSpec tests

* Enable RSpec tests on CI

* Update lib/view_component/render_preview_helper.rb

* Update lib/view_component/render_preview_helper.rb

* Update Gemfile

Co-authored-by: Joel Hawksley <joelhawksley@github.com>
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.

2 participants