diff --git a/features/core.feature b/features/core.feature index 7e495ef9..d5a6fa7f 100644 --- a/features/core.feature +++ b/features/core.feature @@ -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 "🐘" diff --git a/features/environment.py b/features/environment.py index 59763616..bebc2150 100644 --- a/features/environment.py +++ b/features/environment.py @@ -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") diff --git a/features/multiple_journals.feature b/features/multiple_journals.feature index fb026d2e..0510209b 100644 --- a/features/multiple_journals.feature +++ b/features/multiple_journals.feature @@ -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" diff --git a/features/steps/core.py b/features/steps/core.py index 36369edc..bab0ee96 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -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')