diff --git a/tests/rules/test_vagrant_up.py b/tests/rules/test_vagrant_up.py index f3b8e4b3..0ede9712 100644 --- a/tests/rules/test_vagrant_up.py +++ b/tests/rules/test_vagrant_up.py @@ -13,6 +13,15 @@ def test_match(command): assert match(command, None) +@pytest.mark.parametrize('command', [ + Command(script='vagrant ssh', stderr=''), + Command(script='vagrant ssh jeff', stderr='The machine with the name \'jeff\' was not found configured for this Vagrant environment.'), + Command(script='vagrant ssh', stderr='A Vagrant environment or target machine is required to run this command. Run `vagrant init` to create a new Vagrant environment. Or, get an ID of a target machine from `vagrant global-status` to run this command on. A final option is to change to a directory with a Vagrantfile and to try again.'), + Command()]) +def test_not_match(command): + assert not match(command, None) + + @pytest.mark.parametrize('command, new_command', [ (Command(script='vagrant ssh', stderr='VM must be running to open SSH connection. Run `vagrant up`\nto start the virtual machine.'), 'vagrant up && vagrant ssh'), (Command(script='vagrant ssh devbox', stderr='VM must be running to open SSH connection. Run `vagrant up`\nto start the virtual machine.'), 'vagrant up devbox && vagrant ssh devbox'), diff --git a/thefuck/rules/vagrant_up.py b/thefuck/rules/vagrant_up.py index 44954a47..1c27db48 100644 --- a/thefuck/rules/vagrant_up.py +++ b/thefuck/rules/vagrant_up.py @@ -4,9 +4,10 @@ from thefuck import shells def match(command, settings): return command.script.startswith('vagrant ') and 'run `vagrant up`' in command.stderr.lower() + def get_new_command(command, settings): cmds = command.script.split(' ') machine = "" if len(cmds) >= 3: machine = cmds[2] - return "vagrant up " + machine + " && " + command.script + return shells.and_("vagrant up " + machine, command.script)