From 2b35144540cacf618d86cc6774bd5beb1f4fb53d Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 3 Nov 2021 11:56:36 +0100 Subject: [PATCH 1/3] Unify expectations on spec components folder In this PR (https://github.com/consul/consul/pull/4683) a new syntax was introduced in the component specs to check that the component was not rendering. It seems interesting to add this syntax to the rest of the cases and thus unify the way we check that a component is not rendering. --- spec/components/admin/budgets/duration_component_spec.rb | 4 ++-- .../budgets_wizard/headings/group_switcher_component_spec.rb | 3 +-- spec/components/budgets/supports_info_component_spec.rb | 3 +-- spec/components/layout/locale_switcher_component_spec.rb | 3 +-- spec/components/layout/social_component_spec.rb | 2 +- spec/components/layout/top_links_component_spec.rb | 2 +- spec/components/sdg/goals/help_page_component_spec.rb | 2 +- spec/components/sdg/goals/plain_tag_list_component_spec.rb | 2 +- spec/components/sdg/goals/tag_list_component_spec.rb | 4 ++-- spec/components/sdg/goals/targets_component_spec.rb | 4 +--- spec/components/sdg/related_list_selector_component_spec.rb | 4 ++-- spec/components/sdg/targets/plain_tag_list_component_spec.rb | 4 ++-- spec/components/sdg/targets/tag_list_component_spec.rb | 4 ++-- spec/components/shared/banner_component_spec.rb | 4 ++-- spec/components/shared/link_list_component_spec.rb | 4 ++-- 15 files changed, 22 insertions(+), 27 deletions(-) diff --git a/spec/components/admin/budgets/duration_component_spec.rb b/spec/components/admin/budgets/duration_component_spec.rb index a95c44108..e581c3bbf 100644 --- a/spec/components/admin/budgets/duration_component_spec.rb +++ b/spec/components/admin/budgets/duration_component_spec.rb @@ -49,7 +49,7 @@ describe Admin::Budgets::DurationComponent do render Admin::Budgets::DurationComponent.new(durable).duration - expect(page.text).to be_empty + expect(page.native.inner_html).to be_empty end it "is not defined when no start date is defined" do @@ -57,7 +57,7 @@ describe Admin::Budgets::DurationComponent do render Admin::Budgets::DurationComponent.new(durable).duration - expect(page.text).to be_empty + expect(page.native.inner_html).to be_empty end end diff --git a/spec/components/admin/budgets_wizard/headings/group_switcher_component_spec.rb b/spec/components/admin/budgets_wizard/headings/group_switcher_component_spec.rb index a0e0ee1cb..13a6db846 100644 --- a/spec/components/admin/budgets_wizard/headings/group_switcher_component_spec.rb +++ b/spec/components/admin/budgets_wizard/headings/group_switcher_component_spec.rb @@ -6,8 +6,7 @@ describe Admin::BudgetsWizard::Headings::GroupSwitcherComponent do render_inline Admin::BudgetsWizard::Headings::GroupSwitcherComponent.new(group) - expect(page.text).to be_empty - expect(page).not_to have_css ".budget-group-switcher" + expect(page.native.inner_html).to be_empty end it "renders a link to switch group for budgets with two groups" do diff --git a/spec/components/budgets/supports_info_component_spec.rb b/spec/components/budgets/supports_info_component_spec.rb index 64b563877..9286976fd 100644 --- a/spec/components/budgets/supports_info_component_spec.rb +++ b/spec/components/budgets/supports_info_component_spec.rb @@ -28,8 +28,7 @@ describe Budgets::SupportsInfoComponent do render_inline component - expect(page).not_to have_selector ".supports-info" - expect(page.text).to be_empty + expect(page.native.inner_html).to be_empty end describe "#total_supports" do diff --git a/spec/components/layout/locale_switcher_component_spec.rb b/spec/components/layout/locale_switcher_component_spec.rb index d703aa62f..4c104525b 100644 --- a/spec/components/layout/locale_switcher_component_spec.rb +++ b/spec/components/layout/locale_switcher_component_spec.rb @@ -13,8 +13,7 @@ describe Layout::LocaleSwitcherComponent do it "doesn't render anything" do render_inline component - expect(page.text).to be_empty - expect(page).not_to have_css ".locale" + expect(page.native.inner_html).to be_empty end end diff --git a/spec/components/layout/social_component_spec.rb b/spec/components/layout/social_component_spec.rb index 757051538..f54ff1182 100644 --- a/spec/components/layout/social_component_spec.rb +++ b/spec/components/layout/social_component_spec.rb @@ -33,7 +33,7 @@ describe Layout::SocialComponent do render_inline Layout::SocialComponent.new - expect(page).not_to have_css "ul" + expect(page.native.inner_html).to be_empty end end end diff --git a/spec/components/layout/top_links_component_spec.rb b/spec/components/layout/top_links_component_spec.rb index e9e297d26..893d282f6 100644 --- a/spec/components/layout/top_links_component_spec.rb +++ b/spec/components/layout/top_links_component_spec.rb @@ -13,7 +13,7 @@ describe Layout::TopLinksComponent do it "does not render when no content block is defined" do render_inline Layout::TopLinksComponent.new - expect(page).not_to have_css "ul" + expect(page.native.inner_html).to be_empty end end end diff --git a/spec/components/sdg/goals/help_page_component_spec.rb b/spec/components/sdg/goals/help_page_component_spec.rb index 250dd4e91..7f713f0ee 100644 --- a/spec/components/sdg/goals/help_page_component_spec.rb +++ b/spec/components/sdg/goals/help_page_component_spec.rb @@ -13,7 +13,7 @@ describe SDG::Goals::HelpPageComponent do render_inline component - expect(page).not_to have_css ".sdg-help-content" + expect(page.native.inner_html).to be_empty end it "renders content when the feature is enabled" do diff --git a/spec/components/sdg/goals/plain_tag_list_component_spec.rb b/spec/components/sdg/goals/plain_tag_list_component_spec.rb index cd629f26b..76581c6c3 100644 --- a/spec/components/sdg/goals/plain_tag_list_component_spec.rb +++ b/spec/components/sdg/goals/plain_tag_list_component_spec.rb @@ -14,7 +14,7 @@ describe SDG::Goals::PlainTagListComponent do render_inline component - expect(page).not_to have_css "li" + expect(page.native.inner_html).to be_empty end it "does not render when the SDG process feature is disabled" do diff --git a/spec/components/sdg/goals/tag_list_component_spec.rb b/spec/components/sdg/goals/tag_list_component_spec.rb index b47bcd5b9..f55b1d479 100644 --- a/spec/components/sdg/goals/tag_list_component_spec.rb +++ b/spec/components/sdg/goals/tag_list_component_spec.rb @@ -14,7 +14,7 @@ describe SDG::Goals::TagListComponent do render_inline component - expect(page).not_to have_css "li" + expect(page.native.inner_html).to be_empty end it "does not render when the SDG process feature is disabled" do @@ -22,7 +22,7 @@ describe SDG::Goals::TagListComponent do render_inline component - expect(page).not_to have_css "li" + expect(page.native.inner_html).to be_empty end it "renders a list of goals" do diff --git a/spec/components/sdg/goals/targets_component_spec.rb b/spec/components/sdg/goals/targets_component_spec.rb index 072abf99f..5f00300aa 100644 --- a/spec/components/sdg/goals/targets_component_spec.rb +++ b/spec/components/sdg/goals/targets_component_spec.rb @@ -13,9 +13,7 @@ describe SDG::Goals::TargetsComponent do render_inline component - expect(page).not_to have_css ".targets" - expect(page).not_to have_css "#target_tabs" - expect(page).not_to have_css ".tabs-content" + expect(page.native.inner_html).to be_empty end it "renders tabs panel" do diff --git a/spec/components/sdg/related_list_selector_component_spec.rb b/spec/components/sdg/related_list_selector_component_spec.rb index 9d8509245..6aa1bb1b8 100644 --- a/spec/components/sdg/related_list_selector_component_spec.rb +++ b/spec/components/sdg/related_list_selector_component_spec.rb @@ -15,7 +15,7 @@ describe SDG::RelatedListSelectorComponent do render_inline component - expect(page).not_to have_css ".sdg-related-list-selector" + expect(page.native.inner_html).to be_empty end it "does not render when the SDG process feature is disabled" do @@ -23,7 +23,7 @@ describe SDG::RelatedListSelectorComponent do render_inline component - expect(page).not_to have_css ".sdg-related-list-selector" + expect(page.native.inner_html).to be_empty end it "renders related_sdg_list field" do diff --git a/spec/components/sdg/targets/plain_tag_list_component_spec.rb b/spec/components/sdg/targets/plain_tag_list_component_spec.rb index 801273bde..415ccc856 100644 --- a/spec/components/sdg/targets/plain_tag_list_component_spec.rb +++ b/spec/components/sdg/targets/plain_tag_list_component_spec.rb @@ -18,7 +18,7 @@ describe SDG::Targets::PlainTagListComponent do render_inline component - expect(page).not_to have_css "li" + expect(page.native.inner_html).to be_empty end it "does not render when the SDG process feature is disabled" do @@ -26,7 +26,7 @@ describe SDG::Targets::PlainTagListComponent do render_inline component - expect(page).not_to have_css "li" + expect(page.native.inner_html).to be_empty end it "renders a list of targets" do diff --git a/spec/components/sdg/targets/tag_list_component_spec.rb b/spec/components/sdg/targets/tag_list_component_spec.rb index 327c7aa56..cf2cb9546 100644 --- a/spec/components/sdg/targets/tag_list_component_spec.rb +++ b/spec/components/sdg/targets/tag_list_component_spec.rb @@ -18,7 +18,7 @@ describe SDG::Targets::TagListComponent do render_inline component - expect(page).not_to have_css "li" + expect(page.native.inner_html).to be_empty end it "does not render when the SDG process feature is disabled" do @@ -26,7 +26,7 @@ describe SDG::Targets::TagListComponent do render_inline component - expect(page).not_to have_css "li" + expect(page.native.inner_html).to be_empty end it "renders a list of targets" do diff --git a/spec/components/shared/banner_component_spec.rb b/spec/components/shared/banner_component_spec.rb index 9dc1113a2..dd11f9772 100644 --- a/spec/components/shared/banner_component_spec.rb +++ b/spec/components/shared/banner_component_spec.rb @@ -82,13 +82,13 @@ describe Shared::BannerComponent do render_inline Shared::BannerComponent.new("debates") - expect(page).not_to have_css ".banner" + expect(page.native.inner_html).to be_empty end end it "does not render anything given nil" do render_inline Shared::BannerComponent.new(nil) - expect(page).not_to have_css ".banner" + expect(page.native.inner_html).to be_empty end end diff --git a/spec/components/shared/link_list_component_spec.rb b/spec/components/shared/link_list_component_spec.rb index 8dea5fb90..dd23307d2 100644 --- a/spec/components/shared/link_list_component_spec.rb +++ b/spec/components/shared/link_list_component_spec.rb @@ -4,13 +4,13 @@ describe Shared::LinkListComponent do it "renders nothing with an empty list" do render_inline Shared::LinkListComponent.new - expect(page).not_to have_css "ul" + expect(page.native.inner_html).to be_empty end it "returns nothing with a list of nil elements" do render_inline Shared::LinkListComponent.new(nil, nil) - expect(page).not_to have_css "ul" + expect(page.native.inner_html).to be_empty end it "generates a list of links" do From 612872ac7ab6685677fb8f8f9c134e3ce780ae97 Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 3 Nov 2021 18:17:30 +0100 Subject: [PATCH 2/3] Define and apply matcher :be_rendered Add this changes to make components specs clear --- .../admin/budgets/duration_component_spec.rb | 4 ++-- .../headings/group_switcher_component_spec.rb | 2 +- .../budgets/investments/filters_component_spec.rb | 2 +- .../budgets/supports_info_component_spec.rb | 2 +- .../layout/locale_switcher_component_spec.rb | 2 +- spec/components/layout/social_component_spec.rb | 2 +- spec/components/layout/top_links_component_spec.rb | 2 +- .../comments_summary_component_spec.rb | 6 +++--- .../sdg/goals/help_page_component_spec.rb | 2 +- .../sdg/goals/plain_tag_list_component_spec.rb | 2 +- .../components/sdg/goals/tag_list_component_spec.rb | 4 ++-- spec/components/sdg/goals/targets_component_spec.rb | 2 +- .../sdg/related_list_selector_component_spec.rb | 4 ++-- spec/components/sdg/tag_list_component_spec.rb | 2 +- .../sdg/targets/plain_tag_list_component_spec.rb | 4 ++-- .../sdg/targets/tag_list_component_spec.rb | 4 ++-- spec/components/shared/banner_component_spec.rb | 4 ++-- spec/components/shared/link_list_component_spec.rb | 4 ++-- spec/components/shared/tag_list_component_spec.rb | 2 +- spec/support/matchers/be_rendered.rb | 13 +++++++++++++ 20 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 spec/support/matchers/be_rendered.rb diff --git a/spec/components/admin/budgets/duration_component_spec.rb b/spec/components/admin/budgets/duration_component_spec.rb index e581c3bbf..d84d13c7b 100644 --- a/spec/components/admin/budgets/duration_component_spec.rb +++ b/spec/components/admin/budgets/duration_component_spec.rb @@ -49,7 +49,7 @@ describe Admin::Budgets::DurationComponent do render Admin::Budgets::DurationComponent.new(durable).duration - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "is not defined when no start date is defined" do @@ -57,7 +57,7 @@ describe Admin::Budgets::DurationComponent do render Admin::Budgets::DurationComponent.new(durable).duration - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end end diff --git a/spec/components/admin/budgets_wizard/headings/group_switcher_component_spec.rb b/spec/components/admin/budgets_wizard/headings/group_switcher_component_spec.rb index 13a6db846..56e7e825d 100644 --- a/spec/components/admin/budgets_wizard/headings/group_switcher_component_spec.rb +++ b/spec/components/admin/budgets_wizard/headings/group_switcher_component_spec.rb @@ -6,7 +6,7 @@ describe Admin::BudgetsWizard::Headings::GroupSwitcherComponent do render_inline Admin::BudgetsWizard::Headings::GroupSwitcherComponent.new(group) - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "renders a link to switch group for budgets with two groups" do diff --git a/spec/components/budgets/investments/filters_component_spec.rb b/spec/components/budgets/investments/filters_component_spec.rb index 5fe213934..88e9c075d 100644 --- a/spec/components/budgets/investments/filters_component_spec.rb +++ b/spec/components/budgets/investments/filters_component_spec.rb @@ -16,7 +16,7 @@ describe Budgets::Investments::FiltersComponent do render_inline Budgets::Investments::FiltersComponent.new - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end end diff --git a/spec/components/budgets/supports_info_component_spec.rb b/spec/components/budgets/supports_info_component_spec.rb index 9286976fd..1bf10f986 100644 --- a/spec/components/budgets/supports_info_component_spec.rb +++ b/spec/components/budgets/supports_info_component_spec.rb @@ -28,7 +28,7 @@ describe Budgets::SupportsInfoComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end describe "#total_supports" do diff --git a/spec/components/layout/locale_switcher_component_spec.rb b/spec/components/layout/locale_switcher_component_spec.rb index 4c104525b..0edb9e968 100644 --- a/spec/components/layout/locale_switcher_component_spec.rb +++ b/spec/components/layout/locale_switcher_component_spec.rb @@ -13,7 +13,7 @@ describe Layout::LocaleSwitcherComponent do it "doesn't render anything" do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end end diff --git a/spec/components/layout/social_component_spec.rb b/spec/components/layout/social_component_spec.rb index f54ff1182..e3956e215 100644 --- a/spec/components/layout/social_component_spec.rb +++ b/spec/components/layout/social_component_spec.rb @@ -33,7 +33,7 @@ describe Layout::SocialComponent do render_inline Layout::SocialComponent.new - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end end end diff --git a/spec/components/layout/top_links_component_spec.rb b/spec/components/layout/top_links_component_spec.rb index 893d282f6..1f69a02b1 100644 --- a/spec/components/layout/top_links_component_spec.rb +++ b/spec/components/layout/top_links_component_spec.rb @@ -13,7 +13,7 @@ describe Layout::TopLinksComponent do it "does not render when no content block is defined" do render_inline Layout::TopLinksComponent.new - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end end end diff --git a/spec/components/machine_learning/comments_summary_component_spec.rb b/spec/components/machine_learning/comments_summary_component_spec.rb index 7cc32b12b..71c861d23 100644 --- a/spec/components/machine_learning/comments_summary_component_spec.rb +++ b/spec/components/machine_learning/comments_summary_component_spec.rb @@ -22,7 +22,7 @@ describe MachineLearning::CommentsSummaryComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "is not displayed when the machine learning feature is disabled" do @@ -30,7 +30,7 @@ describe MachineLearning::CommentsSummaryComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "is not displayed when there's no summary" do @@ -38,6 +38,6 @@ describe MachineLearning::CommentsSummaryComponent do render_inline MachineLearning::CommentsSummaryComponent.new(commentable) - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end end diff --git a/spec/components/sdg/goals/help_page_component_spec.rb b/spec/components/sdg/goals/help_page_component_spec.rb index 7f713f0ee..35b4a1395 100644 --- a/spec/components/sdg/goals/help_page_component_spec.rb +++ b/spec/components/sdg/goals/help_page_component_spec.rb @@ -13,7 +13,7 @@ describe SDG::Goals::HelpPageComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "renders content when the feature is enabled" do diff --git a/spec/components/sdg/goals/plain_tag_list_component_spec.rb b/spec/components/sdg/goals/plain_tag_list_component_spec.rb index 76581c6c3..930192930 100644 --- a/spec/components/sdg/goals/plain_tag_list_component_spec.rb +++ b/spec/components/sdg/goals/plain_tag_list_component_spec.rb @@ -14,7 +14,7 @@ describe SDG::Goals::PlainTagListComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "does not render when the SDG process feature is disabled" do diff --git a/spec/components/sdg/goals/tag_list_component_spec.rb b/spec/components/sdg/goals/tag_list_component_spec.rb index f55b1d479..65aec351e 100644 --- a/spec/components/sdg/goals/tag_list_component_spec.rb +++ b/spec/components/sdg/goals/tag_list_component_spec.rb @@ -14,7 +14,7 @@ describe SDG::Goals::TagListComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "does not render when the SDG process feature is disabled" do @@ -22,7 +22,7 @@ describe SDG::Goals::TagListComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "renders a list of goals" do diff --git a/spec/components/sdg/goals/targets_component_spec.rb b/spec/components/sdg/goals/targets_component_spec.rb index 5f00300aa..36b435fc9 100644 --- a/spec/components/sdg/goals/targets_component_spec.rb +++ b/spec/components/sdg/goals/targets_component_spec.rb @@ -13,7 +13,7 @@ describe SDG::Goals::TargetsComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "renders tabs panel" do diff --git a/spec/components/sdg/related_list_selector_component_spec.rb b/spec/components/sdg/related_list_selector_component_spec.rb index 6aa1bb1b8..f06280fa0 100644 --- a/spec/components/sdg/related_list_selector_component_spec.rb +++ b/spec/components/sdg/related_list_selector_component_spec.rb @@ -15,7 +15,7 @@ describe SDG::RelatedListSelectorComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "does not render when the SDG process feature is disabled" do @@ -23,7 +23,7 @@ describe SDG::RelatedListSelectorComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "renders related_sdg_list field" do diff --git a/spec/components/sdg/tag_list_component_spec.rb b/spec/components/sdg/tag_list_component_spec.rb index c262250c1..d61f3029d 100644 --- a/spec/components/sdg/tag_list_component_spec.rb +++ b/spec/components/sdg/tag_list_component_spec.rb @@ -27,7 +27,7 @@ describe SDG::TagListComponent do render_inline SDG::TagListComponent.new(record) - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end context "when linkable is false" do diff --git a/spec/components/sdg/targets/plain_tag_list_component_spec.rb b/spec/components/sdg/targets/plain_tag_list_component_spec.rb index 415ccc856..9606153b9 100644 --- a/spec/components/sdg/targets/plain_tag_list_component_spec.rb +++ b/spec/components/sdg/targets/plain_tag_list_component_spec.rb @@ -18,7 +18,7 @@ describe SDG::Targets::PlainTagListComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "does not render when the SDG process feature is disabled" do @@ -26,7 +26,7 @@ describe SDG::Targets::PlainTagListComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "renders a list of targets" do diff --git a/spec/components/sdg/targets/tag_list_component_spec.rb b/spec/components/sdg/targets/tag_list_component_spec.rb index cf2cb9546..db8a7bcff 100644 --- a/spec/components/sdg/targets/tag_list_component_spec.rb +++ b/spec/components/sdg/targets/tag_list_component_spec.rb @@ -18,7 +18,7 @@ describe SDG::Targets::TagListComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "does not render when the SDG process feature is disabled" do @@ -26,7 +26,7 @@ describe SDG::Targets::TagListComponent do render_inline component - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "renders a list of targets" do diff --git a/spec/components/shared/banner_component_spec.rb b/spec/components/shared/banner_component_spec.rb index dd11f9772..5723dd54c 100644 --- a/spec/components/shared/banner_component_spec.rb +++ b/spec/components/shared/banner_component_spec.rb @@ -82,13 +82,13 @@ describe Shared::BannerComponent do render_inline Shared::BannerComponent.new("debates") - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end end it "does not render anything given nil" do render_inline Shared::BannerComponent.new(nil) - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end end diff --git a/spec/components/shared/link_list_component_spec.rb b/spec/components/shared/link_list_component_spec.rb index dd23307d2..0289a1b94 100644 --- a/spec/components/shared/link_list_component_spec.rb +++ b/spec/components/shared/link_list_component_spec.rb @@ -4,13 +4,13 @@ describe Shared::LinkListComponent do it "renders nothing with an empty list" do render_inline Shared::LinkListComponent.new - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "returns nothing with a list of nil elements" do render_inline Shared::LinkListComponent.new(nil, nil) - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end it "generates a list of links" do diff --git a/spec/components/shared/tag_list_component_spec.rb b/spec/components/shared/tag_list_component_spec.rb index 8b311ed33..d8474fca8 100644 --- a/spec/components/shared/tag_list_component_spec.rb +++ b/spec/components/shared/tag_list_component_spec.rb @@ -42,6 +42,6 @@ describe Shared::TagListComponent do it "is not rendered when there are no tags" do render_inline Shared::TagListComponent.new(Proposal.new, limit: nil) - expect(page.native.inner_html).to be_empty + expect(page).not_to be_rendered end end diff --git a/spec/support/matchers/be_rendered.rb b/spec/support/matchers/be_rendered.rb new file mode 100644 index 000000000..b69c1e75e --- /dev/null +++ b/spec/support/matchers/be_rendered.rb @@ -0,0 +1,13 @@ +RSpec::Matchers.define :be_rendered do + match do |page| + !page.native.inner_html.empty? + end + + failure_message_when_negated do |page| + if page.has_css?("body") + "expected page not to be rendered, but was rendered with #{page.find("body").native.inner_html}" + else + "expected page not to be rendered, but was rendered with #{page.native.inner_html}" + end + end +end From 934ce21871139800002eba61aa931f9a791c4029 Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 3 Nov 2021 18:51:09 +0100 Subject: [PATCH 3/3] Allow passing :with argument to :be_rendered We need it in order to check the rendered content. --- .../shared/link_list_component_spec.rb | 6 ++---- spec/support/matchers/be_rendered.rb | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/spec/components/shared/link_list_component_spec.rb b/spec/components/shared/link_list_component_spec.rb index 0289a1b94..93e57cb01 100644 --- a/spec/components/shared/link_list_component_spec.rb +++ b/spec/components/shared/link_list_component_spec.rb @@ -17,9 +17,8 @@ describe Shared::LinkListComponent do render_inline Shared::LinkListComponent.new( ["Home", "/"], ["Info", "/info"], class: "menu" ) - list = page.find("body").native.inner_html - expect(list).to eq '