summaryrefslogtreecommitdiff
path: root/spec/support/artifice/fail.rb
blob: 2ef009c7c88dd1db432442dd8511f0f3a6815fc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

require File.expand_path("../../path.rb", __FILE__)

# 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"

class Fail
  def call(env)
    raise(exception(env))
  end

  def exception(env)
    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"]}")
  end
end
Artifice.activate_with(Fail.new)