Skip to content
Merged
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
16 changes: 11 additions & 5 deletions test/rbs/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def refute_cli_success(exit_status = nil, &)
assert_predicate exit_status, :nonzero?, "Expected CLI to succeed, but it failed with status: #{exit_status.inspect}"
end

# Command to run `bundle` with the Ruby running the tests
#
# The `bundle` executable found in `PATH` may belong to another Ruby installation, which aborts
# with a version mismatch error when `RUBYLIB` points at the standard library of the running Ruby.
# That is what happens in ruby/ruby CI, where the tests run with a freshly built `ruby`.
#
BUNDLE_COMMAND = [RbConfig.ruby, "-S", "bundle"]

# Run `rbs collection` with fresh bundler environment
#
# You need this method to test `rbs collection` features.
Expand All @@ -35,20 +43,18 @@ def refute_cli_success(exit_status = nil, &)
# - If `bundler: true` is given, it runs `rbs collection` command with `bundle exec`
# - If `bundler: false` is given, it runs `rbs collection` command without `bundle exec`
#
# We cannot run tests that uses this method in ruby CI.
#
def run_rbs_collection(*commands, bundler:)
stdout, stderr, status =
Bundler.with_unbundled_env do
bundle_exec = []
bundle_exec = ["bundle", "exec"] if bundler
bundle_exec = [*BUNDLE_COMMAND, "exec"] if bundler

rbs_path = Pathname("#{__dir__}/../../lib").cleanpath.to_s
if rblib = ENV["RUBYLIB"]
rbs_path << (":" + rblib)
end

Open3.capture3({ "RUBYLIB" => rbs_path }, *bundle_exec, "#{__dir__}/../../exe/rbs", "--log-level=debug", "collection", *commands, chdir: Dir.pwd)
Open3.capture3({ "RUBYLIB" => rbs_path }, *bundle_exec, RbConfig.ruby, "#{__dir__}/../../exe/rbs", "--log-level=debug", "collection", *commands, chdir: Dir.pwd)
end

if block_given?
Expand Down Expand Up @@ -83,7 +89,7 @@ def bundle_install(*gems)
#{gems.join("\n")}
RUBY

Open3.capture3("bundle", "install", chdir: Dir.pwd)
Open3.capture3(*BUNDLE_COMMAND, "install", chdir: Dir.pwd)
end

assert_predicate status, :success?, stderr
Expand Down
Loading