| 1 |
@issue |
| 2 |
Feature: Issue #66: context.text and context.table are not cleared |
| 3 |
|
| 4 |
I noticed that context.table and context.text survive after the step is finished. |
| 5 |
|
| 6 |
|
| 7 |
Background: Test Setup |
| 8 |
Given a new working directory |
| 9 |
And a file named "features/steps/steps.py" with: |
| 10 |
""" |
| 11 |
from behave import given, when, then |
| 12 |
from hamcrest import assert_that, equal_to, is_not, is_, none |
| 13 |
import six |
| 14 |
|
| 15 |
@given(u'a step with multiline text') |
| 16 |
def step(context): |
| 17 |
assert context.text is not None |
| 18 |
assert context.text, "Ensure non-empty" |
| 19 |
assert isinstance(context.text, six.string_types) |
| 20 |
|
| 21 |
@given(u'a step with a table') |
| 22 |
def step(context): |
| 23 |
assert context.table is not None |
| 24 |
|
| 25 |
@when(u'I check the "context.{name}" attribute') |
| 26 |
def step(context, name): |
| 27 |
context.name = name |
| 28 |
context.value = getattr(context, name, None) |
| 29 |
|
| 30 |
@then(u'its value is None') |
| 31 |
def step(context): |
| 32 |
assert_that(context.value, is_(none())) |
| 33 |
|
| 34 |
@then(u'its value is "{value}"') |
| 35 |
def step(context, value): |
| 36 |
assert_that(context.value, equal_to(value)) |
| 37 |
|
| 38 |
@then(u'its value is not "{value}"') |
| 39 |
def step(context, value): |
| 40 |
assert_that(value, is_not(equal_to(context.value))) |
| 41 |
""" |
| 42 |
|
| 43 |
Scenario: Ensure multiline text data is cleared for next step |
| 44 |
Given a file named "features/issue66_case1.feature" with: |
| 45 |
""" |
| 46 |
Feature: |
| 47 |
Scenario: |
| 48 |
Given a step with multiline text: |
| 49 |
''' |
| 50 |
Alice, Bob and Charly |
| 51 |
''' |
| 52 |
When I check the "context.text" attribute |
| 53 |
Then its value is not "Alice, Bob and Charly" |
| 54 |
But its value is None |
| 55 |
""" |
| 56 |
When I run "behave -f plain features/issue66_case1.feature" |
| 57 |
Then it should pass with: |
| 58 |
""" |
| 59 |
1 scenario passed, 0 failed, 0 skipped |
| 60 |
4 steps passed, 0 failed, 0 skipped, 0 undefined |
| 61 |
""" |
| 62 |
|
| 63 |
Scenario: Ensure table data is cleared for next step |
| 64 |
Given a file named "features/issue66_case2.feature" with: |
| 65 |
""" |
| 66 |
Feature: |
| 67 |
Scenario: |
| 68 |
Given a step with a table: |
| 69 |
| name | gender | |
| 70 |
| Alice | female | |
| 71 |
| Bob | male | |
| 72 |
When I check the "context.table" attribute |
| 73 |
Then its value is None |
| 74 |
""" |
| 75 |
When I run "behave -f plain features/issue66_case2.feature" |
| 76 |
Then it should pass with: |
| 77 |
""" |
| 78 |
1 scenario passed, 0 failed, 0 skipped |
| 79 |
3 steps passed, 0 failed, 0 skipped, 0 undefined |
| 80 |
""" |