diff --git a/features/core.feature b/features/core.feature index 1b534fa0..057db399 100644 --- a/features/core.feature +++ b/features/core.feature @@ -33,19 +33,21 @@ Feature: Basic reading and writing to a journal When we run "jrnl -n 1" Then the output should contain "2013-07-23 09:00 A cold and stormy day." + @skip_win Scenario: Writing an empty entry from the editor Given we use the config "editor.yaml" When we open the editor and enter nothing Then we should see the message "[Nothing saved to file]" + @skip_win Scenario: Sending an argument with spaces to the editor should work Given we use the config "editor-args.yaml" When we open the editor and enter "lorem ipsum" Then the editor should have been called with 5 arguments - And the editor arguments should contain "vim" - And the editor arguments should contain "-f" - And the editor arguments should contain "-c" - And the editor arguments should contain "setf markdown" + And one editor argument should be "vim" + And one editor argument should be "-f" + And one editor argument should be "-c" + And one editor argument should match "'?setf markdown'?" Scenario: Writing an empty entry from the command line Given we use the config "basic.yaml" diff --git a/features/steps/core.py b/features/steps/core.py index cd00701c..99ac9859 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -2,6 +2,7 @@ import ast from collections import defaultdict import os from pathlib import Path +import re import shlex import sys import time @@ -101,9 +102,21 @@ def count_editor_args(context, num): assert len(context.editor_command) == int(num) -@then('the editor arguments should contain "{arg}"') +@then('one editor argument should be "{arg}"') def contains_editor_arg(context, arg): - assert arg in context.editor_command + args = context.editor_command + assert ( + arg in args and args.count(arg) == 1 + ), f"\narg not in args exactly 1 time:\n{arg}\n{str(args)}" + + +@then('one editor argument should match "{regex}"') +def matches_editor_arg(context, regex): + args = context.editor_command + matches = list(filter(lambda x: re.match(regex, x), args)) + assert ( + len(matches) == 1 + ), f"\nRegex didn't match exactly 1 time:\n{regex}\n{str(args)}" def _mock_getpass(inputs): @@ -169,7 +182,7 @@ def run(context, command, cache_dir=None): args = ushlex(command) try: - with patch('sys.argv', args): + with patch("sys.argv", args): cli.run(args[1:]) context.exit_status = 0 except SystemExit as e: