Debian Codegraph @

features/steps/behave_undefined_steps.py

raw
1 # -*- coding: UTF-8 -*-
2 """
3 Provides step definitions for behave based on behave4cmd.
4
5 REQUIRES:
6 * behave4cmd.steplib.output steps (command output from behave).
7 """
8
9 from __future__ import absolute_import
10 from behave import then
11 from behave.runner_util import make_undefined_step_snippet
12
13
14 # -----------------------------------------------------------------------------
15 # UTILITY FUNCTIONS:
16 # -----------------------------------------------------------------------------
17 def text_indent(text, indent_size=0):
18 prefix = " " * indent_size
19 return prefix.join(text.splitlines(True))
20
21
22 # -----------------------------------------------------------------------------
23 # STEPS FOR: Undefined step definitions
24 # -----------------------------------------------------------------------------
25 @then(u'an undefined-step snippets section exists')
26 def step_undefined_step_snippets_section_exists(context):
27 """
28 Checks if an undefined-step snippet section is in behave command output.
29 """
30 context.execute_steps(u'''
31 Then the command output should contain:
32 """
33 You can implement step definitions for undefined steps with these snippets:
34 """
35 ''')
36
37 @then(u'an undefined-step snippet should exist for "{step}"')
38 def step_undefined_step_snippet_should_exist_for(context, step):
39 """
40 Checks if an undefined-step snippet is provided for a step
41 in behave command output (last command).
42
43 EXAMPLE:
44 Then an undefined-step snippet should exist for "Given an undefined step"
45 """
46 undefined_step_snippet = make_undefined_step_snippet(step)
47 context.execute_steps(u'''\
48 Then the command output should contain:
49 """
50 {undefined_step_snippet}
51 """
52 '''.format(undefined_step_snippet=text_indent(undefined_step_snippet, 4)))
53
54
55 @then(u'an undefined-step snippet should not exist for "{step}"')
56 def step_undefined_step_snippet_should_not_exist_for(context, step):
57 """
58 Checks if an undefined-step snippet is provided for a step
59 in behave command output (last command).
60 """
61 undefined_step_snippet = make_undefined_step_snippet(step)
62 context.execute_steps(u'''\
63 Then the command output should not contain:
64 """
65 {undefined_step_snippet}
66 """
67 '''.format(undefined_step_snippet=text_indent(undefined_step_snippet, 4)))
68
69
70 @then(u'undefined-step snippets should exist for')
71 def step_undefined_step_snippets_should_exist_for_table(context):
72 """
73 Checks if undefined-step snippets are provided.
74
75 EXAMPLE:
76 Then undefined-step snippets should exist for:
77 | Step |
78 | When an undefined step is used |
79 | Then another undefined step is used |
80 """
81 assert context.table, "REQUIRES: table"
82 for row in context.table.rows:
83 step = row["Step"]
84 step_undefined_step_snippet_should_exist_for(context, step)
85
86
87 @then(u'undefined-step snippets should not exist for')
88 def step_undefined_step_snippets_should_not_exist_for_table(context):
89 """
90 Checks if undefined-step snippets are not provided.
91
92 EXAMPLE:
93 Then undefined-step snippets should not exist for:
94 | Step |
95 | When an known step is used |
96 | Then another known step is used |
97 """
98 assert context.table, "REQUIRES: table"
99 for row in context.table.rows:
100 step = row["Step"]
101 step_undefined_step_snippet_should_not_exist_for(context, step)