From 6d169c1b08b805ad8c8fddcf58f9edd589442a1a Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 5 Oct 2020 12:20:43 +0100 Subject: [PATCH] Improve Webmock debugging --- spec/spec_helper.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 539b7a31ab..782e55095f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -120,6 +120,7 @@ RSpec.configure do |config| .select { |s| s.driver.is_a?(Capybara::Selenium::Driver) } .each { |s| s.driver.reset! } end + config.before(:all) { restart_driver } # Enable caching in any specs tagged with `caching: true`. Usage is exactly the same as the # well-known `js: true` tag used to enable javascript in feature specs. @@ -139,7 +140,18 @@ RSpec.configure do |config| end end - config.before(:all) { restart_driver } + # Webmock raises errors that inherit directly from Exception (not StandardError). + # The messages contain useful information for debugging stubbed requests to external + # services (in tests), but they normally don't appear in the test output. + config.before(:all) do + ApplicationController.class_eval do + rescue_from WebMock::NetConnectNotAllowedError, with: :handle_webmock_error + + def handle_webmock_error(exception) + raise exception.message + end + end + end # Geocoding config.before(:each) { allow_any_instance_of(Spree::Address).to receive(:geocode).and_return([1, 1]) }