mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Tests for error messages on empty directories
This commit is contained in:
parent
c849b03c5c
commit
1bab646c09
4 changed files with 46 additions and 4 deletions
14
features/data/configs/empty_folder.json
Normal file
14
features/data/configs/empty_folder.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"default_hour": 9,
|
||||||
|
"timeformat": "%Y-%m-%d %H:%M",
|
||||||
|
"linewrap": 80,
|
||||||
|
"encrypt": false,
|
||||||
|
"editor": "",
|
||||||
|
"default_minute": 0,
|
||||||
|
"highlight": true,
|
||||||
|
"password": "",
|
||||||
|
"journals": {
|
||||||
|
"default": "features/journals/empty_folder"
|
||||||
|
},
|
||||||
|
"tagsymbols": "@"
|
||||||
|
}
|
|
@ -12,6 +12,14 @@ def before_scenario(context, scenario):
|
||||||
context.messages = StringIO()
|
context.messages = StringIO()
|
||||||
jrnl.util.STDERR = context.messages
|
jrnl.util.STDERR = context.messages
|
||||||
jrnl.util.TEST = True
|
jrnl.util.TEST = True
|
||||||
|
|
||||||
|
# Clean up in case something went wrong
|
||||||
|
for folder in ("configs", "journals"):
|
||||||
|
working_dir = os.path.join("features", folder)
|
||||||
|
if os.path.exists(working_dir):
|
||||||
|
shutil.rmtree(working_dir)
|
||||||
|
|
||||||
|
|
||||||
for folder in ("configs", "journals"):
|
for folder in ("configs", "journals"):
|
||||||
original = os.path.join("features", "data", folder)
|
original = os.path.join("features", "data", folder)
|
||||||
working_dir = os.path.join("features", folder)
|
working_dir = os.path.join("features", folder)
|
||||||
|
@ -30,4 +38,5 @@ def after_scenario(context, scenario):
|
||||||
context.messages = None
|
context.messages = None
|
||||||
for folder in ("configs", "journals"):
|
for folder in ("configs", "journals"):
|
||||||
working_dir = os.path.join("features", folder)
|
working_dir = os.path.join("features", folder)
|
||||||
|
if os.path.exists(working_dir):
|
||||||
shutil.rmtree(working_dir)
|
shutil.rmtree(working_dir)
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
Feature: Zapped bugs should stay dead.
|
Feature: Zapped bugs should stay dead.
|
||||||
|
|
||||||
Scenario: Writing an entry does not print the entire journal
|
Scenario: Writing an entry does not print the entire journal
|
||||||
|
# https://github.com/maebert/jrnl/issues/87
|
||||||
Given we use the config "basic.json"
|
Given we use the config "basic.json"
|
||||||
When we run "jrnl 23 july 2013: A cold and stormy day. I ate crisps on the sofa."
|
When we run "jrnl 23 july 2013: A cold and stormy day. I ate crisps on the sofa."
|
||||||
Then we should see the message "Entry added"
|
Then we should see the message "Entry added"
|
||||||
When we run "jrnl -n 1"
|
When we run "jrnl -n 1"
|
||||||
Then the output should not contain "Life is good"
|
Then the output should not contain "Life is good"
|
||||||
|
|
||||||
|
Scenario: Opening an folder that's not a DayOne folder gives a nice error message
|
||||||
|
Given we use the config "empty_folder.json"
|
||||||
|
When we run "jrnl Herro"
|
||||||
|
Then we should get an error
|
||||||
|
Then we should see the message "is a directory, but doesn't seem to be a DayOne journal either"
|
||||||
|
|
|
@ -53,16 +53,28 @@ def run_with_input(context, command, inputs=None):
|
||||||
args = _parse_args(command)
|
args = _parse_args(command)
|
||||||
buffer = StringIO(text.strip())
|
buffer = StringIO(text.strip())
|
||||||
jrnl.util.STDIN = buffer
|
jrnl.util.STDIN = buffer
|
||||||
jrnl.cli(args)
|
try:
|
||||||
|
jrnl.cli(args or None)
|
||||||
|
context.exit_status = 0
|
||||||
|
except SystemExit as e:
|
||||||
|
context.exit_status = e.code
|
||||||
|
|
||||||
@when('we run "{command}"')
|
@when('we run "{command}"')
|
||||||
def run(context, command):
|
def run(context, command):
|
||||||
args = _parse_args(command)
|
args = _parse_args(command)
|
||||||
|
try:
|
||||||
jrnl.cli(args or None)
|
jrnl.cli(args or None)
|
||||||
|
context.exit_status = 0
|
||||||
|
except SystemExit as e:
|
||||||
|
context.exit_status = e.code
|
||||||
|
|
||||||
|
@then('we should get an error')
|
||||||
|
def has_error(context):
|
||||||
|
assert context.exit_status is not 0
|
||||||
|
|
||||||
@then('we should get no error')
|
@then('we should get no error')
|
||||||
def no_error(context):
|
def no_error(context):
|
||||||
|
assert context.exit_status is 0
|
||||||
assert context.failed is False
|
assert context.failed is False
|
||||||
|
|
||||||
@then('the output should be parsable as json')
|
@then('the output should be parsable as json')
|
||||||
|
@ -121,7 +133,7 @@ def check_output_not_inline(context, text):
|
||||||
@then('we should see the message "{text}"')
|
@then('we should see the message "{text}"')
|
||||||
def check_message(context, text):
|
def check_message(context, text):
|
||||||
out = context.messages.getvalue()
|
out = context.messages.getvalue()
|
||||||
assert text in out
|
assert text in out, [text, out]
|
||||||
|
|
||||||
@then('the journal should contain "{text}"')
|
@then('the journal should contain "{text}"')
|
||||||
@then('journal "{journal_name}" should contain "{text}"')
|
@then('journal "{journal_name}" should contain "{text}"')
|
||||||
|
|
Loading…
Add table
Reference in a new issue