From 9ca6519fb1ff523b45cfffe775d7a1cbcadca44e Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 9 May 2024 10:02:17 +1000 Subject: [PATCH] Recommended RSpec option: shared_context_metadata_behavior One spec failed due to this new behaviour. Converting the shared examples to simple blocks solved this. But the specs could probably be written better now. I didn't invest this time. --- spec/base_spec_helper.rb | 7 +++ spec/system/admin/order_cycles/simple_spec.rb | 59 +++++++++++-------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index bf65ee490e..7412ba4dec 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -117,6 +117,13 @@ RSpec.configure do |config| # mocks.verify_partial_doubles = true end + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + # Reset locale for all specs. config.around(:each) do |example| I18n.with_locale(:en) { example.run } diff --git a/spec/system/admin/order_cycles/simple_spec.rb b/spec/system/admin/order_cycles/simple_spec.rb index 087665d92d..364048ee9d 100644 --- a/spec/system/admin/order_cycles/simple_spec.rb +++ b/spec/system/admin/order_cycles/simple_spec.rb @@ -399,37 +399,44 @@ describe ' oc.update prefers_product_selection_from_coordinator_inventory_only: false end - shared_examples "inventory warning" do - |inventory_visible, inventory_only, it_description, expect_message| - before do - # hides/displays variant within coordinator's inventory - inventory_item_v1.update!(visible: inventory_visible) - # changes coordinator's inventory preferences - supplier_managed.update preferred_product_selection_from_inventory_only: inventory_only + it "shows a warning when going to 'outgoing products' tab" do + # hides/displays variant within coordinator's inventory + inventory_item_v1.update!(visible: false) + # changes coordinator's inventory preferences + supplier_managed.update preferred_product_selection_from_inventory_only: true + + visit edit_admin_order_cycle_path(oc) + click_link "Outgoing Products" + within "tr.distributor-#{distributor_managed.id}" do + page.find("td.products").click end - it "#{it_description} a warning when going to 'outgoing products' tab" do - visit edit_admin_order_cycle_path(oc) - click_link "Outgoing Products" - within "tr.distributor-#{distributor_managed.id}" do - page.find("td.products").click - end + # we need this assertion here to assure there is enough time to + # toggle the variant box and evaluate the following assertion + expect(page).to have_content product.name.upcase - # we need this assertion here to assure there is enough time to - # toggle the variant box and evaluate the following assertion - expect(page).to have_content product.name.upcase - - # iterates between true / false, depending on the test case - expectation = expect_message ? :to : :not_to - expect(page).public_send(expectation, - have_content(%(No variant available for this product - (hidden via inventory settings)).squish)) - end + expect(page).to have_content "No variant available for this product" end - it_behaves_like "inventory warning", false, true, "shows", true - it_behaves_like "inventory warning", false, false, "does not show", false do - before { pending("#11851") } + it "doesn't show a warning when going to 'outgoing products' tab" do + pending("#11851") + + # hides/displays variant within coordinator's inventory + inventory_item_v1.update!(visible: false) + # changes coordinator's inventory preferences + supplier_managed.update preferred_product_selection_from_inventory_only: false + + visit edit_admin_order_cycle_path(oc) + click_link "Outgoing Products" + within "tr.distributor-#{distributor_managed.id}" do + page.find("td.products").click + end + + # we need this assertion here to assure there is enough time to + # toggle the variant box and evaluate the following assertion + expect(page).to have_content product.name.upcase + + expect(page).not_to have_content "No variant available for this product" end end