def test_scenario_may_own_outlines(): "A scenario may own outlines" scenario = Scenario.from_string(OUTLINED_SCENARIO) assert_equals(len(scenario.steps), 4) expected_sentences = [ 'Given I have entered <input_1> into the calculator', 'And I have entered <input_2> into the calculator', 'When I press <button>', 'Then the result should be <output> on the screen', ] for step, expected_sentence in zip(scenario.steps, expected_sentences): assert_equals(type(step), Step) assert_equals(step.sentence, expected_sentence) assert_equals(scenario.name, "Add two numbers") assert_equals( scenario.outlines, [ {'input_1': '20', 'input_2': '30', 'button': 'add', 'output': '50'}, {'input_1': '2', 'input_2': '5', 'button': 'add', 'output': '7'}, {'input_1': '0', 'input_2': '40', 'button': 'add', 'output': '40'}, ] )
def test_scenario_has_repr(): "Scenario implements __repr__ nicely" scenario = Scenario.from_string(SCENARIO1) assert_equals( repr(scenario), '<Scenario: "Adding some students to my university database">' )
def test_scenario_outline3_fr_from_string(): 'Language: FR -> Scenario.from_string, with scenario outline, third case' lang = Language('fr') scenario = Scenario.from_string(OUTLINED_SCENARIO2, language=lang) assert_equals(scenario.name, 'Ajouter 2 nombres') assert_equals(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' }, ])
def test_scenario_has_steps(): "A scenario object should have a list of steps" scenario = Scenario.from_string(SCENARIO1) assert_equals(type(scenario.steps), list) assert_equals(len(scenario.steps), 4, "It should have 4 steps") expected_sentences = [ "Given I have the following courses in my university:", "When I consolidate the database into 'courses.txt'", "Then I see the 1st line of 'courses.txt' has 'Computer Science:5'", "And I see the 2nd line of 'courses.txt' has 'Nutrition:4'", ] for step, expected_sentence in zip(scenario.steps, expected_sentences): assert_equals(type(step), Step) assert_equals(step.sentence, expected_sentence) assert_equals(scenario.steps[0].keys, ('Name', 'Duration')) assert_equals( scenario.steps[0].hashes, [ {'Name': 'Computer Science', 'Duration': '5 years'}, {'Name': 'Nutrition', 'Duration': '4 years'}, ] )
def test_scenario_tables_are_solved_against_outlines(): "Outline substitution should apply to tables within a scenario" expected_hashes_per_step = [ # a = 1, b = 2 [{ 'Parameter': 'a', 'Value': '1' }, { 'Parameter': 'b', 'Value': '2' }], # Given ... [], # When I run the program [], # Then I crash hard-core # a = 2, b = 4 [{ 'Parameter': 'a', 'Value': '2' }, { 'Parameter': 'b', 'Value': '4' }], [], [] ] scenario = Scenario.from_string( OUTLINED_SCENARIO_WITH_SUBSTITUTIONS_IN_TABLE) for step, expected_hashes in zip(scenario.solved_steps, expected_hashes_per_step): assert_equals(type(step), Step) assert_equals(step.hashes, expected_hashes)
def test_scenario_has_steps(): "A scenario object should have a list of steps" scenario = Scenario.from_string(SCENARIO1) assert_equals(type(scenario.steps), list) assert_equals(len(scenario.steps), 4, "It should have 4 steps") expected_sentences = [ "Given I have the following courses in my university:", "When I consolidate the database into 'courses.txt'", "Then I see the 1st line of 'courses.txt' has 'Computer Science:5'", "And I see the 2nd line of 'courses.txt' has 'Nutrition:4'", ] for step, expected_sentence in zip(scenario.steps, expected_sentences): assert_equals(type(step), Step) assert_equals(step.sentence, expected_sentence) assert_equals(scenario.steps[0].keys, ('Name', 'Duration')) assert_equals(scenario.steps[0].hashes, [ { 'Name': 'Computer Science', 'Duration': '5 years' }, { 'Name': 'Nutrition', 'Duration': '4 years' }, ])
def test_scenario_matches_tags_excluding_when_scenario_has_no_tags(): ("When Scenario#matches_tags is called for a scenario " "that has no tags and the given match is a exclusionary tag") scenario = Scenario.from_string(SCENARIO1, original_string=(SCENARIO1.strip())) assert scenario.matches_tags(['-nope', '-neither'])
def test_scenario_has_tag(): "A scenario object should be able to find at least one tag " \ "on the first line" scenario = Scenario.from_string( SCENARIO1, original_string=('@onetag\n' + SCENARIO1.strip())) assert that(scenario.tags).deep_equals(['onetag'])
def test_scenario_has_tag(): "A scenario object should be able to find at least one tag " \ "on the first line" scenario = Scenario.from_string(SCENARIO1, original_string=('@onetag\n' + SCENARIO1.strip())) assert that(scenario.tags).deep_equals(['onetag'])
def test_scenario_has_tag(): ("A scenario object should be able to find at least one tag " "on the first line") scenario = Scenario.from_string(SCENARIO1, original_string=('@onetag\n' + SCENARIO1.strip())) expect(scenario.tags).to.equal(['onetag'])
def test_scenario_matches_tags_fuzzywuzzy(): ("When Scenario#matches_tags is called with a member starting with ~ " "it will consider a fuzzywuzzy match") scenario = Scenario.from_string( SCENARIO1, original_string=('@anothertag\n@another-tag\n' + SCENARIO1.strip())) assert scenario.matches_tags(['~another'])
def test_scenario_has_tag(): ("A scenario object should be able to find at least one tag " "on the first line") scenario = Scenario.from_string( SCENARIO1, original_string=('@onetag\n' + SCENARIO1.strip())) expect(scenario.tags).to.equal(['onetag'])
def test_scenario_matches_tags_excluding_fuzzywuzzy(): ("When Scenario#matches_tags is called with a member starting with -~ " "it will exclude that tag from that fuzzywuzzy match") scenario = Scenario.from_string( SCENARIO1, original_string=('@anothertag\n@another-tag\n' + SCENARIO1.strip())) assert not scenario.matches_tags(['-~anothertag'])
def test_scenario_matches_tags_fuzzywuzzy(): ("When Scenario#matches_tags is called with a member starting with ~ " "it will consider a fuzzywuzzy match") scenario = Scenario.from_string(SCENARIO1, original_string=SCENARIO1.strip(), tags=['anothertag', 'another-tag']) assert scenario.matches_tags(['~another'])
def test_scenario_with_inline_comments(): ("Scenarios can have steps with inline comments") scenario = Scenario.from_string(INLINE_COMMENTS) step1, step2 = scenario.steps expect(step1.sentence).to.equal(u'Given I am using an anvil') expect(step2.sentence).to.equal(u'And I am using a hammer')
def test_scenario_tables_are_solved_against_outlines(): "Outline substitution should apply to multiline strings within a scenario" expected_multiline = '<div>outline value</div>' scenario = Scenario.from_string(OUTLINED_SCENARIO_WITH_SUBSTITUTIONS_IN_MULTILINE) step = scenario.solved_steps[0] assert_equals(type(step), Step) assert_equals(step.multiline, expected_multiline)
def test_scenario_matches_tags_excluding_when_scenario_has_no_tags(): ("When Scenario#matches_tags is called for a scenario " "that has no tags and the given match is a exclusionary tag") scenario = Scenario.from_string( SCENARIO1, original_string=(SCENARIO1.strip())) assert scenario.matches_tags(['-nope', '-neither'])
def test_scenario_has_name(): "It should extract the name of the scenario" scenario = Scenario.from_string(SCENARIO1) assert isinstance(scenario, Scenario) assert_equals(scenario.name, "Adding some students to my university database")
def test_scenario_show_tags_in_its_representation(): ("Scenario#represented should show its tags") scenario = Scenario.from_string(SCENARIO1, original_string=SCENARIO1.strip(), tags=['slow', 'firefox', 'chrome']) expect(scenario.represented()).to.equal( u' @slow @firefox @chrome\n ' 'Scenario: Adding some students to my university database')
def test_scenario_show_tags_in_its_representation(): ("Scenario#represented should show its tags") scenario = Scenario.from_string( SCENARIO1, original_string=('@slow\n@firefox\n@chrome\n' + SCENARIO1.strip())) assert that(scenario.represented()).equals( u' @slow @firefox @chrome\n ' 'Scenario: Adding some students to my university database')
def test_scenario_matches_tags_excluding(): ("When Scenario#matches_tags is called with a member starting with - " "it will exclude that tag from the matching") scenario = Scenario.from_string(SCENARIO1, original_string=SCENARIO1.strip(), tags=['anothertag', 'another-tag']) assert not scenario.matches_tags(['-anothertag']) assert scenario.matches_tags(['-foobar'])
def test_scenario_ignore_commented_lines_from_examples(): "Comments on scenario example should be ignored" scenario = Scenario.from_string(OUTLINED_SCENARIO_WITH_COMMENTS_ON_EXAMPLES) assert_equals( scenario.outlines, [ {'input_1': '20', 'input_2': '30', 'button': 'add', 'output': '50'}, {'input_1': '0', 'input_2': '40', 'button': 'add', 'output': '40'}, ] )
def test_scenario_with_hash_within_single_quotes(): ("Scenarios have hashes within single quotes and yet don't " "consider them as comments") scenario = Scenario.from_string( INLINE_COMMENTS_IGNORED_WITHIN_SINGLE_QUOTES) step1, step2 = scenario.steps expect(step1.sentence).to.equal(u'Given I am logged in on twitter') expect(step2.sentence).to.equal(u"When I search for the hashtag '#hammer'")
def test_scenario_matches_tags_excluding(): ("When Scenario#matches_tags is called with a member starting with - " "it will exclude that tag from the matching") scenario = Scenario.from_string( SCENARIO1, original_string=SCENARIO1.strip(), tags=['anothertag', 'another-tag']) assert not scenario.matches_tags(['-anothertag']) assert scenario.matches_tags(['-foobar'])
def test_scenario_matches_tags(): ("A scenario with tags should respond with True when " ".matches_tags() is called with a valid list of tags") scenario = Scenario.from_string(SCENARIO1, original_string=SCENARIO1.strip(), tags=['onetag', 'another-one']) expect(scenario.tags).to.equal(['onetag', 'another-one']) assert scenario.matches_tags(['onetag']) assert scenario.matches_tags(['another-one'])
def test_scenario_matches_tags(): ("A scenario with tags should respond with True when " ".matches_tags() is called with a valid list of tags") scenario = Scenario.from_string( SCENARIO1, original_string=('@onetag\n@another-one\n' + SCENARIO1.strip())) assert that(scenario.tags).deep_equals(['onetag', 'another-one']) assert scenario.matches_tags(['onetag']) assert scenario.matches_tags(['another-one'])
def test_scenario_matches_tags(): ("A scenario with tags should respond with True when " ".matches_tags() is called with a valid list of tags") scenario = Scenario.from_string( SCENARIO1, original_string=('@onetag\n@another-one\n' + SCENARIO1.strip())) assert that(scenario.tags).deep_equals(['onetag','another-one']) assert scenario.matches_tags(['onetag']) assert scenario.matches_tags(['another-one'])
def test_scenario_has_name(): "It should extract the name of the scenario" scenario = Scenario.from_string(SCENARIO1) assert isinstance(scenario, Scenario) assert_equals( scenario.name, "Adding some students to my university database" )
def test_scenario_show_tags_in_its_representation(): ("Scenario#represented should show its tags") scenario = Scenario.from_string( SCENARIO1, original_string=SCENARIO1.strip(), tags=['slow', 'firefox', 'chrome']) expect(scenario.represented()).to.equal( u' @slow @firefox @chrome\n ' 'Scenario: Adding some students to my university database')
def test_scenario_matches_tags(): ("A scenario with tags should respond with True when " ".matches_tags() is called with a valid list of tags") scenario = Scenario.from_string( SCENARIO1, original_string=SCENARIO1.strip(), tags=['onetag', 'another-one']) expect(scenario.tags).to.equal(['onetag', 'another-one']) assert scenario.matches_tags(['onetag']) assert scenario.matches_tags(['another-one'])
def test_scenario_has_tags_singleline(): ("A scenario object should be able to find many tags " "on the first line") scenario = Scenario.from_string( SCENARIO1, original_string=('@onetag @another @$%^&even-weird_chars \n' + SCENARIO1.strip())) expect(scenario.tags).to.equal([ 'onetag', 'another', '$%^&even-weird_chars', ])
def test_scenario_aggregate_all_examples_blocks(): "All scenario's examples block should be translated to outlines" scenario = Scenario.from_string(OUTLINED_SCENARIO_WITH_MORE_THAN_ONE_EXAMPLES_BLOCK) assert_equals( scenario.outlines, [ {'input_1': '20', 'input_2': '30', 'button': 'add', 'output': '50'}, {'input_1': '2', 'input_2': '5', 'button': 'add', 'output': '7'}, {'input_1': '0', 'input_2': '40', 'button': 'add', 'output': '40'}, {'input_1': '20', 'input_2': '33', 'button': 'add', 'output': '53'}, {'input_1': '12', 'input_2': '40', 'button': 'add', 'output': '52'}, ] )
def test_scenario_has_tags_singleline(): "A scenario object should be able to find many tags " \ "on the first line" scenario = Scenario.from_string( SCENARIO1, original_string=( '@onetag @another @$%^&even-weird_chars \n' + SCENARIO1.strip())) assert that(scenario.tags).deep_equals([ 'onetag', 'another', '$%^&even-weird_chars', ])
def test_scenario_has_tags_singleline(): ("A scenario object should be able to find many tags " "on the first line") scenario = Scenario.from_string( SCENARIO1, original_string=( '@onetag @another @$%^&even-weird_chars \n' + SCENARIO1.strip())) expect(scenario.tags).to.equal([ 'onetag', 'another', '$%^&even-weird_chars', ])
def test_scenario_has_tags_singleline(): "A scenario object should be able to find many tags " \ "on the first line" scenario = Scenario.from_string( SCENARIO1, original_string=('@onetag @another @$%^&even-weird_chars \n' + SCENARIO1.strip())) assert that(scenario.tags).deep_equals([ 'onetag', 'another', '$%^&even-weird_chars', ])
def test_scenario_ptbr_from_string(): 'Language: PT-BR -> Scenario.from_string' ptbr = Language('pt-br') scenario = Scenario.from_string(SCENARIO, language=ptbr) assert_equals( scenario.name, u'Consolidar o banco de dados de cursos universitários em arquivo texto' ) assert_equals( scenario.steps[0].hashes, [ {'Nome': u'Ciência da Computação', u'Duração': '5 anos'}, {'Nome': u'Nutrição', u'Duração': '4 anos'}, ] )
def test_scenario_outline1_ru_from_string(): 'Language: RU -> Scenario.from_string, with scenario outline, first case' ru = Language('ru') scenario = Scenario.from_string(SCENARIO_OUTLINE1, language=ru) assert_equals( scenario.name, u'Заполнение пользователей в базу' ) assert_equals( scenario.outlines, [ {u'имя': u'Вася', u'возраст': '22'}, {u'имя': u'Петя', u'возраст': '30'}, ] )
def test_scenario_outline2_ptbr_from_string(): 'Language: PT-BR -> Scenario.from_string, with scenario outline, second case' ptbr = Language('pt-br') scenario = Scenario.from_string(SCENARIO_OUTLINE2, language=ptbr) assert_equals(scenario.name, 'Cadastrar um aluno no banco de dados') assert_equals(scenario.outlines, [ { 'nome': u'Gabriel', u'idade': '99' }, { 'nome': u'João', u'idade': '100' }, ])
def test_scenario_outline1_ptbr_from_string(): 'Language: PT-BR -> Scenario.from_string, with scenario outline, first case' ptbr = Language('pt-br') scenario = Scenario.from_string(SCENARIO_OUTLINE1, language=ptbr) assert_equals(scenario.name, 'Cadastrar um aluno no banco de dados') assert_equals(scenario.outlines, [ { 'nome': 'Gabriel', 'idade': '22' }, { 'nome': 'João', 'idade': '30' }, ])
def test_scenario_outline1_ptbr_from_string(): 'Language: PT-BR -> Scenario.from_string, with scenario outline, first case' ptbr = Language('pt-br') scenario = Scenario.from_string(SCENARIO_OUTLINE1, language=ptbr) assert_equals( scenario.name, 'Cadastrar um aluno no banco de dados' ) assert_equals( scenario.outlines, [ {'nome': 'Gabriel', 'idade': '22'}, {'nome': 'João', 'idade': '30'}, ] )
def test_scenario_ru_from_string(): 'Language: RU -> Scenario.from_string' ru = Language('ru') scenario = Scenario.from_string(SCENARIO, language=ru) assert_equals( scenario.name, u'Сохранение базы курсов универитета в текстовый файл' ) assert_equals( scenario.steps[0].hashes, [ {u'Название': u'Матан', u'Длительность': u'2 года'}, {u'Название': u'Основы программирования', u'Длительность': u'1 год'}, ] )
def test_scenario_outline1_ru_from_string(): 'Language: RU -> Scenario.from_string, with scenario outline, first case' ru = Language('ru') scenario = Scenario.from_string(SCENARIO_OUTLINE1, language=ru) assert_equals(scenario.name, 'Заполнение пользователей в базу') assert_equals(scenario.outlines, [ { 'имя': 'Вася', 'возраст': '22' }, { 'имя': 'Петя', 'возраст': '30' }, ])
def test_scenario_fr_from_string(): 'Language: FR -> Scenario.from_string' lang = Language('fr') scenario = Scenario.from_string(SCENARIO, language=lang) assert_equals( scenario.name, u'Ajout de plusieurs cursus dans la base de mon université' ) assert_equals( scenario.steps[0].hashes, [ {'Nom': u"Science de l'Informatique", u'Durée': '5 ans'}, {'Nom': u'Nutrition', u'Durée': '4 ans'}, ] )
def test_scenario_outline2_ptbr_from_string(): 'Language: PT-BR -> Scenario.from_string, with scenario outline, second case' ptbr = Language('pt-br') scenario = Scenario.from_string(SCENARIO_OUTLINE2, language=ptbr) assert_equals( scenario.name, 'Cadastrar um aluno no banco de dados' ) assert_equals( scenario.outlines, [ {'nome': u'Gabriel', u'idade': '99'}, {'nome': u'João', u'idade': '100'}, ] )
def test_scenario_outline3_fr_from_string(): 'Language: FR -> Scenario.from_string, with scenario outline, third case' lang = Language('fr') scenario = Scenario.from_string(OUTLINED_SCENARIO2, language=lang) 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_scenario_outline1_fr_from_string(): 'Language: FR -> Scenario.from_string, with scenario outline, first case' lang = Language('fr') scenario = Scenario.from_string(OUTLINED_SCENARIO, language=lang) 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_scenario_ru_from_string(): 'Language: RU -> Scenario.from_string' ru = Language('ru') scenario = Scenario.from_string(SCENARIO, language=ru) assert_equals(scenario.name, 'Сохранение базы курсов универитета в текстовый файл') assert_equals(scenario.steps[0].hashes, [ { 'Название': 'Матан', 'Длительность': '2 года' }, { 'Название': 'Основы программирования', 'Длительность': '1 год' }, ])
def test_scenario_outline1_fr_from_string(): 'Language: FR -> Scenario.from_string, with scenario outline, first case' lang = Language('fr') scenario = Scenario.from_string(OUTLINED_SCENARIO, language=lang) assert_equals( scenario.name, 'Ajouter 2 nombres' ) assert_equals( 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'}, ] )
def test_scenario_tables_are_solved_against_outlines(): "Outline substitution should apply to tables within a scenario" expected_hashes_per_step = [ # a = 1, b = 2 [{'Parameter': 'a', 'Value': '1'}, {'Parameter': 'b', 'Value': '2'}], # Given ... [], # When I run the program [], # Then I crash hard-core # a = 2, b = 4 [{'Parameter': 'a', 'Value': '2'}, {'Parameter': 'b', 'Value': '4'}], [], [] ] scenario = Scenario.from_string(OUTLINED_SCENARIO_WITH_SUBSTITUTIONS_IN_TABLE) for step, expected_hashes in zip(scenario.solved_steps, expected_hashes_per_step): assert_equals(type(step), Step) assert_equals(step.hashes, expected_hashes)