diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb index ce016e3ad2..5365338823 100644 --- a/lib/bundler/cli/doctor.rb +++ b/lib/bundler/cli/doctor.rb @@ -2,7 +2,6 @@ require "rbconfig" require "shellwords" -require "fiddle" module Bundler class CLI::Doctor @@ -57,6 +56,14 @@ module Bundler Dir.glob("#{spec.full_gem_path}/**/*.bundle") end + def lookup_with_fiddle(path) + require "fiddle" + Fiddle.dlopen(path) + false + rescue Fiddle::DLError + true + end + def check! require_relative "check" Bundler::CLI::Check.new({}).run @@ -73,10 +80,7 @@ module Bundler definition.specs.each do |spec| bundles_for_gem(spec).each do |bundle| bad_paths = dylibs(bundle).select do |f| - Fiddle.dlopen(f) - false - rescue Fiddle::DLError - true + lookup_with_fiddle(f) end if bad_paths.any? broken_links[spec] ||= [] diff --git a/spec/bundler/commands/doctor_spec.rb b/spec/bundler/commands/doctor_spec.rb index 744510cd40..d6dd362c2b 100644 --- a/spec/bundler/commands/doctor_spec.rb +++ b/spec/bundler/commands/doctor_spec.rb @@ -54,16 +54,20 @@ RSpec.describe "bundle doctor" do doctor = Bundler::CLI::Doctor.new({}) expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"] expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/lib/libSystem.dylib"] - allow(Fiddle).to receive(:dlopen).with("/usr/lib/libSystem.dylib").and_return(true) + allow(doctor).to receive(:lookup_with_fiddle).with("/usr/lib/libSystem.dylib").and_return(false) expect { doctor.run }.not_to raise_error expect(@stdout.string).to be_empty end + class Fiddle + class DLError < StandardError; end + end unless defined?(Fiddle) + it "exits with a message if one of the linked libraries is missing" do doctor = Bundler::CLI::Doctor.new({}) expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"] expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib"] - allow(Fiddle).to receive(:dlopen).with("/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib").and_raise(Fiddle::DLError) + allow(doctor).to receive(:lookup_with_fiddle).with("/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib").and_return(true) expect { doctor.run }.to raise_error(Bundler::ProductionError, <<~E.strip), @stdout.string The following gems are missing OS dependencies: * bundler: /usr/local/opt/icu4c/lib/libicui18n.57.1.dylib