Skip to content

Instantly share code, notes, and snippets.

@poundifdef
Last active May 28, 2016 23:53
Show Gist options
  • Save poundifdef/b3846403141ff3ae9b236e022dcac994 to your computer and use it in GitHub Desktop.
Save poundifdef/b3846403141ff3ae9b236e022dcac994 to your computer and use it in GitHub Desktop.
Given I have a string "hello world"
When I split it based on the " " character
Then I expect two tokens
And I expect these tokens to be present:
| token |
| hello |
| world |
class TestStringMethods(unittest.TestCase):
def test_split(self):
# Precondition
s = 'hello world'
# Test Case
tokens = s.split()
# Assertion
self.assertEqual(tokens, ['hello', 'world'])
from behave import *
@given(u'I have a string \'{s}\'')
def step_impl(context, s):
context.s = s
@when(u'I split it based on the \'{separator}\' character')
def step_impl(context, separator):
context.tokens = context.s.split(' ')
@then(u'I expect {num} tokens')
def step_impl(context, num):
assert len(context.tokens) == int(num)
@then(u'I expect these tokens to be present')
def step_impl(context):
for i, row in enumerate(context.table):
assert context.tokens[i] == row['token']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment