diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2016-11-28 11:07:45 -0600 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-12-21 18:02:10 +0100 |
commit | e1514acaedc1d051439fe308f6310633c2b57edc (patch) | |
tree | 628440af17fe129ee6e0e1bf7743379f3a5a564e | |
parent | f48c16cdc9ad3e48c242eeb210db558c3100539a (diff) | |
download | bundler-e1514acaedc1d051439fe308f6310633c2b57edc.tar.gz |
Don’t use Artifice for the fail endpoint
This avoids loading rack, which conflicts with some specs
-rw-r--r-- | spec/support/artifice/fail.rb | 27 |
1 files 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 |