Beispiel #1
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.splitlines())
    assert_equals(len(steps), 1)
    assert isinstance(steps[0], Step)
    assert_equals(steps[0].sentence, string.split(I_HAVE_TASTY_BEVERAGES, "\n")[0])
Beispiel #2
0
def test_step_has_repr():
    "Step implements __repr__ nicely"
    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)
    assert_equals(
        repr(step),
        '<Step: "' + string.split(I_HAVE_TASTY_BEVERAGES, '\n')[0] + '">'
    )
Beispiel #3
0
def test_multiple_subordinate_steps_are_run():
    "When a step definition calls two subordinate step definitions (that do not fail), both should run."

    @step("I run two subordinate steps")
    def two_subordinate_steps(step):
        step.behave_as(
            """
            When I run the first sub-step
            And I run the second sub-step
        """
        )

    global first_ran
    global second_ran
    first_ran = False
    second_ran = False

    @step("I run the first sub-step$")
    def increment(step):
        global first_ran
        first_ran = True

    @step("I run the second sub-step")
    def increment_twice(step):
        global second_ran
        second_ran = True

    runnable_step = Step.from_string("Given I run two subordinate steps")
    runnable_step.run(True)
    assert_equals((first_ran, second_ran), (True, True))

    del first_ran
    del second_ran
Beispiel #4
0
def test_step_has_repr():
    "Step implements __repr__ nicely"
    step = Step.from_string(STEP1)
    assert_equals(
        repr(step),
        '<Step: "I have the following beverages in my freezer:">'
    )
def test_handy_attribute_for_first_occurrence_of_hashes():
    'Step.hashes objects should have a ".first" attribute that gives the first row (dict) of the "hashes" list'

    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)
    assert_equals(
        step.hashes.first,
        {'Name': 'Skol', 'Type': 'Beer', 'Price': '3.80'}
    )
Beispiel #6
0
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_handy_attribute_for_last_occurrence_of_hashes():
    'Step.hashes objects should have a ".last" attribute that gives the last row (dict) of the "hashes" list'

    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)
    assert_equals(
        step.hashes.last,
        {'Name': 'Nestea', 'Type': 'Ice-tea', 'Price': '2.10'}
    )
Beispiel #8
0
def test_multiline_is_parsed():
    step = Step.from_string(MULTI_LINE)
    assert_equals(step.sentence, 'I have a string like so:')
    assert_equals(step.multiline, u"""This is line one
and this is line two
and this is line three
and this is line four,
with spaces at the beginning""")
Beispiel #9
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:")
Beispiel #10
0
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"
Beispiel #11
0
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)
Beispiel #12
0
def test_can_get_sentence_from_string():
    "It should extract the sentence string from the whole step"

    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)

    assert isinstance(step, Step)

    assert_equals(step.sentence, string.split(I_HAVE_TASTY_BEVERAGES, "\n")[0])
Beispiel #13
0
def test_failing_behave_as_step_doesnt_pass():
    "When a step definition calls another (failing) step definition with behave_as, that step should not be marked as success."
    runnable_step = Step.from_string('Given I have a step which calls the "other step fails" step with behave_as')
    try:
        runnable_step.run(True)
    except:
        pass

    assert_false(runnable_step.passed)
def test_step_should_parse_one_tag():
    u"step should parse one tag"

    step = Step.from_string('''
    @headless
    Given I need no javascript
    ''')
    assert_equals(step.sentence, 'Given I need no javascript')
    assert_equals(step.tags, ['headless'])
Beispiel #15
0
def test_can_parse_tables():
    "It should have a list of data from a given step, if it has a table"

    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)

    assert isinstance(step.hashes, list)
    assert_equals(len(step.hashes), 2)
    assert_equals(step.hashes[0], {"Name": "Skol", "Type": "Beer", "Price": "3.80"})
    assert_equals(step.hashes[1], {"Name": "Nestea", "Type": "Ice-tea", "Price": "2.10"})
Beispiel #16
0
def test_failing_behave_as_step_fails():
    "When a step definition calls another (failing) step definition with behave_as, that step should be marked a failure."
    runnable_step = Step.from_string('Given I have a step which calls the "other step fails" step with behave_as')
    try:
        runnable_step.run(True)
    except:
        pass

    assert runnable_step.failed
Beispiel #17
0
def test_multiline_with_whitespace():
    step = Step.from_string(MULTI_LINE_WHITESPACE)
    assert_equals(step.sentence, 'I have a string like so:')
    assert_equals(step.multiline, u"""This is line one
and this is line two
and this is line three
  and this is line four,

  with spaces at the beginning
and spaces at the end   """)
Beispiel #18
0
def test_can_get_sentence_from_string():
    "It should extract the sentence string from the whole step"

    step = Step.from_string(STEP1)

    assert isinstance(step, Step)

    assert_equals(
        step.sentence,
        "I have the following beverages in my freezer:"
    )
Beispiel #19
0
def test_multiline_with_whitespace():
    step = Step.from_string(MULTI_LINE_WHITESPACE)
    assert_equals(step.sentence, 'I have a string like so:')
    assert_equals(
        step.multiline, u"""This is line one
and this is line two
and this is line three
  and this is line four,

  with spaces at the beginning
and spaces at the end   """)
def test_step_with_one_tag():
    "Lettuce should support a tag in a step"
    step = Step.from_string(MULTI_LINE_WHITESPACE)
    assert_equals(step.sentence, 'I have a string like so:')
    assert_equals(step.multiline, u"""This is line one
and this is line two
and this is line three
  and this is line four,

  with spaces at the beginning
and spaces at the end   """)
def test_step_should_parse_many_tags():
    u"step should parse many tags"

    step = Step.from_string('''
    @nice, @good,@bad,  @evil, @regex
    Given my email is "*****@*****.**"
    ''')

    assert_equals(
        step.sentence,
        'Given my email is "*****@*****.**"'
    )
    assert_equals(step.tags, ['nice', 'good', 'bad', 'evil', 'regex'])
Beispiel #22
0
def test_hashes__last_attr_raises_assertion_error_if_empty():
    'Step().hashes.last should raise a assertion error if the list is empty'

    step = Step.from_string(I_DIE_HAPPY)

    try:
        step.hashes.last
        failed = False
    except AssertionError, e:
        failed = True
        assert_equals(
            unicode(e),
            'The step "%s" have no table defined, so that you can\'t use step.hashes.last' % I_DIE_HAPPY
        )
Beispiel #23
0
def test_hashes__last_attr_raises_assertion_error_if_empty():
    'Step().hashes.last should raise a assertion error if the list is empty'

    step = Step.from_string(I_DIE_HAPPY)

    try:
        step.hashes.last
        failed = False
    except AssertionError, e:
        failed = True
        assert_equals(
            unicode(e),
            'The step "%s" have no table defined, so that you can\'t use step.hashes.last'
            % I_DIE_HAPPY)
Beispiel #24
0
def test_handy_function_for_table_members_fail_giving_assertionerror():
    'Step.hashes.values_under raises AssertionError if the key does not exist'

    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)
    try:
        step.hashes.values_under('Foobar')
        failed = False
    except AssertionError, e:
        failed = True
        assert_equals(
            unicode(e),
            'The step "I have the following tasty beverages in my freezer:" ' \
            'have no table column with the key "Foobar". ' \
            'Could you check your step definition for that ? ' \
            'Maybe there is a typo :)'
        )
Beispiel #25
0
def test_handy_function_for_table_members_fail_giving_assertionerror():
    'Step.hashes.values_under raises AssertionError if the key does not exist'

    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)
    try:
        step.hashes.values_under('Foobar')
        failed = False
    except AssertionError, e:
        failed = True
        assert_equals(
            unicode(e),
            'The step "I have the following tasty beverages in my freezer:" ' \
            'have no table column with the key "Foobar". ' \
            'Could you check your step definition for that ? ' \
            'Maybe there is a typo :)'
        )
Beispiel #26
0
def test_step_runs_subordinate_step_with_when():
    global simple_thing_ran
    simple_thing_ran = False
    @step('I do something simple')
    def simple_thing(step):
        global simple_thing_ran
        simple_thing_ran = True

    @step('I do many complex things')
    def complex_things(step):
        step.when('I do something simple')

    runnable_step = Step.from_string('When I do many complex things')
    runnable_step.run(True)
    assert(simple_thing_ran)

    del simple_thing_ran
Beispiel #27
0
def test_can_parse_tables():
    "It should have a list of data from a given step, if it has a table"

    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)

    assert isinstance(step.hashes, list)
    assert_equals(len(step.hashes), 2)
    assert_equals(step.hashes[0], {
        'Name': 'Skol',
        'Type': 'Beer',
        'Price': '3.80'
    })
    assert_equals(step.hashes[1], {
        'Name': 'Nestea',
        'Type': 'Ice-tea',
        'Price': '2.10'
    })
Beispiel #28
0
def test_step_runs_subordinate_step_with_when():
    global simple_thing_ran
    simple_thing_ran = False
    @step('I do something simple')
    def simple_thing(step):
        global simple_thing_ran
        simple_thing_ran = True

    @step('I do many complex things')
    def complex_things(step):
        step.when('I do something simple')

    runnable_step = Step.from_string('When I do many complex things')
    runnable_step.run(True)
    assert(simple_thing_ran)

    del simple_thing_ran
Beispiel #29
0
def test_step_runs_subordinate_step_with_then():
    global simple_thing_ran
    simple_thing_ran = False

    @step("I do something simple")
    def simple_thing(step):
        global simple_thing_ran
        simple_thing_ran = True

    @step("I do many complex things")
    def complex_things(step):
        step.then("I do something simple")

    runnable_step = Step.from_string("Then I do many complex things")
    runnable_step.run(True)
    assert simple_thing_ran

    del simple_thing_ran
Beispiel #30
0
def test_can_parse_tables():
    "It should have a list of data from a given step, if it has a table"

    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)

    assert isinstance(step.hashes, list)
    assert_equals(len(step.hashes), 2)
    assert_equals(
        step.hashes[0],
        {
            'Name': 'Skol',
            'Type': 'Beer',
            'Price': '3.80'
        }
    )
    assert_equals(
        step.hashes[1],
        {
            'Name': 'Nestea',
            'Type': 'Ice-tea',
            'Price': '2.10'
        }
    )
Beispiel #31
0
def test_can_parse_tables_to_column_dicts():
    "It should have a column dict of data from a given step, if it has a table"

    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)

    assert isinstance(step.columns_as_dict, list)
    assert_equals(len(step.columns_as_dict), 2)
    assert_equals(
        step.columns_as_dict[0],
        {
            'Name': 'Type',
            'Skol': 'Beer',
            'Nestea': 'Ice-tea'
        }
    )
    assert_equals(
        step.columns_as_dict[1],
        {
            'Name': 'Price',
            'Skol': '3.80',
            'Nestea': '2.10'
        }
    )
Beispiel #32
0
def test_undefined_behave_as_step_fails():
    "When a step definition calls an undefined step definition with behave_as, that step should be marked a failure."
    runnable_step = Step.from_string('Given I have a step which calls the "undefined step" step with behave_as')
    assert_raises(AssertionError, runnable_step.run, True)
    assert runnable_step.failed
Beispiel #33
0
def test_undefined_behave_as_step_doesnt_pass():
    "When a step definition calls an undefined step definition with behave_as, that step should not be marked as success."
    runnable_step = Step.from_string('Given I have a step which calls the "undefined step" step with behave_as')
    assert_raises(AssertionError, runnable_step.run, True)
    assert_false(runnable_step.passed)
Beispiel #34
0
def test_undefined_behave_as_step_doesnt_pass():
    'When a step definition calls an undefined step definition with behave_as, that step should not be marked as success.'
    runnable_step = Step.from_string('Given I have a step which calls the "undefined step" step with behave_as')
    assert_raises(AssertionError, runnable_step.run, True)
    assert_false(runnable_step.passed)
Beispiel #35
0
def test_undefined_behave_as_step_fails():
    'When a step definition calls an undefined step definition with behave_as, that step should be marked a failure.'
    runnable_step = Step.from_string('Given I have a step which calls the "undefined step" step with behave_as')
    assert_raises(AssertionError, runnable_step.run, True)
    assert runnable_step.failed
Beispiel #36
0
def test_successful_behave_as_step_doesnt_fail():
    "When a step definition calls another (successful) step definition with behave_as, that step should not be marked a failure."
    runnable_step = Step.from_string('Given I have a step which calls the "define a step" step with behave_as')
    runnable_step.run(True)
    assert_false(runnable_step.failed)
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))
Beispiel #38
0
def test_successful_behave_as_step_doesnt_fail():
    'When a step definition calls another (successful) step definition with behave_as, that step should not be marked a failure.'
    runnable_step = Step.from_string('Given I have a step which calls the "define a step" step with behave_as')
    runnable_step.run(True)
    assert_false(runnable_step.failed)
Beispiel #39
0
def test_successful_behave_as_step_passes():
    'When a step definition calls another (successful) step definition with behave_as, that step should be a success.'
    runnable_step = Step.from_string('Given I have a step which calls the "define a step" step with behave_as')
    runnable_step.run(True)
    assert runnable_step.passed
Beispiel #40
0
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)
Beispiel #41
0
def test_handy_function_for_table_members():
    'Step.hashes.values_under should be a method that gives a list of members'

    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)
    assert_equals(step.hashes.values_under('Name'), ['Skol', 'Nestea'])
Beispiel #42
0
def test_failing_behave_as_step_raises_assertion():
    "When a step definition calls another (failing) step definition with behave_as, that step should be marked a failure."
    runnable_step = Step.from_string('Given I have a step which calls the "other step fails" step with behave_as')
    assert_raises(AssertionError, runnable_step.run, True)
Beispiel #43
0
def test_can_parse_keys_from_table():
    "It should take the keys from the step, if it has a table"

    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)
    assert_equals(step.keys, ('Name', 'Type', 'Price'))
Beispiel #44
0
def test_failing_behave_as_step_raises_assertion():
    'When a step definition calls another (failing) step definition with behave_as, that step should be marked a failure.'
    runnable_step = Step.from_string(
        'Given I have a step which calls the "other step fails" step with behave_as'
    )
    assert_raises(AssertionError, runnable_step.run, True)
Beispiel #45
0
def test_step_has_repr():
    "Step implements __repr__ nicely"
    step = Step.from_string(I_HAVE_TASTY_BEVERAGES)
    assert_equals(
        repr(step),
        '<Step: "' + string.split(I_HAVE_TASTY_BEVERAGES, '\n')[0] + '">')