diff --git a/features/data/configs/dayone.yaml b/features/data/configs/dayone.yaml index 5b8f4aa4..894cb911 100644 --- a/features/data/configs/dayone.yaml +++ b/features/data/configs/dayone.yaml @@ -1,10 +1,9 @@ default_hour: 9 default_minute: 0 -editor: '' +editor: noop template: false encrypt: false highlight: true -editor: noop journals: default: features/journals/dayone.dayone linewrap: 80 diff --git a/features/dayone.feature b/features/dayone.feature index 0efc7bfd..1b81cc38 100644 --- a/features/dayone.feature +++ b/features/dayone.feature @@ -81,3 +81,14 @@ Feature: Dayone specific implementation details. When we run "jrnl --edit" Then we should get no error + Scenario: Editing Dayone entries + Given we use the config "dayone.yaml" + When we open the editor and append + """ + Here is the first line. + Here is the second line. + """ + When we run "jrnl -n 5" + Then we should get no error + and the output should contain "Here is the first line" + and the output should contain "Here is the second line" diff --git a/features/steps/core.py b/features/steps/core.py index 00ff34a9..c1e00a00 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -101,15 +101,24 @@ def move_up_dir(context, path): os.chdir(path) -@when('we open the editor and enter "{text}"') -@when("we open the editor and enter nothing") -def open_editor_and_enter(context, text=""): +@when('we open the editor and {method}') +@when('we open the editor and {method} "{text}"') +@when("we open the editor and {method} nothing") +@when("we open the editor and {method} nothing") +def open_editor_and_enter(context, method, text=""): text = text or context.text or "" + if method == "enter": + file_method = "w+" + elif method == "append": + file_method = "a" + else: + file_method = "r+" + def _mock_editor_function(command): context.editor_command = command tmpfile = command[-1] - with open(tmpfile, "w+") as f: + with open(tmpfile, file_method) as f: f.write(text) return tmpfile @@ -120,7 +129,7 @@ def open_editor_and_enter(context, text=""): patch("subprocess.call", side_effect=_mock_editor_function), \ patch("sys.stdin.isatty", return_value=True) \ : - context.execute_steps('when we run "jrnl"') + cli.run(["--edit"]) # fmt: on @@ -287,8 +296,7 @@ def check_output_version_inline(context): def check_output_inline(context, text=None, text2=None): text = text or context.text out = context.stdout_capture.getvalue() - assert text in out or text2 in out, text or text2 - + assert (text and text in out) or (text2 and text2 in out) @then("the error output should contain") @then('the error output should contain "{text}"')