Skip to content

Commit 5044cf7

Browse files
committed
add feature file for basic CLI behavior
Before I implement behavior with expected input, I want to have graceful behavior with wrong input. Also remove the existing check for the hello world behavior
1 parent 18916d2 commit 5044cf7

4 files changed

Lines changed: 74 additions & 27 deletions

File tree

behave/fix_cli.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Feature: Fix CLI behavior
2+
3+
Scenario: Show usage when called without arguments
4+
When we call Fix without arguments
5+
Then it prints usage information
6+
And it prints a list of available commands
7+
And terminates with exit code 1
8+
9+
Scenario: Show usage when called with help option
10+
When we call Fix with argument list "--help"
11+
Then it prints usage information
12+
And it prints a list of available commands
13+
And terminates with exit code 0
14+
15+
16+
Scenario Outline: Show error when called with an unknown argument
17+
When we call Fix with argument list "<args>"
18+
Then it prints "fix: '<arg1>' is not a fix command. See 'fix --help'."
19+
And terminates with exit code 1
20+
21+
Examples:
22+
| args | arg1 |
23+
| foo | foo |
24+
| bar baz | bar |

behave/hello.feature

Lines changed: 0 additions & 6 deletions
This file was deleted.

behave/steps/fix_cli.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from behave import given, when, then
2+
import pexpect
3+
4+
fix_executable = '../cmake-build-debug/bin/fix'
5+
6+
7+
@given(u'nothing')
8+
def nothing(context):
9+
pass
10+
11+
12+
def _start_fix_with_args(context, args):
13+
context.fix = pexpect.spawn(fix_executable, args=args)
14+
15+
16+
@when(u'we call Fix with argument list "{args}"')
17+
def start_fix(context, args):
18+
_start_fix_with_args(context, args.strip().split(" "))
19+
20+
21+
@when(u'we call Fix without arguments')
22+
def start_fix(context):
23+
_start_fix_with_args(context, [])
24+
25+
26+
@then(u'it prints "{output}"')
27+
def check_output(context, output):
28+
context.fix.expect_exact(output)
29+
30+
31+
@then(u'it prints usage information')
32+
def check_usage(context):
33+
usage = "usage: fix [--help] <command> [<args>]"
34+
check_output(usage)
35+
36+
37+
@then(u'it prints a list of available commands')
38+
def check_commands(context):
39+
command_list = """Available commands:
40+
create Create a new issue
41+
setstatus Set the status of an issue
42+
list List all existing issues
43+
show Show a specific issue
44+
"""
45+
check_output(command_list)
46+
47+
48+
@then(u'terminates with exit code {ec:d}')
49+
def check_output(context, ec):
50+
assert (context.fix.wait() == ec)

behave/steps/hello.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)