Also stub-out with directry using with test script or -e option

This commit is contained in:
Hiroshi SHIBATA 2025-01-08 11:09:36 +09:00
parent 4a02a72ca5
commit 27c9ccb30e
Notes: git 2025-01-08 02:55:57 +00:00

View File

@ -55,14 +55,19 @@ RSpec.configure do |config|
end
RSpec.describe "bundled_gems.rb" do
def script(code, options = {})
options[:artifice] ||= "compact_index"
code = <<~RUBY
let(:stub_code) {
<<~STUB
Gem::BUNDLED_GEMS.send(:remove_const, :LIBDIR)
Gem::BUNDLED_GEMS.send(:remove_const, :ARCHDIR)
Gem::BUNDLED_GEMS.const_set(:LIBDIR, File.expand_path(File.join(__dir__, "../../..", "lib")) + "/")
Gem::BUNDLED_GEMS.const_set(:ARCHDIR, File.expand_path($LOAD_PATH.find{|path| path.include?(".ext/common") }) + "/")
STUB
}
def script(code, options = {})
options[:artifice] ||= "compact_index"
code = <<~RUBY
#{stub_code}
require 'bundler/inline'
#{code}
@ -143,6 +148,7 @@ RSpec.describe "bundled_gems.rb" do
it "Show warning when bundle exec with ruby and script" do
code = <<-RUBY
#{stub_code}
require "ostruct"
RUBY
create_file("script.rb", code)
@ -151,7 +157,7 @@ RSpec.describe "bundled_gems.rb" do
bundle "exec ruby script.rb"
expect(err).to include(/ostruct was loaded from (.*) from Ruby 3.5.0/)
expect(err).to include(/script\.rb:1/)
expect(err).to include(/script\.rb:6/)
end
it "Show warning when bundle exec with shebang's script" do
@ -159,6 +165,7 @@ RSpec.describe "bundled_gems.rb" do
code = <<-RUBY
#!/usr/bin/env ruby
#{stub_code}
require "ostruct"
RUBY
create_file("script.rb", code)
@ -168,12 +175,13 @@ RSpec.describe "bundled_gems.rb" do
bundle "exec ./script.rb"
expect(err).to include(/ostruct was loaded from (.*) from Ruby 3.5.0/)
expect(err).to include(/script\.rb:2/)
expect(err).to include(/script\.rb:7/)
end
it "Show warning when bundle exec with -r option" do
create_file("stub.rb", stub_code)
create_file("Gemfile", "source 'https://rubygems.org'")
bundle "exec ruby -rostruct -e ''"
bundle "exec ruby -r./stub -rostruct -e ''"
expect(err).to include(/ostruct was loaded from (.*) from Ruby 3.5.0/)
end
@ -298,6 +306,7 @@ RSpec.describe "bundled_gems.rb" do
it "Show warning with zeitwerk" do
libpath = Dir[File.expand_path("../.bundle/gems/{zeitwerk}-*/lib", __dir__)].map(&:to_s).first
code = <<-RUBY
#{stub_code}
$LOAD_PATH.unshift("#{libpath}")
require "zeitwerk"
loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
@ -310,7 +319,7 @@ RSpec.describe "bundled_gems.rb" do
bundle "exec ruby script.rb"
expect(err).to include(/ostruct was loaded from (.*) from Ruby 3.5.0/)
expect(err).to include(/script\.rb:6/)
expect(err).to include(/script\.rb:11/)
end
it "Don't show warning fiddle/import when fiddle on Gemfile" do
@ -353,8 +362,9 @@ RSpec.describe "bundled_gems.rb" do
end
it "Don't show warning for reline when using irb from standard library" do
create_file("stub.rb", stub_code)
create_file("Gemfile", "source 'https://rubygems.org'")
bundle "exec ruby -rirb -e ''"
bundle "exec ruby -r./stub -rirb -e ''"
expect(err).to include(/irb was loaded from (.*) from Ruby 3.5.0/)
expect(err).to_not include(/reline was loaded from (.*) from Ruby 3.5.0/)