Last active
May 28, 2016 23:53
-
-
Save poundifdef/b3846403141ff3ae9b236e022dcac994 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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