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_equals(feature1.max_length, 68) assert_equals(feature2.max_length, 68)
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_equals(feature1.max_length, 68) assert_equals(feature2.max_length, 68)
def test_feature_has_scenarios(): "A feature object should have a list of scenarios" feature = Feature.from_string(FEATURE1) assert_equals(type(feature.scenarios), list) assert_equals(len(feature.scenarios), 3, "It should have 3 scenarios") expected_scenario_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_scenario_names): assert_equals(type(scenario), Scenario) assert_equals(scenario.name, expected_name) assert_equals(feature.scenarios[1].steps[0].keys, ("Name", "Rating", "New", "Available")) assert_equals( 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_description_on_big_sentenced_steps(): "Can parse the description on long sentenced steps" feature = Feature.from_string(FEATURE4) assert_equals( feature.description, "As a clever guy\n" "I want to describe this Feature\n" "So that I can take care of my Scenario", )
def test_feature_has_scenarios(): "A feature object should have a list of scenarios" feature = Feature.from_string(FEATURE1) assert_equals(type(feature.scenarios), list) assert_equals(len(feature.scenarios), 3, "It should have 3 scenarios") expected_scenario_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_scenario_names): assert_equals(type(scenario), Scenario) assert_equals(scenario.name, expected_name) assert_equals(feature.scenarios[1].steps[0].keys, ('Name', 'Rating', 'New', 'Available')) assert_equals( 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_after_each_step_is_executed_before_each_step(): "terrain.before.each_step and terrain.after.each_step decorators" world.step_states = [] @before.each_step def set_state_to_before(step): world.step_states.append('before') expected = 'Given I append "during" to states' if step.sentence != expected: raise TypeError('%r != %r' % (step.sentence, expected)) @step('append "during" to states') def append_during_to_step_states(step): world.step_states.append("during") @after.each_step def set_state_to_after(step): world.step_states.append('after') expected = 'Given I append "during" to states' if step.sentence != expected: raise TypeError('%r != %r' % (step.sentence, expected)) feature = Feature.from_string(FEATURE1) feature.run() assert_equals(world.step_states, ['before', 'during', 'after'])
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 that(feature.scenarios[0].tags).deep_equals([ 'onetag'])
def test_scenario_outlines_within_feature(): "Solving scenario outlines within a feature" feature = Feature.from_string(OUTLINED_FEATURE) scenario = feature.scenarios[0] assert_equals(len(scenario.solved_steps), 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_sentence in zip(scenario.solved_steps, expected_sentences): assert_equals(type(step), Step) assert_equals(step.sentence, expected_sentence)
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 that(feature.scenarios[0].tags).deep_equals([ 'onetag', 'another', '$%^&even-weird_chars'])
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_equals(scenario.feature, feature)
def test_feature_ptbr_from_string(): 'Language: RU -> Feature.from_string' ru = Language('ru') feature = Feature.from_string(FEATURE, language=ru) assert_equals( feature.name, u'Деление чисел' ) assert_equals( feature.description, u"Поскольку деление сложный процесс и люди часто допускают ошибки\n" u"Нужно дать им возможность делить на калькуляторе" ) (scenario, ) = feature.scenarios assert_equals( scenario.name, u'Целочисленное деление' ) assert_equals( scenario.steps[-1].hashes, [ {u'делимое': '100', u'делитель': '2', u'частное': '50'}, {u'делимое': '28', u'делитель': '7', u'частное': '4'}, {u'делимое': '0', u'делитель': '5', u'частное': '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_equals( feature.name, u'Pesquisar alunos com matrícula vencida' ) assert_equals( 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_equals( scenario.name, 'Pesquisar por nome do curso' ) assert_equals( 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'}, ] )
def test_feature_ptbr_from_string(): 'Language: PT-BR -> Feature.from_string' ptbr = Language('pt-br') feature = Feature.from_string(FEATURE, language=ptbr) assert_equals(feature.name, u'Pesquisar alunos com matrícula vencida') assert_equals( 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_equals(scenario.name, 'Pesquisar por nome do curso') assert_equals(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' }, ])
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_equals(scenario.feature, feature)
def test_background_parsing_without_mmf(): feature = Feature.from_string(FEATURE17) expect(feature.description).to.be.empty expect(feature).to.have.property('background').being.a(Background) expect(feature.background).to.have.property('steps') expect(feature.background.steps).to.have.length_of(2) step1, step2 = feature.background.steps step1.sentence.should.equal( 'Given I have the following movies in my database:') step1.hashes.should.equal(HashList(step1, [ { 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', }, ])) step2.sentence.should.equal( 'And the following clients:') step2.hashes.should.equal(HashList(step2, [ {u'Name': u'John Doe'}, {u'Name': u'Foo Bar'}, ]))
def test_after_each_step_is_executed_before_each_step(): "terrain.before.each_step and terrain.after.each_step decorators" world.step_states = [] @before.each_step def set_state_to_before(step): world.step_states.append('before') expected = 'Given I append "during" to states' if step.sentence != expected: raise TypeError('%r != %r' % (step.sentence, expected)) @step('append "during" to states') def append_during_to_step_states(step): world.step_states.append("during") @after.each_step def set_state_to_after(step): world.step_states.append('after') expected = 'Given I append "during" to states' if step.sentence != expected: raise TypeError('%r != %r' % (step.sentence, expected)) feature = Feature.from_string(FEATURE1) feature.run() assert_equals(world.step_states, ['before', 'during', 'after'])
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 that(feature.scenarios[0].tags).deep_equals( ['onetag', 'another', '$%^&even-weird_chars'])
def test_scenarios_with_special_characters(): "Make sure that regex special characters in the scenario names are ignored" feature = Feature.from_string(FEATURE19) assert that(feature.scenarios[0].tags).deep_equals(['runme1']) assert that(feature.scenarios[1].tags).deep_equals(['runme2'])
def test_outline_hooks(): "terrain.before.each_outline and terrain.after.each_outline decorators" world.scenario_names = set() world.hooks = [] @before.each_scenario def before_scenario(scenario): world.hooks.append("before scenario {0}".format(scenario.name)) @after.each_scenario def after_scenario(scenario): world.hooks.append("after scenario {0}".format(scenario.name)) @before.each_outline def before_outline(scenario, outline): world.scenario_names.add(scenario.name) world.hooks.append("before {0}".format(outline["outline"])) @after.each_outline def after_outline(scenario, outline): world.scenario_names.add(scenario.name) world.hooks.append("after {0}".format(outline["outline"])) feature = Feature.from_string(OUTLINE_FEATURE) feature.run() assert_equals(world.hooks, [ 'before scenario Outlines', 'before first_outline', 'after first_outline', 'before second_outline', 'after second_outline', 'after scenario Outlines' ])
def test_outline_hooks(): "terrain.before.each_outline and terrain.after.each_outline decorators" world.scenario_names = set() world.hooks = [] @before.each_scenario def before_scenario(scenario): world.hooks.append("before scenario {0}".format(scenario.name)) @after.each_scenario def after_scenario(scenario): world.hooks.append("after scenario {0}".format(scenario.name)) @before.each_outline def before_outline(scenario, outline): world.scenario_names.add(scenario.name) world.hooks.append("before {0}".format(outline["outline"])) @after.each_outline def after_outline(scenario, outline): world.scenario_names.add(scenario.name) world.hooks.append("after {0}".format(outline["outline"])) feature = Feature.from_string(OUTLINE_FEATURE) feature.run() assert_equals(world.hooks, ['before scenario Outlines', 'before first_outline', 'after first_outline', 'before second_outline', 'after second_outline', 'after scenario Outlines'])
def test_description_on_big_sentenced_steps(): "Can parse the description on long sentenced steps" feature = Feature.from_string(FEATURE4) assert_equals( feature.description, "As a clever guy\n" "I want to describe this Feature\n" "So that I can take care of my Scenario")
def test_feature_ptbr_from_string(): 'Language: RU -> Feature.from_string' ru = Language('ru') feature = Feature.from_string(FEATURE, language=ru) assert_equals(feature.name, 'Деление чисел') assert_equals( feature.description, "Поскольку деление сложный процесс и люди часто допускают ошибки\n" "Нужно дать им возможность делить на калькуляторе") (scenario, ) = feature.scenarios assert_equals(scenario.name, 'Целочисленное деление') assert_equals(scenario.steps[-1].hashes, [ { 'делимое': '100', 'делитель': '2', 'частное': '50' }, { 'делимое': '28', 'делитель': '7', 'частное': '4' }, { 'делимое': '0', 'делитель': '5', 'частное': '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_equals( feature.name, u'Faire plusieur choses en même temps' ) assert_equals( 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_equals( scenario.name, 'Ajouter 2 nombres' ) assert_equals( 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'}, ] )
def test_feature_has_scenarios(): "A feature object should have a list of scenarios" feature = Feature.from_string(FEATURE1) assert_equals(type(feature.scenarios), list) assert_equals(len(feature.scenarios), 3, "It should have 3 scenarios") expected_scenario_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_scenario_names): assert_equals(type(scenario), Scenario) assert_equals(scenario.name, expected_name) assert_equals(feature.scenarios[1].steps[0].keys, ('Name', 'Rating', 'New', 'Available')) assert_equals(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_has_scenarios(): "A feature object should have a list of scenarios" feature = Feature.from_string(FEATURE1) expect(feature.scenarios).to.be.a(list) expect(feature.scenarios).to.have.length_of(3) expected_scenario_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_scenario_names): expect(scenario).to.be.a(Scenario) expect(scenario.name).to.equal(expected_name) expect(feature.scenarios[1].steps[0].keys).to.equal( ('Name', 'Rating', 'New', 'Available')) expect(list(feature.scenarios[1].steps[0].hashes)).to.equal([ { '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_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 that(first_scenario.tags).deep_equals([ 'many', 'other', 'basic', 'tags', 'here', ':)'])
def test_description_on_long_named_feature(): "Can parse the description on long named features" feature = Feature.from_string(FEATURE3) assert_equals( feature.description, "In order to describe my features\n" "I want to add description on them", )
def test_skipped_steps_can_be_retrieved_as_steps(): "Skipped steps can be retrieved as steps" f = Feature.from_string(FEATURE1) feature_result = f.run() scenario_result = feature_result.scenario_results[0] for step in scenario_result.steps_skipped: assert_equals(type(step), Step)
def test_scenario_has_name(): "It should extract the name string from the scenario" feature = Feature.from_string(FEATURE1) assert isinstance(feature, Feature) expect(feature.name).to.equal("Rent movies")
def parse_scenario(string, language=None): feature = u""" Функция: parse_scenario """ feature += string feature = Feature.from_string(feature, language=language) return feature.scenarios[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 that(first_scenario.tags).deep_equals( ['many', 'other', 'basic', 'tags', 'here', ':)'])
def test_skipped_steps_can_be_retrieved_as_steps(): "Skipped steps can be retrieved as steps" f = Feature.from_string(FEATURE1) feature_result = f.run() scenario_result = feature_result.scenario_results[0] for step in scenario_result.steps_skipped: assert_equals(type(step), Step)
def test_description_on_long_named_feature(): "Can parse the description on long named features" feature = Feature.from_string(FEATURE3) assert_equals( feature.description, "In order to describe my features\n" "I want to add description on them", )
def test_scenario_has_name(): "It should extract the name string from the scenario" feature = Feature.from_string(FEATURE1) assert isinstance(feature, Feature) expect(feature.name).to.equal("Rent movies")
def test_feature_and_scenario_tags_extraction(): "Feature tags should be applied to all its scenarios" feature = Feature.from_string(FEATURE24) assert that(feature.scenarios[0].tags).deep_equals([ 'feature-tag']) assert that(feature.scenarios[1].tags).deep_equals([ 'scenario-tag', 'feature-tag'])
def test_background(): "It should parse the background section" feature = Feature.from_string(FEATURE11) assert_true(feature.background is not None) assert_equals(len(feature.background.steps), 2) assert_equals(feature.background.steps[0].sentence, "Given I'm working at Video Library") assert_equals(feature.background.steps[1].sentence, "And there is a sale today")
def test_scenarios_with_special_characters(): "Make sure that regex special characters in the scenario names are ignored" feature = Feature.from_string(FEATURE19) assert that(feature.scenarios[0].tags).deep_equals([ 'runme1']) assert that(feature.scenarios[1].tags).deep_equals([ 'runme2'])
def test_feature_has_background(): """Ensure that background section is parsed as expected""" feature = Feature.from_string(FEATURE2) assert feature.background is not None assert feature.background.steps assert_equals(len(feature.background.steps), 1) assert_equals(len(feature.scenarios), 1) assert_equals(len(feature.scenarios[0].steps), 4)
def parse_scenario(string, language=None): feature = """ Funcionalidade: parse_scenario """ feature += string feature = Feature.from_string(feature, language=language) return feature.scenarios[0]
def parse_steps(steps): feature = """ Feature: a feature Scenario: a scenario """ feature += steps return Feature.from_string(feature)
def test_ignore_case_on_step_definitions(): "By default lettuce ignore case on step definitions" f = Feature.from_string(FEATURE3) feature_result = f.run() scenario_result = feature_result.scenario_results[0] assert_equals(len(scenario_result.steps_passed), 3) assert_equals(scenario_result.total_steps, 3) assert all([s.has_definition for s in scenario_result.scenario.steps])
def test_ignore_case_on_step_definitions(): "By default lettuce ignore case on step definitions" f = Feature.from_string(FEATURE3) feature_result = f.run() scenario_result = feature_result.scenario_results[0] assert_equals(len(scenario_result.steps_passed), 3) assert_equals(scenario_result.total_steps, 3) assert all([s.has_definition for s in scenario_result.scenario.steps])
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_equals(scenario1.name, 'Do something') assert_equals(scenario2.name, 'Do something else') assert_equals(scenario3.name, 'Worked!') assert_equals(scenario4.name, 'Add two numbers wisely') assert_equals(len(scenario1.solved_steps), 2) expected_sentences = [ 'Given I have entered ok into the fail', 'Given I have entered fail into the ok', ] for step, expected_sentence in zip(scenario1.solved_steps, expected_sentences): assert_equals(step.sentence, expected_sentence) 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): sentences_of = lambda x: x.sentence assert_equals(got_examples, expected_examples) assert_equals(list(map(sentences_of, got_steps)), expected_steps)
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_equals(scenario1.name, 'Do something') assert_equals(scenario2.name, 'Do something else') assert_equals(scenario3.name, 'Worked!') assert_equals(scenario4.name, 'Add two numbers wisely') assert_equals(len(scenario1.solved_steps), 2) expected_sentences = [ 'Given I have entered ok into the fail', 'Given I have entered fail into the ok', ] for step, expected_sentence in zip(scenario1.solved_steps, expected_sentences): assert_equals(step.sentence, expected_sentence) 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): sentences_of = lambda x: x.sentence assert_equals(got_examples, expected_examples) assert_equals(map(sentences_of, got_steps), expected_steps)
def test_feature_hooks_not_invoked_if_no_scenarios_run(): feature = Feature.from_string(FEATURE3) world.feature_steps = [] feature.run(tags=['tag1']) assert_equals(world.feature_steps, ['before', 'during', 'after']) world.feature_steps = [] feature.run(tags=['tag3']) assert_equals(world.feature_steps, [])
def test_features(self): import lettuce_webdriver.webdriver import lettuce_webdriver.css_selector_steps for feature_string in FEATURES: f = Feature.from_string(feature_string) feature_result = f.run(failfast=True) scenario_result = feature_result.scenario_results[0] self.assertFalse(scenario_result.steps_failed) self.assertFalse(scenario_result.steps_skipped) self.assertFalse(scenario_result.steps_undefined)
def test_doesnt_ignore_case(): "Lettuce can, optionally consider case on step definitions" f = Feature.from_string(FEATURE3) feature_result = f.run(ignore_case=False) scenario_result = feature_result.scenario_results[0] assert_equals(len(scenario_result.steps_passed), 1) assert_equals(len(scenario_result.steps_undefined), 2) assert_equals(scenario_result.total_steps, 3) assert not all([s.has_definition for s in scenario_result.scenario.steps])
def test_doesnt_ignore_case(): "Lettuce can, optionally consider case on step definitions" f = Feature.from_string(FEATURE3) feature_result = f.run(ignore_case=False) scenario_result = feature_result.scenario_results[0] assert_equals(len(scenario_result.steps_passed), 1) assert_equals(len(scenario_result.steps_undefined), 2) assert_equals(scenario_result.total_steps, 3) assert not all([s.has_definition for s in scenario_result.scenario.steps])
def test_count_raised_exceptions_as_failing_steps(): "When a step definition raises an exception, it is marked as a failed step. " try: f = Feature.from_string(FEATURE8) feature_result = f.run() scenario_result = feature_result.scenario_results[0] assert_equals(len(scenario_result.steps_failed), 1) finally: registry.clear()
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 scenario1.tags.should.be.empty scenario2.tags.should.equal(['tag'])
def test_features(self): import lettuce_webdriver.webdriver import lettuce_webdriver.css_selector_steps for feature_string in FEATURES: f = Feature.from_string(feature_string) feature_result = f.run(failfast=True) scenario_result = feature_result.scenario_results[0] self.assertFalse(scenario_result.steps_failed) self.assertFalse(scenario_result.steps_skipped) self.assertFalse(scenario_result.steps_undefined)
def test_count_raised_exceptions_as_failing_steps(): "When a step definition raises an exception, it is marked as a failed step. " try: f = Feature.from_string(FEATURE8) feature_result = f.run() scenario_result = feature_result.scenario_results[0] assert_equals(len(scenario_result.steps_failed), 1) finally: registry.clear()
def test_steps_that_match_groups_and_named_groups_takes_just_named_as_params(): "Steps that match groups and named groups takes just the named as parameters" @step(r'(he|she) gets a (?P<what>\w+)') def given_action_named(step, what): assert_equals(what, 'caipirinha') f = Feature.from_string(FEATURE6) feature_result = f.run() scenario_result = feature_result.scenario_results[0] assert_equals(len(scenario_result.steps_passed), 1) assert_equals(scenario_result.total_steps, 1)
def test_scenarios_with_extra_whitespace(): "Make sure that extra leading whitespace is ignored" feature = Feature.from_string(FEATURE14) assert_equals(type(feature.scenarios), list) assert_equals(len(feature.scenarios), 1, "It should have 1 scenario") assert_equals(feature.name, "Extra whitespace feature") scenario = feature.scenarios[0] assert_equals(type(scenario), Scenario) assert_equals(scenario.name, "Extra whitespace scenario")
def test_steps_that_match_groups_takes_them_as_parameters(): "Steps that match groups takes them as parameters" @step(r'Given a ([^\s]+) called "(.*)"') def given_what_named(step, what, name): assert_equals(what, 'person') assert_equals(name, 'John Doe') f = Feature.from_string(FEATURE4) feature_result = f.run() scenario_result = feature_result.scenario_results[0] assert_equals(len(scenario_result.steps_passed), 1) assert_equals(scenario_result.total_steps, 1)
def test_steps_that_match_named_groups_takes_them_as_parameters(): "Steps that match named groups takes them as parameters" @step(r'When a (?P<what>\w+) at "(?P<city>.*)"') def given_action_named(step, what, city): assert_equals(what, 'foreign') assert_equals(city, 'Rio de Janeiro') f = Feature.from_string(FEATURE5) feature_result = f.run() scenario_result = feature_result.scenario_results[0] assert_equals(len(scenario_result.steps_passed), 1) assert_equals(scenario_result.total_steps, 1)
def test_feature_can_run_only_specified_scenarios(): "Features can run only specified scenarios, by index + 1" feature = Feature.from_string(FEATURE7) scenarios_ran = [] @after.each_scenario def just_register(scenario): scenarios_ran.append(scenario.name) feature.run(scenarios=(2, 5)) assert_equals(scenarios_ran, ['2nd one', '5th one'])
def test_single_feature_single_tag(): "All scenarios within a feature inherit the feature's tags" feature = Feature.from_string(FEATURE18) assert that(feature.scenarios[0].tags).deep_equals( ['runme1', 'feature_runme']) assert that(feature.scenarios[1].tags).deep_equals( ['runme2', 'feature_runme']) assert that(feature.scenarios[2].tags).deep_equals( ['runme3', 'feature_runme'])