Skip to content

Commit 470784c

Browse files
committed
Expand stub-out scope of Fiddle.dlopen
1 parent ec2bd6f commit 470784c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/bundler/cli/doctor.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require "rbconfig"
44
require "shellwords"
5-
require "fiddle"
65

76
module Bundler
87
class CLI::Doctor
@@ -57,6 +56,14 @@ def bundles_for_gem(spec)
5756
Dir.glob("#{spec.full_gem_path}/**/*.bundle")
5857
end
5958

59+
def lookup_with_fiddle(path)
60+
require "fiddle"
61+
Fiddle.dlopen(path)
62+
false
63+
rescue Fiddle::DLError
64+
true
65+
end
66+
6067
def check!
6168
require_relative "check"
6269
Bundler::CLI::Check.new({}).run
@@ -73,10 +80,7 @@ def run
7380
definition.specs.each do |spec|
7481
bundles_for_gem(spec).each do |bundle|
7582
bad_paths = dylibs(bundle).select do |f|
76-
Fiddle.dlopen(f)
77-
false
78-
rescue Fiddle::DLError
79-
true
83+
lookup_with_fiddle(f)
8084
end
8185
if bad_paths.any?
8286
broken_links[spec] ||= []

spec/bundler/commands/doctor_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,20 @@
5454
doctor = Bundler::CLI::Doctor.new({})
5555
expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"]
5656
expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/lib/libSystem.dylib"]
57-
allow(Fiddle).to receive(:dlopen).with("/usr/lib/libSystem.dylib").and_return(true)
57+
allow(doctor).to receive(:lookup_with_fiddle).with("/usr/lib/libSystem.dylib").and_return(false)
5858
expect { doctor.run }.not_to raise_error
5959
expect(@stdout.string).to be_empty
6060
end
6161

62+
class Fiddle
63+
class DLError < StandardError; end
64+
end unless defined?(Fiddle)
65+
6266
it "exits with a message if one of the linked libraries is missing" do
6367
doctor = Bundler::CLI::Doctor.new({})
6468
expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"]
6569
expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib"]
66-
allow(Fiddle).to receive(:dlopen).with("/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib").and_raise(Fiddle::DLError)
70+
allow(doctor).to receive(:lookup_with_fiddle).with("/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib").and_return(true)
6771
expect { doctor.run }.to raise_error(Bundler::ProductionError, <<~E.strip), @stdout.string
6872
The following gems are missing OS dependencies:
6973
* bundler: /usr/local/opt/icu4c/lib/libicui18n.57.1.dylib

0 commit comments

Comments
 (0)