From e1514acaedc1d051439fe308f6310633c2b57edc Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Mon, 28 Nov 2016 11:07:45 -0600 Subject: =?UTF-8?q?Don=E2=80=99t=20use=20Artifice=20for=20the=20fail=20end?= =?UTF-8?q?point?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids loading rack, which conflicts with some specs --- spec/support/artifice/fail.rb | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/spec/support/artifice/fail.rb b/spec/support/artifice/fail.rb index 2ef009c7c8..dbb7ab9b7a 100644 --- a/spec/support/artifice/fail.rb +++ b/spec/support/artifice/fail.rb @@ -1,20 +1,27 @@ # frozen_string_literal: true -require File.expand_path("../../path.rb", __FILE__) +require "net/http" -# Set up pretend http gem server with Artifice -$LOAD_PATH.unshift(*Dir[Spec::Path.base_system_gems.join("gems/{artifice,rack,tilt}-*/lib")].map(&:to_s)) -require "artifice" +# We can't use artifice here because it uses rack -class Fail - def call(env) - raise(exception(env)) +class Fail < Net::HTTP + def request(req, body = nil, &block) + raise(exception(req)) end - def exception(env) + # Ensure we don't start a connect here + def connect + end + + def exception(req) name = ENV.fetch("BUNDLER_SPEC_EXCEPTION") { "Errno::ENETUNREACH" } const = name.split("::").reduce(Object) {|mod, sym| mod.const_get(sym) } - const.new("host down: Bundler spec artifice fail! #{env["PATH_INFO"]}") + const.new("host down: Bundler spec artifice fail! #{req["PATH_INFO"]}") end end -Artifice.activate_with(Fail.new) + +# Replace Net::HTTP with our failing subclass +::Net.class_eval do + remove_const(:HTTP) + const_set(:HTTP, Fail) +end -- cgit v1.2.1