Got the same error also using Rails 7.1.2 with Ruby 3.3.0. Patched it using rescue, but would like to know the correct way to handle this.
test “can’t delete product in cart” do
assert_difference(“Product.count”, 0) do
delete product_url(products(:two))
rescue ActiveRecord::RecordNotDestroyed
assert true
end
end
test "can't delete product in cart" do
assert_raises(ActiveRecord::RecordNotDestroyed) do
delete product_url(products(:two))
end
assert Product.exists?(products(:two).id)
end