Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bundler/lib/bundler/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ def set_path
validate_bundle_path
paths = (ENV["PATH"] || "").split(File::PATH_SEPARATOR)
paths.unshift "#{Bundler.bundle_path}/bin"
bin_dir = Bundler.settings[:bin] || "bin"
bin_path = Pathname.new(bin_dir).expand_path(Bundler.root)
paths.unshift bin_path.to_s if bin_path.directory?
Bundler::SharedHelpers.set_env "PATH", paths.uniq.join(File::PATH_SEPARATOR)
end

Expand Down
33 changes: 33 additions & 0 deletions spec/bundler/shared_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,39 @@
it_behaves_like "ENV['PATH'] gets set correctly"
end

context "when project bin/ directory exists" do
before do
Dir.mkdir bundled_app(".bundle")
Dir.mkdir(bundled_app("bin")) unless File.directory?(bundled_app("bin"))
ENV["BUNDLE_GEMFILE"] = bundled_app_gemfile.to_s
ENV["PATH"] = "/usr/bin"
end

it "prepends project bin/ to ENV['PATH'] before bundle path bin" do
subject.set_bundle_environment
paths = ENV["PATH"].split(File::PATH_SEPARATOR)
bundle_bin_index = paths.index("#{Bundler.bundle_path}/bin")
project_bin_index = paths.index(bundled_app("bin").to_s)
expect(project_bin_index).not_to be_nil
expect(project_bin_index).to be < bundle_bin_index
end
end

context "when project bin/ directory does not exist" do
before do
Dir.mkdir bundled_app(".bundle")
FileUtils.rm_rf(bundled_app("bin"))
ENV["BUNDLE_GEMFILE"] = bundled_app_gemfile.to_s
ENV["PATH"] = "/usr/bin"
end

it "does not prepend project bin/ to ENV['PATH']" do
subject.set_bundle_environment
paths = ENV["PATH"].split(File::PATH_SEPARATOR)
expect(paths).not_to include(bundled_app("bin").to_s)
end
end

context "ENV['PATH'] already contains the bundle bin path" do
let(:bundle_path) { "#{Bundler.bundle_path}/bin" }

Expand Down