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.
This commit is contained in:
Maikel Linke
2024-05-09 10:02:17 +10:00
parent 6b2bb0bd32
commit 9ca6519fb1
2 changed files with 40 additions and 26 deletions

View File

@@ -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 }

View File

@@ -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