Skip to content

Commit

Permalink
Rename run_rbs to run_rbs_collection to avoid abuse
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Nov 14, 2023
1 parent d1c97a5 commit 03493a8
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions test/rbs/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ def stderr
@stderr ||= StringIO.new
end

def run_rbs(*commands, bundler: true)
# Run `rbs collection` with fresh bundler environment
#
# You need this method to test `rbs collection` features.
# `rbs collection` loads gems from Bundler context, so re-using the currenr Bundler context (used to develop rbs gem) causes issues.
#
# - 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 = []
Expand All @@ -26,7 +36,7 @@ def run_rbs(*commands, bundler: true)
rbs_path << (":" + rblib)
end

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

if block_given?
Expand Down Expand Up @@ -849,7 +859,7 @@ def test_collection_install
2.2.0
LOCK

_stdout, _stderr = run_rbs("collection", "install")
_stdout, _stderr = run_rbs_collection("install", bundler: true)

rbs_collection_lock = dir.join('rbs_collection.lock.yaml')
assert rbs_collection_lock.exist?
Expand All @@ -861,7 +871,7 @@ def test_collection_install

Dir.mkdir("child")
Dir.chdir("child") do
_stdout, _stderr = run_rbs("collection", "install")
_stdout, _stderr = run_rbs_collection("install", bundler: true)
assert rbs_collection_lock.exist?
assert collection_dir.exist?
end
Expand Down Expand Up @@ -891,7 +901,7 @@ def test_collection_install_frozen
YAML
dir.join('rbs_collection.lock.yaml').write(lock_content)

run_rbs("collection", "install", "--frozen", bundler: false)
run_rbs_collection("install", "--frozen", bundler: false)

refute dir.join(RBS::Collection::Config::PATH).exist?
assert dir.join('gem_rbs_collection/ast').exist?
Expand Down Expand Up @@ -933,7 +943,7 @@ def test_collection_update
2.2.0
LOCK

run_rbs("collection", "update", bundler: true)
run_rbs_collection("update", bundler: true)

assert dir.join('rbs_collection.lock.yaml').exist?
assert dir.join('gem_rbs_collection/ast').exist?
Expand Down Expand Up @@ -997,7 +1007,7 @@ def test_collection_install_gemspec
RUBY
(dir/"sig").mkdir

stdout, _ = run_rbs("collection", "install", bundler: true)
stdout, _ = run_rbs_collection("install", bundler: true)

assert_match(/Installing ast:(\d(\.\d)*)/, stdout)
refute_match(/^Using hola:(\d(\.\d)*)/, stdout)
Expand Down

0 comments on commit 03493a8

Please sign in to comment.