Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
from thefuck.rules.rails_migrations_pending import match, get_new_command | ||
from thefuck.types import Command | ||
|
||
output_env_development = ''' | ||
Migrations are pending. To resolve this issue, run: | ||
rails db:migrate RAILS_ENV=development | ||
''' | ||
output_env_test = ''' | ||
Migrations are pending. To resolve this issue, run: | ||
bin/rails db:migrate RAILS_ENV=test | ||
''' | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command", | ||
[ | ||
Command("", output_env_development), | ||
Command("", output_env_test), | ||
], | ||
) | ||
def test_match(command): | ||
assert match(command) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command", | ||
[ | ||
Command("Environment data not found in the schema. To resolve this issue, run: \n\n", ""), | ||
], | ||
) | ||
def test_not_match(command): | ||
assert not match(command) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command, new_command", | ||
[ | ||
(Command("", output_env_development), "rails db:migrate RAILS_ENV=development"), | ||
(Command("", output_env_test), "bin/rails db:migrate RAILS_ENV=test"), | ||
], | ||
) | ||
def test_get_new_command(command, new_command): | ||
assert get_new_command(command) == new_command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import re | ||
|
||
|
||
SUGGESTION_REGEX = r"To resolve this issue, run:\s+(.*?)\n" | ||
|
||
|
||
def match(command): | ||
return "Migrations are pending. To resolve this issue, run:" in command.output | ||
|
||
|
||
def get_new_command(command): | ||
return re.search(SUGGESTION_REGEX, command.output).group(1) |