Skip to content

Commit 4aa249c

Browse files
authored
Merge pull request #1672 from pre-commit/ruby_default
don't call rbenv install for language_version = default
2 parents b2207e5 + e05ac1e commit 4aa249c

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

pre_commit/languages/ruby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ def install_environment(
121121
# Need to call this before installing so rbenv's directories
122122
# are set up
123123
helpers.run_setup_cmd(prefix, ('rbenv', 'init', '-'))
124-
# XXX: this will *always* fail if `version == C.DEFAULT`
125-
_install_ruby(prefix, version)
124+
if version != C.DEFAULT:
125+
_install_ruby(prefix, version)
126126
# Need to call this after installing to set up the shims
127127
helpers.run_setup_cmd(prefix, ('rbenv', 'rehash'))
128128

tests/languages/ruby_test.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,45 @@ def test_uses_system_if_both_gem_and_ruby_are_available(find_exe_mck):
3030
assert ACTUAL_GET_DEFAULT_VERSION() == 'system'
3131

3232

33+
@pytest.fixture
34+
def fake_gem_prefix(tmpdir):
35+
gemspec = '''\
36+
Gem::Specification.new do |s|
37+
s.name = 'pre_commit_dummy_package'
38+
s.version = '0.0.0'
39+
s.summary = 'dummy gem for pre-commit hooks'
40+
s.authors = ['Anthony Sottile']
41+
end
42+
'''
43+
tmpdir.join('dummy_gem.gemspec').write(gemspec)
44+
yield Prefix(tmpdir)
45+
46+
47+
@xfailif_windows # pragma: win32 no cover
48+
def test_install_ruby_system(fake_gem_prefix):
49+
ruby.install_environment(fake_gem_prefix, 'system', ())
50+
51+
# Should be able to activate and use rbenv install
52+
with ruby.in_env(fake_gem_prefix, 'system'):
53+
_, out, _ = cmd_output('gem', 'list')
54+
assert 'pre_commit_dummy_package' in out
55+
56+
3357
@xfailif_windows # pragma: win32 no cover
34-
def test_install_rbenv(tempdir_factory):
35-
prefix = Prefix(tempdir_factory.get())
36-
ruby._install_rbenv(prefix, C.DEFAULT)
58+
def test_install_ruby_default(fake_gem_prefix):
59+
ruby.install_environment(fake_gem_prefix, C.DEFAULT, ())
3760
# Should have created rbenv directory
38-
assert os.path.exists(prefix.path('rbenv-default'))
61+
assert os.path.exists(fake_gem_prefix.path('rbenv-default'))
3962

4063
# Should be able to activate using our script and access rbenv
41-
with ruby.in_env(prefix, 'default'):
64+
with ruby.in_env(fake_gem_prefix, 'default'):
4265
cmd_output('rbenv', '--help')
4366

4467

4568
@xfailif_windows # pragma: win32 no cover
46-
def test_install_rbenv_with_version(tempdir_factory):
47-
prefix = Prefix(tempdir_factory.get())
48-
ruby._install_rbenv(prefix, version='1.9.3p547')
69+
def test_install_ruby_with_version(fake_gem_prefix):
70+
ruby.install_environment(fake_gem_prefix, '2.7.2', ())
4971

5072
# Should be able to activate and use rbenv install
51-
with ruby.in_env(prefix, '1.9.3p547'):
73+
with ruby.in_env(fake_gem_prefix, '2.7.2'):
5274
cmd_output('rbenv', 'install', '--help')

0 commit comments

Comments
 (0)