mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-14 17:41:45 +04:00
Support ruby through a combination of rbenv, ruby-build, and GEM_HOME
This commit is contained in:
parent
390af24c44
commit
b381bb68b7
10 changed files with 124 additions and 24 deletions
|
|
@ -13,6 +13,7 @@ from pre_commit import five
|
|||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
||||
from pre_commit.store import Store
|
||||
from testing.util import copy_tree_to_path
|
||||
from testing.util import get_head_sha
|
||||
|
|
@ -76,6 +77,11 @@ def node_hooks_repo(dummy_git_repo):
|
|||
yield _make_repo(dummy_git_repo, 'node_hooks_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def ruby_hooks_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'ruby_hooks_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def consumer_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'consumer_repo')
|
||||
|
|
@ -112,6 +118,11 @@ def config_for_node_hooks_repo(node_hooks_repo):
|
|||
yield _make_config(node_hooks_repo, 'foo', '\\.js$')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_ruby_hooks_repo(ruby_hooks_repo):
|
||||
yield _make_config(ruby_hooks_repo, 'ruby_hook', '\\.rb$')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_python_hooks_repo(python_hooks_repo):
|
||||
yield _make_config(python_hooks_repo, 'foo', '\\.py$')
|
||||
|
|
@ -206,3 +217,8 @@ def mock_out_store_directory(tmpdir_factory):
|
|||
@pytest.yield_fixture
|
||||
def store(tmpdir_factory):
|
||||
yield Store(os.path.join(tmpdir_factory.get(), '.pre-commit'))
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def cmd_runner(tmpdir_factory):
|
||||
yield PrefixedCommandRunner(tmpdir_factory.get())
|
||||
|
|
|
|||
23
tests/languages/ruby_test.py
Normal file
23
tests/languages/ruby_test.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import os.path
|
||||
|
||||
from pre_commit.languages.ruby import _install_rbenv
|
||||
|
||||
|
||||
def test_install_rbenv(cmd_runner):
|
||||
_install_rbenv(cmd_runner)
|
||||
# Should have created rbenv directory
|
||||
assert os.path.exists(cmd_runner.path('rbenv'))
|
||||
# It should be a git checkout
|
||||
assert os.path.exists(cmd_runner.path('rbenv', '.git'))
|
||||
# We should have created our `activate` script
|
||||
activate_path = cmd_runner.path('rbenv', 'bin', 'activate')
|
||||
assert os.path.exists(activate_path)
|
||||
|
||||
# Should be able to activate using our script and access the install method
|
||||
cmd_runner.run(
|
||||
[
|
||||
'bash',
|
||||
'-c',
|
||||
'. {prefix}/rbenv/bin/activate && rbenv install --help',
|
||||
],
|
||||
)
|
||||
|
|
@ -6,6 +6,7 @@ from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
|||
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from pre_commit.repository import Repository
|
||||
from testing.util import skipif_slowtests_false
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
|
|
@ -19,7 +20,6 @@ def test_install_python_repo_in_env(config_for_python_hooks_repo, store):
|
|||
def test_run_a_python_hook(config_for_python_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
ret = repo.run_hook('foo', ['/dev/null'])
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == "['/dev/null']\nHello World\n"
|
||||
|
||||
|
|
@ -28,7 +28,6 @@ def test_run_a_python_hook(config_for_python_hooks_repo, store):
|
|||
def test_lots_of_files(config_for_python_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
ret = repo.run_hook('foo', ['/dev/null'] * 15000)
|
||||
|
||||
assert ret[0] == 0
|
||||
|
||||
|
||||
|
|
@ -37,24 +36,29 @@ def test_cwd_of_hook(config_for_prints_cwd_repo, store):
|
|||
# Note: this doubles as a test for `system` hooks
|
||||
repo = Repository.create(config_for_prints_cwd_repo, store)
|
||||
ret = repo.run_hook('prints_cwd', [])
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == repo.repo_url + '\n'
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
os.environ.get('slowtests', None) == 'false',
|
||||
reason="TODO: make this test not super slow",
|
||||
)
|
||||
@skipif_slowtests_false
|
||||
@pytest.mark.integration
|
||||
def test_run_a_node_hook(config_for_node_hooks_repo, store):
|
||||
repo = Repository.create(config_for_node_hooks_repo, store)
|
||||
ret = repo.run_hook('foo', [])
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'Hello World\n'
|
||||
|
||||
|
||||
@pytest.mark.herpderp
|
||||
@skipif_slowtests_false
|
||||
@pytest.mark.integration
|
||||
def test_run_a_ruby_hook(config_for_ruby_hooks_repo, store):
|
||||
repo = Repository.create(config_for_ruby_hooks_repo, store)
|
||||
ret = repo.run_hook('ruby_hook', [])
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'Hello world from a ruby hook\n'
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_a_script_hook(config_for_script_hooks_repo, store):
|
||||
repo = Repository.create(config_for_script_hooks_repo, store)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import pytest
|
|||
import shutil
|
||||
from plumbum import local
|
||||
|
||||
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
||||
from pre_commit.staged_files_only import staged_files_only
|
||||
from testing.auto_namedtuple import auto_namedtuple
|
||||
from testing.util import get_resource_path
|
||||
|
|
@ -31,11 +30,6 @@ def foo_staged(empty_git_dir):
|
|||
yield auto_namedtuple(path=empty_git_dir, foo_filename=foo_filename)
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def cmd_runner(tmpdir_factory):
|
||||
yield PrefixedCommandRunner(tmpdir_factory.get())
|
||||
|
||||
|
||||
def _test_foo_state(path, foo_contents=FOO_CONTENTS, status='A'):
|
||||
assert os.path.exists(path.foo_filename)
|
||||
assert io.open(path.foo_filename, encoding='utf-8').read() == foo_contents
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue