示例#1
0
def test_syntax_error_for_scenarios_with_no_name():
    ("Trying to parse features with unnamed "
     "scenarios will cause a syntax error")
    with assert_raises(LettuceSyntaxError) as error:
        Feature.from_string(FEATURE20)

    assert error.exception.msg == \
        'Syntax error at: None\n' \
        '3:5 Scenario must have a name'
示例#2
0
def test_feature_max_length_on_scenario_outline_keys():
    """
    The max length of a feature considering when the table keys of the
    scenario oulines are longer than the remaining things
    """

    feature1 = Feature.from_string(FEATURE8)
    feature2 = Feature.from_string(FEATURE9)
    assert_equal(feature1.max_length, 68)
    assert_equal(feature2.max_length, 68)
示例#3
0
def test_syntax_error_malformed_feature():
    """Parsing a malformed feature causes a syntax error."""

    with assert_raises(AloeSyntaxError) as error:
        Feature.from_string("""
PARSE ERROR
""")

    # pylint:disable=line-too-long
    assert_equal(error.exception.msg, '\n'.join((
        "Syntax error at: None",
        "Parser errors:",
        "(2:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'PARSE ERROR'",
    )))
示例#4
0
def test_scenarios_parsed_by_feature_has_feature():
    "Scenarios parsed by features has feature"

    feature = Feature.from_string(FEATURE2)

    for scenario in feature.scenarios:
        assert_equal(scenario.feature, feature)
示例#5
0
def test_outline_steps():
    """Test steps that are part of an outline."""

    feature = Feature.from_string(FEATURE6)

    # Steps that are a part of an outline have a reference back to the outline
    for outline, steps in feature.scenarios[0].evaluated:
        for step in steps:
            assert_equal(step.outline, outline)

    feature = Feature.from_string(FEATURE1)

    # Steps that are not a part of an outline don't have the outline reference
    for outline, steps in feature.scenarios[0].evaluated:
        for step in steps:
            assert_equal(step, outline, None)
示例#6
0
def test_scenarios_with_special_characters():
    "Make sure that regex special characters in the scenario names are ignored"
    feature = Feature.from_string(FEATURE19)

    assert feature.scenarios[0].tags == ('runme1',)

    assert feature.scenarios[1].tags == ('runme2',)
示例#7
0
def test_feature_first_scenario_tags_extraction():
    ("A feature object should be able to find the tags "
     "belonging to the first scenario")
    feature = Feature.from_string(FEATURE23)

    assert feature.scenarios[0].tags == \
        ('onetag', 'another', '$%^&even-weird_chars')
示例#8
0
def test_feature_ru_from_string():
    """
    Language: RU -> Feature.from_string
    """

    feature = Feature.from_string(FEATURE, language='ru')

    assert_equal(
        feature.name,
        u'Деление чисел'
    )

    assert_equal(
        feature.description,
        u"Поскольку деление сложный процесс и люди часто допускают ошибки\n"
        u"Нужно дать им возможность делить на калькуляторе"
    )

    (scenario, ) = feature.scenarios

    assert_equal(
        scenario.name,
        u'Целочисленное деление'
    )

    assert_equal(
        scenario.steps[-1].hashes,
        (
            {u'делимое': '100', u'делитель': '2', u'частное': '50'},
            {u'делимое': '28', u'делитель': '7', u'частное': '4'},
            {u'делимое': '0', u'делитель': '5', u'частное': '0'},
        )
    )
示例#9
0
def test_feature_ptbr_from_string():
    """
    Language: PT-BR -> Feature.from_string
    """

    ptbr = Language('pt-br')
    feature = Feature.from_string(FEATURE, language=ptbr)

    assert_equal(
        feature.name,
        u'Pesquisar alunos com matrícula vencida'
    )

    assert_equal(
        feature.description,
        u"Como gerente financeiro\n"
        u"Eu quero pesquisar alunos com matrícula vencida\n"
        u"Para propor um financiamento"
    )

    (scenario, ) = feature.scenarios

    assert_equal(
        scenario.name,
        'Pesquisar por nome do curso'
    )

    assert_equal(
        scenario.steps[-1].hashes,
        [
            {'nome': u'João', u'valor devido': 'R$ 512,66'},
            {'nome': u'Maria', u'valor devido': 'R$ 998,41'},
            {'nome': u'Ana', u'valor devido': 'R$ 231,00'},
        ]
    )
示例#10
0
def test_scenario_outlines_within_feature():
    """
    Solving scenario outlines within a feature
    """

    feature = Feature.from_string(OUTLINED_FEATURE)
    scenario = feature.scenarios[0]
    solved = solved_steps(scenario)

    assert_equal(len(solved), 12)
    expected_sentences = [
        'Given I have entered 20 into the calculator',
        'And I have entered 30 into the calculator',
        'When I press add',
        'Then the result should be 50 on the screen',
        'Given I have entered 2 into the calculator',
        'And I have entered 5 into the calculator',
        'When I press add',
        'Then the result should be 7 on the screen',
        'Given I have entered 0 into the calculator',
        'And I have entered 40 into the calculator',
        'When I press add',
        'Then the result should be 40 on the screen',
    ]

    for step, expected in zip(solved, expected_sentences):
        assert_equal(type(step), Step)
        assert_equal(step.sentence, expected)
示例#11
0
def test_can_parse_feature_description():
    """
    A feature object should have a description
    """

    feature = Feature.from_string(FEATURE2)

    assert_equal(
        feature.description,
        "In order to avoid silly mistakes\n"
        "Cashiers must be able to calculate a fraction"
    )
    expected_scenario_names = ["Regular numbers"]
    got_scenario_names = [s.name for s in feature.scenarios]

    assert_equal(expected_scenario_names, got_scenario_names)
    assert_equal(len(feature.scenarios[0].steps), 4)

    step1, step2, step3, step4 = feature.scenarios[0].steps

    assert_equal(step1.sentence, 'Given I have entered 3 into the calculator')
    assert_equal(step2.sentence, 'And I have entered 2 into the calculator')
    assert_equal(step3.sentence, 'When I press divide')
    assert_equal(step4.sentence,
                 'Then the result should be 1.5 on the screen')
示例#12
0
def test_feature_fr_from_string2():
    """
    Language: FR -> Feature.from_string, alternate name
    """

    lang = Language("fr")

    feature = Feature.from_string(OUTLINED_FEATURE2, language=lang)

    assert_equal(feature.name, "Faire plusieur choses en même temps")

    assert_equal(
        feature.description,
        "De façon à automatiser les tests\n" "En tant que fainéant\n" "J'utilise les plans de scénario",
    )

    (scenario,) = feature.scenarios

    assert_equal(scenario.name, "Ajouter 2 nombres")

    assert_equal(
        scenario.outlines,
        [
            {"input_1": "20", "input_2": "30", "bouton": "add", "output": "50"},
            {"input_1": "2", "input_2": "5", "bouton": "add", "output": "7"},
            {"input_1": "0", "input_2": "40", "bouton": "add", "output": "40"},
        ],
    )
示例#13
0
def test_feature_max_length_on_scenario():
    """
    The max length of a feature considering when the scenario is longer than
    the remaining things
    """

    feature = Feature.from_string(FEATURE1)
    assert_equal(feature.max_length, 76)
示例#14
0
def test_feature_max_length_on_step_sentence():
    """
    The max length of a feature considering when the some of the step sentences
    is longer than the remaining things
    """

    feature = Feature.from_string(FEATURE4)
    assert_equal(feature.max_length, 55)
示例#15
0
def test_description_on_long_named_feature():
    "Can parse the description on long named features"
    feature = Feature.from_string(FEATURE3)
    assert_equal(
        feature.description,
        "In order to describe my features\n"
        "I want to add description on them",
    )
示例#16
0
def test_comments():
    """
    It should ignore lines that start with #, despite white spaces
    """

    feature = Feature.from_string(FEATURE10)

    assert_equal(feature.max_length, 55)
示例#17
0
def test_feature_max_length_on_feature_description():
    """
    The max length of a feature considering when one of the description lines
    of the feature is longer than the remaining things
    """

    feature = Feature.from_string(FEATURE2)
    assert_equal(feature.max_length, 47)
示例#18
0
def test_feature_max_length_on_scenario_outline():
    """
    The max length of a feature considering when the table of some of the
    scenario oulines is longer than the remaining things
    """

    feature = Feature.from_string(FEATURE6)
    assert_equal(feature.max_length, 79)
示例#19
0
def test_feature_max_length_on_feature_name():
    """
    The max length of a feature considering when the name of the feature
    is longer than the remaining things
    """

    feature = Feature.from_string(FEATURE3)
    assert_equal(feature.max_length, 78)
示例#20
0
def test_feature_max_length_on_step_with_table_keys():
    """
    The max length of a feature considering when the table keys of some of the
    steps are longer than the remaining things
    """

    feature = Feature.from_string(FEATURE7)
    assert_equal(feature.max_length, 74)
示例#21
0
def parse_scenario(string, language=None):
    """Parse a scenario, prefixing it with a feature header."""
    feature_str = u"""
    Функция: parse_scenario
    """
    feature_str += string
    feature = Feature.from_string(feature_str, language=language)

    return feature.scenarios[0]
示例#22
0
def test_description_on_big_sentenced_steps():
    "Can parse the description on long sentenced steps"
    feature = Feature.from_string(FEATURE4)
    assert_equal(
        feature.description,
        "As a clever guy\n"
        "I want to describe this Feature\n"
        "So that I can take care of my Scenario",
    )
示例#23
0
def test_single_scenario_single_scenario():
    "Features should have at least the first scenario parsed with tags"
    feature = Feature.from_string(FEATURE11)

    first_scenario = feature.scenarios[0]

    assert_equal(first_scenario.tags, (
        'many', 'other', 'basic', 'tags', 'here', ':)'
    ))
示例#24
0
def test_single_feature_single_tag():
    "All scenarios within a feature inherit the feature's tags"
    feature = Feature.from_string(FEATURE18)

    assert feature.scenarios[0].tags == ('runme1', 'feature_runme')

    assert feature.scenarios[1].tags == ('runme2', 'feature_runme')

    assert feature.scenarios[2].tags == ('runme3', 'feature_runme')
示例#25
0
def parse_steps(step):
    """Parse a step, prefixing it with a feature and a scenario header."""
    feature = """
    Feature: parse a step
    Scenario: parse a single step
    """

    feature += step

    return Feature.from_string(feature).scenarios[0].steps
示例#26
0
def test_scenario_has_name():
    """
    It should extract the name string from the scenario
    """

    feature = Feature.from_string(FEATURE1)

    assert isinstance(feature, Feature)

    assert feature.name == "Rent movies"
示例#27
0
def parse_scenario(string, language=None):
    """Parse a scenario, prefixing it with a feature header."""
    feature = """
Funcionalidade: parse_scenario
    """

    feature += string
    feature = Feature.from_string(feature, language=language)

    return feature.scenarios[0]
示例#28
0
def test_scenario_post_email():
    ("Having a scenario which the body has an email address; "
     "Then the following scenario should have no "
     "tags related to the email")

    feature = Feature.from_string(FEATURE21)
    scenario1, scenario2 = feature.scenarios

    assert scenario1.tags == ()
    assert scenario2.tags == ('tag',)
示例#29
0
def test_scenarios_with_extra_whitespace():
    "Make sure that extra leading whitespace is ignored"
    feature = Feature.from_string(FEATURE14)

    assert_equal(type(feature.scenarios), tuple)
    assert_equal(len(feature.scenarios), 1, "It should have 1 scenario")
    assert_equal(feature.name, "Extra whitespace feature")

    scenario = feature.scenarios[0]
    assert_equal(type(scenario), Scenario)
    assert_equal(scenario.name, "Extra whitespace scenario")
示例#30
0
def parse_scenario(scenario, tags=None):
    """Parse a scenario, adding a feature header and tags."""
    feature_str = """
    Feature: test scenario
    """

    if tags:
        feature_str += ' '.join('@%s' % tag for tag in tags)

    feature_str += scenario

    feature = Feature.from_string(feature_str)

    return feature.scenarios[0]
示例#31
0
def parse_scenario(scenario, tags=None):
    """Parse a scenario, adding a feature header and tags."""
    feature_str = """
    Feature: test scenario
    """

    if tags:
        feature_str += ' '.join('@%s' % tag for tag in tags)

    feature_str += scenario

    feature = Feature.from_string(feature_str)

    return feature.scenarios[0]
示例#32
0
def test_single_scenario_many_scenarios():
    "Untagged scenario following a tagged one should have no tags"

    feature = Feature.from_string(FEATURE13)

    first_scenario = feature.scenarios[0]
    assert first_scenario.tags == ['runme']

    second_scenario = feature.scenarios[1]
    assert second_scenario.tags == []

    third_scenario = feature.scenarios[2]
    assert third_scenario.tags == ['slow']

    last_scenario = feature.scenarios[3]
    assert last_scenario.tags == []
示例#33
0
def test_background_parsing_without_mmf():
    """Test background parsing without description."""
    feature = Feature.from_string(FEATURE17)
    assert feature.description == ""

    assert isinstance(feature.background, Background)
    assert feature.background.steps
    assert len(feature.background.steps) == 2

    step1, step2 = feature.background.steps
    assert step1.sentence == \
        'Given I have the following movies in my database:'
    assert step1.hashes == [
        {
            u'Available': u'6',
            u'Rating': u'4 stars',
            u'Name': u'Matrix Revolutions',
            u'New': u'no',
        },
        {
            u'Available': u'11',
            u'Rating': u'5 stars',
            u'Name': u'Iron Man 2',
            u'New': u'yes',
        },
    ]
    assert step1.table == [
        ['Name', 'Rating', 'New', 'Available'],
        ['Matrix Revolutions', '4 stars', 'no', '6'],
        ['Iron Man 2', '5 stars', 'yes', '11'],
    ]

    assert step2.sentence == \
        'And the following clients:'
    assert step2.hashes == [
        {
            u'Name': u'John Doe'
        },
        {
            u'Name': u'Foo Bar'
        },
    ]
    assert step2.table == [
        ['Name'],
        ['John Doe'],
        ['Foo Bar'],
    ]
示例#34
0
def test_background_parsing_with_mmf():
    """Test background parsing with description."""
    feature = Feature.from_string(FEATURE16)
    assert feature.description == \
        "As a rental store owner\n" \
        "I want to keep track of my clients\n" \
        "So that I can manage my business better"

    assert isinstance(feature.background, Background)
    assert feature.background.steps
    assert len(feature.background.steps) == 2

    step1, step2 = feature.background.steps
    assert step1.sentence == \
        'Given I have the following movies in my database:'
    assert step1.hashes == [
        {
            u'Available': u'6',
            u'Rating': u'4 stars',
            u'Name': u'Matrix Revolutions',
            u'New': u'no',
        },
        {
            u'Available': u'11',
            u'Rating': u'5 stars',
            u'Name': u'Iron Man 2',
            u'New': u'yes',
        },
    ]

    assert step2.sentence == \
        'And the following clients:'
    assert step2.hashes == [
        {
            u'Name': u'John Doe'
        },
        {
            u'Name': u'Foo Bar'
        },
    ]
示例#35
0
def test_can_parse_feature_description():
    """
    A feature object should have a description
    """

    feature = Feature.from_string(FEATURE2)

    assert_equal(
        feature.description, "In order to avoid silly mistakes\n"
        "Cashiers must be able to calculate a fraction")
    expected_scenario_names = ["Regular numbers"]
    got_scenario_names = [s.name for s in feature.scenarios]

    assert_equal(expected_scenario_names, got_scenario_names)
    assert_equal(len(feature.scenarios[0].steps), 4)

    step1, step2, step3, step4 = feature.scenarios[0].steps

    assert_equal(step1.sentence, 'Given I have entered 3 into the calculator')
    assert_equal(step2.sentence, 'And I have entered 2 into the calculator')
    assert_equal(step3.sentence, 'When I press divide')
    assert_equal(step4.sentence, 'Then the result should be 1.5 on the screen')
def test_feature_ru_from_string():
    """
    Language: RU -> Feature.from_string
    """

    feature = Feature.from_string(FEATURE, language="ru")

    assert feature.name == "Деление чисел"

    assert feature.description == (
        "Поскольку деление сложный процесс и люди часто допускают ошибки\n"
        "Нужно дать им возможность делить на калькуляторе"
    )

    (scenario,) = feature.scenarios

    assert scenario.name == "Целочисленное деление"

    assert scenario.steps[-1].hashes == (
        {"делимое": "100", "делитель": "2", "частное": "50"},
        {"делимое": "28", "делитель": "7", "частное": "4"},
        {"делимое": "0", "делитель": "5", "частное": "0"},
    )
示例#37
0
def test_feature_has_scenarios():
    """
    A feature object should have a list of scenarios
    """

    feature = Feature.from_string(FEATURE1)

    assert isinstance(feature.scenarios, tuple)
    assert len(feature.scenarios) == 3

    expected_names = [
        "Renting a featured movie",
        "Renting a non-featured movie",
        "Renting two movies allows client to take one more without charge",
    ]

    for scenario, expected_name in zip(feature.scenarios, expected_names):
        assert isinstance(scenario, Scenario)
        assert scenario.name == expected_name

    assert feature.scenarios[1].steps[0].keys == ("Name", "Rating", "New",
                                                  "Available")

    assert list(feature.scenarios[1].steps[0].hashes) == [
        {
            "Name": "A night at the museum 2",
            "Rating": "3 stars",
            "New": "yes",
            "Available": "9",
        },
        {
            "Name": "Matrix Revolutions",
            "Rating": "4 stars",
            "New": "no",
            "Available": "6",
        },
    ]
示例#38
0
def test_feature_has_scenarios():
    """
    A feature object should have a list of scenarios
    """

    feature = Feature.from_string(FEATURE1)

    assert isinstance(feature.scenarios, list)
    assert len(feature.scenarios) == 3

    expected_names = [
        "Renting a featured movie",
        "Renting a non-featured movie",
        "Renting two movies allows client to take one more without charge",
    ]

    for scenario, expected_name in zip(feature.scenarios, expected_names):
        assert isinstance(scenario, Scenario)
        assert scenario.name == expected_name

    assert feature.scenarios[1].steps[0].keys == \
        ('Name', 'Rating', 'New', 'Available')

    assert list(feature.scenarios[1].steps[0].hashes) == [
        {
            'Name': 'A night at the museum 2',
            'Rating': '3 stars',
            'New': 'yes',
            'Available': '9',
        },
        {
            'Name': 'Matrix Revolutions',
            'Rating': '4 stars',
            'New': 'no',
            'Available': '6',
        },
    ]
def test_feature_fr_from_string2():
    """
    Language: FR -> Feature.from_string, alternate name
    """

    feature = Feature.from_string(OUTLINED_FEATURE2, language="fr")

    assert feature.name == "Faire plusieur choses en même temps"

    assert feature.description == ("De façon à automatiser les tests\n"
                                   "En tant que fainéant\n"
                                   "J'utilise les plans de scénario")

    (scenario, ) = feature.scenarios

    assert scenario.name == "Ajouter 2 nombres"

    assert scenario.outlines == (
        {
            "input_1": "20",
            "input_2": "30",
            "bouton": "add",
            "output": "50"
        },
        {
            "input_1": "2",
            "input_2": "5",
            "bouton": "add",
            "output": "7"
        },
        {
            "input_1": "0",
            "input_2": "40",
            "bouton": "add",
            "output": "40"
        },
    )
示例#40
0
def test_feature_fr_from_string2():
    """
    Language: FR -> Feature.from_string, alternate name
    """

    feature = Feature.from_string(OUTLINED_FEATURE2, language='fr')

    assert_equal(
        feature.name,
        u'Faire plusieur choses en même temps'
    )

    assert_equal(
        feature.description,
        u"De façon à automatiser les tests\n"
        u"En tant que fainéant\n"
        u"J'utilise les plans de scénario"
    )

    (scenario, ) = feature.scenarios

    assert_equal(
        scenario.name,
        'Ajouter 2 nombres'
    )

    assert_equal(
        scenario.outlines,
        (
            {u'input_1': u'20', u'input_2': u'30',
             u'bouton': u'add', u'output': u'50'},
            {u'input_1': u'2', u'input_2': u'5',
             u'bouton': u'add', u'output': u'7'},
            {u'input_1': u'0', u'input_2': u'40',
             u'bouton': u'add', u'output': u'40'},
        )
    )
示例#41
0
def test_scenarios_parsing():
    "Tags are parsed correctly"
    feature = Feature.from_string(FEATURE15)
    scenarios_and_tags = [(s.name, s.tags) for s in feature.scenarios]

    assert scenarios_and_tags == [
        ("Bootstraping Redis role", ()),
        ("Restart scalarizr", ()),
        ("Rebundle server", ("rebundle", )),
        ("Use new role", ("rebundle", )),
        ("Restart scalarizr after bundling", ("rebundle", )),
        ("Bundling data", ()),
        ("Modifying data", ()),
        ("Reboot server", ()),
        ("Backuping data on Master", ()),
        ("Setup replication", ()),
        ("Restart scalarizr in slave", ()),
        ("Slave force termination", ()),
        ("Slave delete EBS", ("ec2", )),
        ("Setup replication for EBS test", ("ec2", )),
        ("Writing on Master, reading on Slave", ()),
        ("Slave -> Master promotion", ()),
        ("Restart farm", ("restart_farm", )),
    ]
示例#42
0
def test_scenarios_parsing():
    "Tags are parsed correctly"
    feature = Feature.from_string(FEATURE15)
    scenarios_and_tags = [(s.name, s.tags) for s in feature.scenarios]

    assert scenarios_and_tags == [
        ('Bootstraping Redis role', []),
        ('Restart scalarizr', []),
        ('Rebundle server', [u'rebundle']),
        ('Use new role', [u'rebundle']),
        ('Restart scalarizr after bundling', [u'rebundle']),
        ('Bundling data', []),
        ('Modifying data', []),
        ('Reboot server', []),
        ('Backuping data on Master', []),
        ('Setup replication', []),
        ('Restart scalarizr in slave', []),
        ('Slave force termination', []),
        ('Slave delete EBS', [u'ec2']),
        ('Setup replication for EBS test', [u'ec2']),
        ('Writing on Master, reading on Slave', []),
        ('Slave -> Master promotion', []),
        ('Restart farm', [u'restart_farm']),
    ]
示例#43
0
def test_feature_ru_from_string():
    """
    Language: RU -> Feature.from_string
    """

    lang = Language('ru')
    feature = Feature.from_string(FEATURE, language=lang)

    assert_equal(feature.name, u'Деление чисел')

    assert_equal(
        feature.description,
        u"Поскольку деление сложный процесс и люди часто допускают ошибки\n"
        u"Нужно дать им возможность делить на калькуляторе")

    (scenario, ) = feature.scenarios

    assert_equal(scenario.name, u'Целочисленное деление')

    assert_equal(scenario.steps[-1].hashes, [
        {
            u'делимое': '100',
            u'делитель': '2',
            u'частное': '50'
        },
        {
            u'делимое': '28',
            u'делитель': '7',
            u'частное': '4'
        },
        {
            u'делимое': '0',
            u'делитель': '5',
            u'частное': '0'
        },
    ])
示例#44
0
def test_feature_has_repr():
    """
    Feature implements __repr__ nicely
    """
    feature = Feature.from_string(FEATURE1)
    assert repr(feature) == '<Feature: "Rent movies">'
示例#45
0
def test_feature_first_scenario_tag_extraction():
    ("A feature object should be able to find the single tag "
     "belonging to the first scenario")
    feature = Feature.from_string(FEATURE22)

    assert feature.scenarios[0].tags == ['onetag']
def test_full_featured_feature():
    """
    Solving scenarios within a full-featured feature
    """

    feature = Feature.from_string(OUTLINED_FEATURE_WITH_MANY)
    scenario1, scenario2, scenario3, scenario4 = feature.scenarios

    assert scenario1.name == "Do something"
    assert scenario2.name == "Do something else"
    assert scenario3.name == "Worked!"
    assert scenario4.name == "Add two numbers wisely"

    solved = solved_steps(scenario1)

    assert len(solved) == 2
    expected_sentences = [
        "Given I have entered ok into the fail",
        "Given I have entered fail into the ok",
    ]
    for step, expected in zip(solved, expected_sentences):
        assert step.sentence == expected

    expected_evaluated = (
        (
            {
                "button": "add",
                "input_1": "20",
                "input_2": "30",
                "output": "50"
            },
            [
                "Given I have entered 20 into the calculator",
                "And I have entered 30 into the calculator",
                "When I press add",
                "Then the result should be 50 on the screen",
            ],
        ),
        (
            {
                "button": "add",
                "input_1": "2",
                "input_2": "5",
                "output": "7"
            },
            [
                "Given I have entered 2 into the calculator",
                "And I have entered 5 into the calculator",
                "When I press add",
                "Then the result should be 7 on the screen",
            ],
        ),
        (
            {
                "button": "add",
                "input_1": "0",
                "input_2": "40",
                "output": "40"
            },
            [
                "Given I have entered 0 into the calculator",
                "And I have entered 40 into the calculator",
                "When I press add",
                "Then the result should be 40 on the screen",
            ],
        ),
        (
            {
                "button": "add",
                "input_1": "5",
                "input_2": "7",
                "output": "12"
            },
            [
                "Given I have entered 5 into the calculator",
                "And I have entered 7 into the calculator",
                "When I press add",
                "Then the result should be 12 on the screen",
            ],
        ),
    )
    for ((got_examples, got_steps),
         (expected_examples, expected_steps)) in zip(scenario4.evaluated,
                                                     expected_evaluated):
        assert got_examples == expected_examples
        assert [x.sentence for x in got_steps] == expected_steps
示例#47
0
def test_full_featured_feature():
    """
    Solving scenarios within a full-featured feature
    """

    feature = Feature.from_string(OUTLINED_FEATURE_WITH_MANY)
    scenario1, scenario2, scenario3, scenario4 = feature.scenarios

    assert_equal(scenario1.name, 'Do something')
    assert_equal(scenario2.name, 'Do something else')
    assert_equal(scenario3.name, 'Worked!')
    assert_equal(scenario4.name, 'Add two numbers wisely')

    solved = solved_steps(scenario1)

    assert_equal(len(solved), 2)
    expected_sentences = [
        'Given I have entered ok into the fail',
        'Given I have entered fail into the ok',
    ]
    for step, expected in zip(solved, expected_sentences):
        assert_equal(step.sentence, expected)

    expected_evaluated = (({
        'button': 'add',
        'input_1': '20',
        'input_2': '30',
        'output': '50'
    }, [
        'Given I have entered 20 into the calculator',
        'And I have entered 30 into the calculator',
        'When I press add',
        'Then the result should be 50 on the screen',
    ]), ({
        'button': 'add',
        'input_1': '2',
        'input_2': '5',
        'output': '7'
    }, [
        'Given I have entered 2 into the calculator',
        'And I have entered 5 into the calculator',
        'When I press add',
        'Then the result should be 7 on the screen',
    ]), (
        {
            'button': 'add',
            'input_1': '0',
            'input_2': '40',
            'output': '40'
        },
        [
            'Given I have entered 0 into the calculator',
            'And I have entered 40 into the calculator',
            'When I press add',
            'Then the result should be 40 on the screen',
        ],
    ), (
        {
            'button': 'add',
            'input_1': '5',
            'input_2': '7',
            'output': '12'
        },
        [
            'Given I have entered 5 into the calculator',
            'And I have entered 7 into the calculator',
            'When I press add',
            'Then the result should be 12 on the screen',
        ],
    ))
    for ((got_examples, got_steps), (expected_examples, expected_steps)) \
            in zip(scenario4.evaluated, expected_evaluated):
        assert_equal(got_examples, expected_examples)
        assert_equal([x.sentence for x in got_steps], expected_steps)
示例#48
0
def test_description_on_big_sentenced_steps():
    "Can parse the description on long sentenced steps"
    feature = Feature.from_string(FEATURE4)
    assert feature.description == ("As a clever guy\n"
                                   "I want to describe this Feature\n"
                                   "So that I can take care of my Scenario")
示例#49
0
def test_description_on_long_named_feature():
    "Can parse the description on long named features"
    feature = Feature.from_string(FEATURE3)
    assert feature.description == ("In order to describe my features\n"
                                   "I want to add description on them")