From 0905dc34d9d7e8ff254cdf72116e8d68ceeb37df Mon Sep 17 00:00:00 2001 From: Rylan Bowers Date: Sun, 10 Nov 2024 16:11:25 -0700 Subject: [PATCH 1/4] Add a section for hwo to add the render_inline helpers to View Component tests Source: https://stackoverflow.com/questions/70041733/integrating-viewcomponent-with-rspec --- docs/guide/testing.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/guide/testing.md b/docs/guide/testing.md index dbff2646d..e725767a8 100644 --- a/docs/guide/testing.md +++ b/docs/guide/testing.md @@ -30,6 +30,21 @@ _Note: `assert_selector` only matches on visible elements by default. To match o For debugging purposes, the `rendered_content` test helper outputs the rendered HTML. +## Adding Test Helpers (RSpec) + +This will allow for helpers like `render_inline` to work in your tests. + +```ruby +# spec/rails_helper.rb +require 'view_component/test_helpers' + +RSpec.configure do |config| + # ... + + config.include ViewComponent::TestHelpers, type: :component +end +``` + ## Testing Slots ```ruby From 0be9fec630c8e08b8d7e83d9fec8d0fa77a9ec6d Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Wed, 18 Dec 2024 12:09:36 -0700 Subject: [PATCH 2/4] Apply suggestions from code review --- docs/guide/testing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guide/testing.md b/docs/guide/testing.md index e725767a8..77a321208 100644 --- a/docs/guide/testing.md +++ b/docs/guide/testing.md @@ -30,9 +30,9 @@ _Note: `assert_selector` only matches on visible elements by default. To match o For debugging purposes, the `rendered_content` test helper outputs the rendered HTML. -## Adding Test Helpers (RSpec) +## Use with RSpec -This will allow for helpers like `render_inline` to work in your tests. +To enable ViewComponent test helpers in RSpec, add: ```ruby # spec/rails_helper.rb From 140e993927db4389c9bfd8e8f99aa49d587ba709 Mon Sep 17 00:00:00 2001 From: Rylan Bowers Date: Wed, 18 Dec 2024 12:34:32 -0700 Subject: [PATCH 3/4] Adding a note on the documentation update for RSpec. Fixing lint callout for double quoted strings instead of single --- docs/CHANGELOG.md | 4 ++++ docs/guide/testing.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 43e298e83..96321fe4f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 5 ## main +* Updates docs/guide/testing.md to include an example of how to use with RSpec + + *Rylan Bowers* + * Add `--skip-suffix` option to component generator. *KAWAKAMI Moeki* diff --git a/docs/guide/testing.md b/docs/guide/testing.md index 77a321208..cf344c123 100644 --- a/docs/guide/testing.md +++ b/docs/guide/testing.md @@ -36,7 +36,7 @@ To enable ViewComponent test helpers in RSpec, add: ```ruby # spec/rails_helper.rb -require 'view_component/test_helpers' +require "view_component/test_helpers" RSpec.configure do |config| # ... From 9d2284b6558e5ddf3b0760d27cd668ea70b06ffc Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Wed, 18 Dec 2024 14:10:13 -0700 Subject: [PATCH 4/4] Update docs/CHANGELOG.md --- docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 96321fe4f..c1b3c69f0 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,7 +10,7 @@ nav_order: 5 ## main -* Updates docs/guide/testing.md to include an example of how to use with RSpec +* Updates testing docs to include an example of how to use with RSpec. *Rylan Bowers*