mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Tests for using stderr prompts
This commit is contained in:
parent
d3edbfd53b
commit
279547c350
4 changed files with 17 additions and 4 deletions
|
@ -16,14 +16,14 @@ Feature: Basic reading and writing to a journal
|
|||
Scenario: Writing an entry from command line
|
||||
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."
|
||||
Then the output should contain "Entry added"
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl -n 1"
|
||||
Then the output should contain "2013-07-23 09:00 A cold and stormy day."
|
||||
|
||||
Scenario: Emoji support
|
||||
Given we use the config "basic.json"
|
||||
When we run "jrnl 23 july 2013: 🌞 sunny day. Saw an 🐘"
|
||||
Then the output should contain "Entry added"
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl -n 1"
|
||||
Then the output should contain "🌞"
|
||||
and the output should contain "🐘"
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
from behave import *
|
||||
import shutil
|
||||
import os
|
||||
from jrnl import jrnl
|
||||
try:
|
||||
from io import StringIO
|
||||
except ImportError:
|
||||
from cStringIO import StringIO
|
||||
|
||||
def before_scenario(context, scenario):
|
||||
"""Before each scenario, backup all config and journal test data."""
|
||||
context.messages = StringIO()
|
||||
jrnl.util.STDERR = context.messages
|
||||
for folder in ("configs", "journals"):
|
||||
original = os.path.join("features", folder)
|
||||
backup = os.path.join("features", folder+"_backup")
|
||||
|
@ -14,6 +21,8 @@ def before_scenario(context, scenario):
|
|||
|
||||
def after_scenario(context, scenario):
|
||||
"""After each scenario, restore all test data and remove backups."""
|
||||
context.messages.close()
|
||||
context.messages = None
|
||||
for folder in ("configs", "journals"):
|
||||
original = os.path.join("features", folder)
|
||||
backup = os.path.join("features", folder+"_backup")
|
||||
|
|
|
@ -20,7 +20,7 @@ Feature: Multiple journals
|
|||
Scenario: Tell user which journal was used
|
||||
Given we use the config "multiple.json"
|
||||
When we run "jrnl work a long day in the office"
|
||||
Then the output should contain "Entry added to work journal"
|
||||
Then we should see the message "Entry added to work journal"
|
||||
|
||||
Scenario: Write to specified journal with a timestamp
|
||||
Given we use the config "multiple.json"
|
||||
|
|
|
@ -61,6 +61,11 @@ def check_output_inline(context, text):
|
|||
out = context.stdout_capture.getvalue()
|
||||
assert text in out
|
||||
|
||||
@then('we should see the message "{text}"')
|
||||
def check_message(context, text):
|
||||
out = context.messages.getvalue()
|
||||
assert text in out
|
||||
|
||||
@then('the journal should contain "{text}"')
|
||||
@then('journal "{journal_name}" should contain "{text}"')
|
||||
def check_journal_content(context, text, journal_name="default"):
|
||||
|
@ -72,7 +77,6 @@ def journal_doesnt_exist(context, journal_name="default"):
|
|||
with open(jrnl.CONFIG_PATH) as config_file:
|
||||
config = json.load(config_file)
|
||||
journal_path = config['journals'][journal_name]
|
||||
print journal_path
|
||||
assert not os.path.exists(journal_path)
|
||||
|
||||
@then('the journal should have {number:d} entries')
|
||||
|
|
Loading…
Add table
Reference in a new issue