def test_can_parse_a_unary_array_from_single_step(): "It should extract a single ordinary step correctly into an array of steps" steps = Step.many_from_lines(I_HAVE_TASTY_BEVERAGES.splitlines()) assert_equals(len(steps), 1) assert isinstance(steps[0], Step) assert_equals(steps[0].sentence, string.split(I_HAVE_TASTY_BEVERAGES, "\n")[0])
def test_can_parse_a_unary_array_from_single_step(): "It should extract a single ordinary step correctly into an array of steps" steps = Step.many_from_lines([I_HAVE_TASTY_BEVERAGES]) assert_equals(len(steps), 1) assert isinstance(steps[0], Step) assert_equals(steps[0].sentence, string.split(I_HAVE_TASTY_BEVERAGES, '\n')[0])
def test_multiline_is_part_of_previous_step(): "It should correctly parse a multi-line string as part of the preceding step" lines = strings.get_stripped_lines(MULTI_LINE) steps = Step.many_from_lines(lines) print steps assert_equals(len(steps), 1) assert isinstance(steps[0], Step) assert_equals(steps[0].sentence, "I have a string like so:")
def test_cannot_start_with_multiline(): "It should raise an error when a step starts with a multiline string" lines = strings.get_stripped_lines(INVALID_MULTI_LINE) try: step = Step.many_from_lines(lines) except LettuceSyntaxError: return assert False, "LettuceSyntaxError not raised"
def test_can_parse_two_ordinary_steps(): "It should correctly extract two ordinary steps into an array." steps = Step.many_from_lines(I_DIE_HAPPY.splitlines() + I_LIKE_VEGETABLES.splitlines()) assert_equals(len(steps), 2) assert isinstance(steps[0], Step) assert isinstance(steps[1], Step) assert_equals(steps[0].sentence, I_DIE_HAPPY) assert_equals(steps[1].sentence, I_LIKE_VEGETABLES)
def test_can_parse_tabular_step_followed_by_regular_step(): "It should correctly extract two steps (one tabular, one regular) into an array." steps = Step.many_from_lines(I_HAVE_TASTY_BEVERAGES.splitlines() + I_LIKE_VEGETABLES.splitlines()) assert_equals(len(steps), 2) assert isinstance(steps[0], Step) assert isinstance(steps[1], Step) assert_equals(steps[0].sentence, string.split(I_HAVE_TASTY_BEVERAGES, "\n")[0]) assert_equals(steps[1].sentence, I_LIKE_VEGETABLES)
def test_multiline_is_part_of_previous_step(): "It should correctly parse a multi-line string as part of the preceding step" lines = strings.get_stripped_lines(MULTI_LINE) steps = Step.many_from_lines(lines) print steps assert_equals(len(steps), 1) assert isinstance(steps[0], Step) assert_equals(steps[0].sentence, 'I have a string like so:')
def test_can_parse_two_ordinary_steps(): "It should correctly extract two ordinary steps into an array." steps = Step.many_from_lines([I_DIE_HAPPY, I_LIKE_VEGETABLES]) assert_equals(len(steps), 2) assert isinstance(steps[0], Step) assert isinstance(steps[1], Step) assert_equals(steps[0].sentence, I_DIE_HAPPY) assert_equals(steps[1].sentence, I_LIKE_VEGETABLES)
def test_can_parse_tabular_step_followed_by_regular_step(): "It should correctly extract two steps (one tabular, one regular) into an array." steps = Step.many_from_lines(I_HAVE_TASTY_BEVERAGES.splitlines() + I_LIKE_VEGETABLES.splitlines()) assert_equals(len(steps), 2) assert isinstance(steps[0], Step) assert isinstance(steps[1], Step) assert_equals(steps[0].sentence, string.split(I_HAVE_TASTY_BEVERAGES, '\n')[0]) assert_equals(steps[1].sentence, I_LIKE_VEGETABLES)
def test_can_parse_background_and_ignore_tag(): "It should correctly parse and ignore tags between the background and first step." steps = Step.many_from_lines(BACKGROUND_WITH_TAGGED_SCENARIO.splitlines()) steps_without_tags = filter(lambda x: not x.sentence == "@wip", steps) assert_equals(len(steps), len(steps_without_tags))
def test_can_parse_a_unary_array_from_complicated_step(): "It should extract a single tabular step correctly into an array of steps" steps = Step.many_from_lines(I_LIKE_VEGETABLES.splitlines()) assert_equals(len(steps), 1) assert isinstance(steps[0], Step) assert_equals(steps[0].sentence, I_LIKE_VEGETABLES)
def test_can_parse_a_unary_array_from_complicated_step(): "It should extract a single tabular step correctly into an array of steps" steps = Step.many_from_lines([I_LIKE_VEGETABLES]) assert_equals(len(steps), 1) assert isinstance(steps[0], Step) assert_equals(steps[0].sentence, I_LIKE_VEGETABLES)
def test_can_parse_background_and_ignore_tag(): "It should correctly parse and ignore tags between the background and first step." steps = Step.many_from_lines(BACKGROUND_WITH_TAGGED_SCENARIO.splitlines()) steps_without_tags = [x for x in steps if not x.sentence == '@wip'] assert_equals(len(steps), len(steps_without_tags))