Blob Blame History Raw
From 01f468c61eecc83d931cb56434394770557c60c7 Mon Sep 17 00:00:00 2001
From: Matijs van Zuijlen <matijs@matijs.net>
Date: Sun, 16 Jan 2022 11:29:55 +0100
Subject: [PATCH] Ensure Gem.win_platform? is available

Even though rubygems is nearly always loaded by ruby automatically, it
is possible to avoid doing so. Therefore, to make platform detection
work, we have to require "rubygems" explicitly.
---
 lib/aruba/platforms/unix_platform.rb          |  1 +
 spec/aruba/platforms/unix_platform_spec.rb    | 18 ++++++++++++++++++
 spec/aruba/platforms/windows_platform_spec.rb | 18 ++++++++++++++++++
 3 files changed, 37 insertions(+)
 create mode 100644 spec/aruba/platforms/unix_platform_spec.rb
 create mode 100644 spec/aruba/platforms/windows_platform_spec.rb

diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb
index 2831bbb26..51f653ff9 100644
--- a/lib/aruba/platforms/unix_platform.rb
+++ b/lib/aruba/platforms/unix_platform.rb
@@ -1,4 +1,5 @@
 require "rbconfig"
+require "rubygems"
 require "pathname"
 
 require "aruba/aruba_path"
diff --git a/spec/aruba/platforms/unix_platform_spec.rb b/spec/aruba/platforms/unix_platform_spec.rb
new file mode 100644
index 000000000..75718f726
--- /dev/null
+++ b/spec/aruba/platforms/unix_platform_spec.rb
@@ -0,0 +1,18 @@
+require "spec_helper"
+require "aruba/platforms/unix_platform"
+
+RSpec.describe Aruba::Platforms::UnixPlatform do
+  include_context "uses aruba API"
+
+  describe ".match?" do
+    it "works even when ruby is launched with --disable-gems and --disable-rubyopt" do
+      aruba_lib = File.expand_path("../../../lib", __dir__)
+      run_command_and_stop(
+        "ruby --disable-rubyopt --disable-gems -I#{aruba_lib}" \
+        " -e 'require \"aruba/platforms/unix_platform\";" \
+        " Aruba::Platforms::UnixPlatform.match?;'"
+      )
+      expect(last_command_started).to be_successfully_executed
+    end
+  end
+end
diff --git a/spec/aruba/platforms/windows_platform_spec.rb b/spec/aruba/platforms/windows_platform_spec.rb
new file mode 100644
index 000000000..5ae02e8ab
--- /dev/null
+++ b/spec/aruba/platforms/windows_platform_spec.rb
@@ -0,0 +1,18 @@
+require "spec_helper"
+require "aruba/platforms/windows_platform"
+
+RSpec.describe Aruba::Platforms::WindowsPlatform do
+  include_context "uses aruba API"
+
+  describe ".match?" do
+    it "works even when ruby is launched with --disable-gems and --disable-rubyopt" do
+      aruba_lib = File.expand_path("../../../lib", __dir__)
+      run_command_and_stop(
+        "ruby --disable-rubyopt --disable-gems -I#{aruba_lib}" \
+        " -e 'require \"aruba/platforms/windows_platform\";" \
+        " Aruba::Platforms::WindowsPlatform.match?;'"
+      )
+      expect(last_command_started).to be_successfully_executed
+    end
+  end
+end