mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
Merge pull request #1672 from pre-commit/ruby_default
don't call rbenv install for language_version = default
This commit is contained in:
commit
4aa249c8a5
2 changed files with 33 additions and 11 deletions
|
|
@ -121,7 +121,7 @@ def install_environment(
|
||||||
# Need to call this before installing so rbenv's directories
|
# Need to call this before installing so rbenv's directories
|
||||||
# are set up
|
# are set up
|
||||||
helpers.run_setup_cmd(prefix, ('rbenv', 'init', '-'))
|
helpers.run_setup_cmd(prefix, ('rbenv', 'init', '-'))
|
||||||
# XXX: this will *always* fail if `version == C.DEFAULT`
|
if version != C.DEFAULT:
|
||||||
_install_ruby(prefix, version)
|
_install_ruby(prefix, version)
|
||||||
# Need to call this after installing to set up the shims
|
# Need to call this after installing to set up the shims
|
||||||
helpers.run_setup_cmd(prefix, ('rbenv', 'rehash'))
|
helpers.run_setup_cmd(prefix, ('rbenv', 'rehash'))
|
||||||
|
|
|
||||||
|
|
@ -30,23 +30,45 @@ def test_uses_system_if_both_gem_and_ruby_are_available(find_exe_mck):
|
||||||
assert ACTUAL_GET_DEFAULT_VERSION() == 'system'
|
assert ACTUAL_GET_DEFAULT_VERSION() == 'system'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def fake_gem_prefix(tmpdir):
|
||||||
|
gemspec = '''\
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = 'pre_commit_dummy_package'
|
||||||
|
s.version = '0.0.0'
|
||||||
|
s.summary = 'dummy gem for pre-commit hooks'
|
||||||
|
s.authors = ['Anthony Sottile']
|
||||||
|
end
|
||||||
|
'''
|
||||||
|
tmpdir.join('dummy_gem.gemspec').write(gemspec)
|
||||||
|
yield Prefix(tmpdir)
|
||||||
|
|
||||||
|
|
||||||
@xfailif_windows # pragma: win32 no cover
|
@xfailif_windows # pragma: win32 no cover
|
||||||
def test_install_rbenv(tempdir_factory):
|
def test_install_ruby_system(fake_gem_prefix):
|
||||||
prefix = Prefix(tempdir_factory.get())
|
ruby.install_environment(fake_gem_prefix, 'system', ())
|
||||||
ruby._install_rbenv(prefix, C.DEFAULT)
|
|
||||||
|
# Should be able to activate and use rbenv install
|
||||||
|
with ruby.in_env(fake_gem_prefix, 'system'):
|
||||||
|
_, out, _ = cmd_output('gem', 'list')
|
||||||
|
assert 'pre_commit_dummy_package' in out
|
||||||
|
|
||||||
|
|
||||||
|
@xfailif_windows # pragma: win32 no cover
|
||||||
|
def test_install_ruby_default(fake_gem_prefix):
|
||||||
|
ruby.install_environment(fake_gem_prefix, C.DEFAULT, ())
|
||||||
# Should have created rbenv directory
|
# Should have created rbenv directory
|
||||||
assert os.path.exists(prefix.path('rbenv-default'))
|
assert os.path.exists(fake_gem_prefix.path('rbenv-default'))
|
||||||
|
|
||||||
# Should be able to activate using our script and access rbenv
|
# Should be able to activate using our script and access rbenv
|
||||||
with ruby.in_env(prefix, 'default'):
|
with ruby.in_env(fake_gem_prefix, 'default'):
|
||||||
cmd_output('rbenv', '--help')
|
cmd_output('rbenv', '--help')
|
||||||
|
|
||||||
|
|
||||||
@xfailif_windows # pragma: win32 no cover
|
@xfailif_windows # pragma: win32 no cover
|
||||||
def test_install_rbenv_with_version(tempdir_factory):
|
def test_install_ruby_with_version(fake_gem_prefix):
|
||||||
prefix = Prefix(tempdir_factory.get())
|
ruby.install_environment(fake_gem_prefix, '2.7.2', ())
|
||||||
ruby._install_rbenv(prefix, version='1.9.3p547')
|
|
||||||
|
|
||||||
# Should be able to activate and use rbenv install
|
# Should be able to activate and use rbenv install
|
||||||
with ruby.in_env(prefix, '1.9.3p547'):
|
with ruby.in_env(fake_gem_prefix, '2.7.2'):
|
||||||
cmd_output('rbenv', 'install', '--help')
|
cmd_output('rbenv', 'install', '--help')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue