From 55f2917cfda6a792e4e24e8b2b98e55ff4a400fd Mon Sep 17 00:00:00 2001 From: sodacris Date: Mon, 2 Dec 2024 10:50:23 +0800 Subject: [PATCH] [rubygems/rubygems] allow `bat` files to be created alongside with script files on Windows https://github.com/rubygems/rubygems/commit/ed5b847f03 --- spec/bundler/support/helpers.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index da75c0d6d1..af45c7e425 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -235,10 +235,20 @@ module Spec end def create_file(path, contents = "") + contents = strip_whitespace(contents) path = Pathname.new(path).expand_path(bundled_app) unless path.is_a?(Pathname) path.dirname.mkpath - File.open(path.to_s, "w") do |f| - f.puts strip_whitespace(contents) + path.write(contents) + + # if the file is a script, create respective bat file on Windows + if contents.start_with?("#!") + path.chmod(0o755) + if Gem.win_platform? + path.sub_ext(".bat").write <<~SCRIPT + @ECHO OFF + @"ruby.exe" "%~dpn0" %* + SCRIPT + end end end