From 9e0a5dd2bb8dcd9940c30fc1e2fc4cd30cdf52fb Mon Sep 17 00:00:00 2001 From: Gabriel Abramzon Date: Fri, 30 Aug 2019 14:30:48 +0300 Subject: [PATCH] support rbenv install --- tests/rules/test_rbenv_install.py | 25 +++++++++++++++++++++++++ thefuck/rules/rbenv_install.py | 14 ++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/rules/test_rbenv_install.py create mode 100644 thefuck/rules/rbenv_install.py diff --git a/tests/rules/test_rbenv_install.py b/tests/rules/test_rbenv_install.py new file mode 100644 index 00000000..a585d0a9 --- /dev/null +++ b/tests/rules/test_rbenv_install.py @@ -0,0 +1,25 @@ +import pytest +from thefuck.rules.rbenv_install import match, get_new_command +from thefuck.types import Command + +expected_new_command = """cd /home/alex/.rbenv/plugins/ruby-build && git pull && cd -""" +expected_output = """ruby-build: definition not found: 2.6.1 + +See all available versions with `rbenv install --list'. + +If the version you need is missing, try upgrading ruby-build: + + %s""" % expected_new_command + + +@pytest.mark.parametrize('script, output', [ + ('rbenv install 2.6.1', expected_output) + ]) +def test_match(script, output): + assert match(Command(script, output)) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('rbenv install 2.6.1', expected_output), expected_new_command)]) +def test_get_new_command(command, new_command): + assert get_new_command(command) == new_command diff --git a/thefuck/rules/rbenv_install.py b/thefuck/rules/rbenv_install.py new file mode 100644 index 00000000..93af73c7 --- /dev/null +++ b/thefuck/rules/rbenv_install.py @@ -0,0 +1,14 @@ +from thefuck.shells import shell +from thefuck.utils import for_app + + +@for_app('rbenv') +def match(command): + return ('ruby-build: definition not found' in command.output.lower() and + 'if the version you need is missing, try upgrading ruby-build' in command.output.lower() + ) + + +def get_new_command(command): + output = command.output.split('\n')[-1].lstrip() + return shell.to_shell(output)