示例#1
0
 def test_can_run_feature_with_scenario_outline_with_hashes(self):
     @step('a hash')
     def a_hash(step):
         my_world.run.append(list(step.hashes))
     feature = load_feature('''
     Feature: with multiline scenarnio
       Scenario Outline: follows
         Given a hash
           | <key>   | value         |
           | the     | <placeholder> |
       Examples:
         | <key> | <placeholder> |
         | key   | first         |
         | but   | second        |
     ''')
     my_world = World()
     my_world.run = []
     result = unittest.TestResult()
     
     feature.run(result)
     
     result.testsRun |should| be(2)
     result.wasSuccessful() |should| be(True)
     my_world.run |should| each_be_equal_to([
         [dict(key='the', value='first')],
         [dict(but='the', value='second')],
     ])
示例#2
0
 def test_can_run_feature_with_scenario_outline_with_multiline(self):
     @step('a multiline')
     def a_multiline(step):
         my_world.run.append(step.multiline)
     feature = load_feature('''
     Feature: with multiline scenarnio
       Scenario Outline: follows
         Given a multiline
           """
           with <placeholder>
           """
       Examples:
         | <placeholder> |
         | first         |
         | second        |
     ''')
     my_world = World()
     my_world.run = []
     result = unittest.TestResult()
     
     feature.run(result)
     
     result.testsRun |should| be(2)
     result.wasSuccessful() |should| be(True)
     my_world.run |should| each_be_equal_to([
         'with first\n',
         'with second\n',
     ])
示例#3
0
 def test_can_run_feature_with_scenario_outline_with_background(self):
     @step('a (.*)')
     def a_something(step, value):
         my_world.run.append(value)
     feature = load_feature('''
     Feature: with multiline scenarnio
       Background: with placeholder
         Given a <placeholder>
       Scenario Outline: follows
         And a step
       Examples:
         | <placeholder> |
         | first         |
         | second        |
     ''')
     my_world = World()
     my_world.run = []
     result = unittest.TestResult()
     
     feature.run(result)
     
     result.testsRun |should| be(2)
     result.wasSuccessful() |should| be(True)
     my_world.run |should| each_be_equal_to([
         'first', 'step', 'second', 'step',
     ])
示例#4
0
 def test_can_run_feature(self):
     @step('there is a step')
     def there_is_a_step(step):
         my_world.there_is_a_step = True
     @step('another step')
     def another_step(step):
         my_world.another_step = True
     @step('steps afterwards')
     def steps_afterwards(step):
         my_world.steps_afterwards = True
     feature = load_feature('''
     Feature: run a feature
       Scenario: some steps
         Given there is a step
         And another step
         When I add something undefined
         Then steps afterwards are not run
     ''')
     my_world = World()
     my_world.there_is_a_step = False
     my_world.another_step = False
     my_world.steps_afterwards = False
     result = unittest.TestResult()
     
     feature.run(result)
     
     len(result.skipped) |should| be(1)
     result.skipped[0][1] |should| start_with('pending 1 step(s):')
     run = my_world.there_is_a_step, my_world.another_step, my_world.steps_afterwards
     run |should| be_equal_to((True, True, False))
示例#5
0
    def test_can_run_feature_with_multiple_backgrounds(self):
        @step('background step ([0-9]+)')
        def background_step_number(step, number):
            my_world.background_number = number

        @step('scenario step ([0-9]+)')
        def scenario_step_number(step, number):
            my_world.background_number | should | be_equal_to(number)
            my_world.steps_run.append(int(number))

        feature = load_feature('''
        Feature: with background
          Background: 1 present
            Given a background step 1
          Scenario: with background 1
            And a scenario step 1
          Background: 2 present
            Given a background step 2
          Scenario: with background 2
            And a scenario step 2
        ''')
        my_world = World()
        my_world.steps_run = []
        result = unittest.TestResult()

        feature.run(result)

        result.testsRun | should | be(2)
        result.wasSuccessful() | should | be(True)
        my_world.steps_run | should | be_equal_to([1, 2])
示例#6
0
 def test_can_run_feature_with_hashes_in_background_step(self):
     @step('step with hashes')
     def step_with_hashes(step):
         my_world.hashes = step.hashes
     @step('here it is')
     def here_it_is(step):
         pass
     feature = load_feature('''
     Feature: with multiline scenarnio
       Background: with multiline step
         Given a step with hashes
           | first   | second    | third     |
           | first 1 | second 1  | third 1   |
           | first 2 | second 2  | third 2   |
       Scenario: with defined step
         And here it is
     ''')
     my_world = World()
     my_world.hashes = None
     result = unittest.TestResult()
     
     feature.run(result)
     
     result.testsRun |should| be(1)
     result.wasSuccessful() |should| be(True)
     my_world.hashes |should| each_be_equal_to([
         dict(first='first 1', second='second 1', third='third 1'),
         dict(first='first 2', second='second 2', third='third 2'),
     ])
示例#7
0
 def test_creates_one_test_method_per_scenario(self):
     feature = loader.load_feature('''
     Feature: Load feature file
       Scenario: pending
       Scenario: second one
     ''')
     feature.countTestCases() | should | be(2)
示例#8
0
 def test_can_run_feature_with_scenario_outline_and_examples(self):
     @step('a (.*) with (.*)')
     def a_key_with_value(step, key, value):
         my_world.run.append((key, value))
     feature = load_feature('''
     Feature: with multiline scenarnio
       Scenario Outline: follows
         Given a <key> with <value>
       Examples:
         | key   | value     |
         | key 1 | value 1   |
         | key 2 | value 2   |
     ''')
     my_world = World()
     my_world.run = []
     result = unittest.TestResult()
     
     feature.run(result)
     
     result.testsRun |should| be(2)
     result.wasSuccessful() |should| be(True)
     my_world.run |should| each_be_equal_to([
         ('key 1', 'value 1'),
         ('key 2', 'value 2'),
     ])
示例#9
0
    def test_can_run_feature_with_scenario_outline_and_examples(self):
        @step('a (.*) with (.*)')
        def a_key_with_value(step, key, value):
            my_world.run.append((key, value))

        feature = load_feature('''
        Feature: with multiline scenarnio
          Scenario Outline: follows
            Given a <key> with <value>
          Examples:
            | key   | value     |
            | key 1 | value 1   |
            | key 2 | value 2   |
        ''')
        my_world = World()
        my_world.run = []
        result = unittest.TestResult()

        feature.run(result)

        result.testsRun | should | be(2)
        result.wasSuccessful() | should | be(True)
        my_world.run | should | each_be_equal_to([
            ('key 1', 'value 1'),
            ('key 2', 'value 2'),
        ])
示例#10
0
    def test_can_run_feature_with_hashes_in_background_step(self):
        @step('step with hashes')
        def step_with_hashes(step):
            my_world.hashes = step.hashes

        @step('here it is')
        def here_it_is(step):
            pass

        feature = load_feature('''
        Feature: with multiline scenarnio
          Background: with multiline step
            Given a step with hashes
              | first   | second    | third     |
              | first 1 | second 1  | third 1   |
              | first 2 | second 2  | third 2   |
          Scenario: with defined step
            And here it is
        ''')
        my_world = World()
        my_world.hashes = None
        result = unittest.TestResult()

        feature.run(result)

        result.testsRun | should | be(1)
        result.wasSuccessful() | should | be(True)
        my_world.hashes | should | each_be_equal_to([
            dict(first='first 1', second='second 1', third='third 1'),
            dict(first='first 2', second='second 2', third='third 2'),
        ])
示例#11
0
 def test_can_run_feature_with_multiple_backgrounds(self):
     @step('background step ([0-9]+)')
     def background_step_number(step, number):
         my_world.background_number = number
     @step('scenario step ([0-9]+)')
     def scenario_step_number(step, number):
         my_world.background_number |should| be_equal_to(number)
         my_world.steps_run.append(int(number))
     feature = load_feature('''
     Feature: with background
       Background: 1 present
         Given a background step 1
       Scenario: with background 1
         And a scenario step 1
       Background: 2 present
         Given a background step 2
       Scenario: with background 2
         And a scenario step 2
     ''')
     my_world = World()
     my_world.steps_run = []
     result = unittest.TestResult()
     
     feature.run(result)
     
     result.testsRun |should| be(2)
     result.wasSuccessful() |should| be(True)
     my_world.steps_run |should| be_equal_to([1, 2])
示例#12
0
    def test_can_use_custom_TestCase_subclass(self):
        class MyTestCase(unittest.TestCase):
            pass

        feature = loader.load_feature('Feature:', test_case_class=MyTestCase)
        test_case = six.next(iter(feature))
        test_case | should | be_instance_of(MyTestCase)
示例#13
0
    def test_can_run_feature_with_scenario_outline_with_multiline(self):
        @step('a multiline')
        def a_multiline(step):
            my_world.run.append(step.multiline)

        feature = load_feature('''
        Feature: with multiline scenarnio
          Scenario Outline: follows
            Given a multiline
              """
              with <placeholder>
              """
          Examples:
            | <placeholder> |
            | first         |
            | second        |
        ''')
        my_world = World()
        my_world.run = []
        result = unittest.TestResult()

        feature.run(result)

        result.testsRun | should | be(2)
        result.wasSuccessful() | should | be(True)
        my_world.run | should | each_be_equal_to([
            'with first\n',
            'with second\n',
        ])
示例#14
0
    def test_can_run_feature(self):
        @step('there is a step')
        def there_is_a_step(step):
            my_world.there_is_a_step = True

        @step('another step')
        def another_step(step):
            my_world.another_step = True

        @step('steps afterwards')
        def steps_afterwards(step):
            my_world.steps_afterwards = True

        feature = load_feature('''
        Feature: run a feature
          Scenario: some steps
            Given there is a step
            And another step
            When I add something undefined
            Then steps afterwards are not run
        ''')
        my_world = World()
        my_world.there_is_a_step = False
        my_world.another_step = False
        my_world.steps_afterwards = False
        result = unittest.TestResult()

        feature.run(result)

        len(result.skipped) | should | be(1)
        result.skipped[0][1] | should | start_with('pending 1 step(s):')
        run = my_world.there_is_a_step, my_world.another_step, my_world.steps_afterwards
        run | should | be_equal_to((True, True, False))
示例#15
0
    def test_can_run_feature_with_scenario_outline_with_hashes(self):
        @step('a hash')
        def a_hash(step):
            my_world.run.append(list(step.hashes))

        feature = load_feature('''
        Feature: with multiline scenarnio
          Scenario Outline: follows
            Given a hash
              | <key>   | value         |
              | the     | <placeholder> |
          Examples:
            | <key> | <placeholder> |
            | key   | first         |
            | but   | second        |
        ''')
        my_world = World()
        my_world.run = []
        result = unittest.TestResult()

        feature.run(result)

        result.testsRun | should | be(2)
        result.wasSuccessful() | should | be(True)
        my_world.run | should | each_be_equal_to([
            [dict(key='the', value='first')],
            [dict(but='the', value='second')],
        ])
示例#16
0
 def test_creates_one_test_method_per_scenario(self):
     feature = loader.load_feature('''
     Feature: Load feature file
       Scenario: pending
       Scenario: second one
     ''')
     feature.countTestCases() |should| be(2)
示例#17
0
    def test_can_run_feature_with_scenario_outline_with_background(self):
        @step('a (.*)')
        def a_something(step, value):
            my_world.run.append(value)

        feature = load_feature('''
        Feature: with multiline scenarnio
          Background: with placeholder
            Given a <placeholder>
          Scenario Outline: follows
            And a step
          Examples:
            | <placeholder> |
            | first         |
            | second        |
        ''')
        my_world = World()
        my_world.run = []
        result = unittest.TestResult()

        feature.run(result)

        result.testsRun | should | be(2)
        result.wasSuccessful() | should | be(True)
        my_world.run | should | each_be_equal_to([
            'first',
            'step',
            'second',
            'step',
        ])
示例#18
0
 def test_stores_scenario_title_with_test_case(self):
     feature = loader.load_feature('''
     Feature: Load feature file
       Scenario: Has a nice Title
     ''')
     test_case = six.next(iter(feature))
     test_case.scenario.title | should | be_equal_to('Has a nice Title')
示例#19
0
 def test_stores_scenario_title_with_test_case(self):
     feature = loader.load_feature('''
     Feature: Load feature file
       Scenario: Has a nice Title
     ''')
     test_case = six.next(iter(feature))
     test_case.scenario.title |should| be_equal_to('Has a nice Title')
示例#20
0
 def test_loads_feature_with_description(self):
     feature = loader.load_feature('''
     Feature: Load feature file
         With description
       Scenario: pending
     ''')
     test_case = six.next(iter(feature))
     test_case.description |should| be_equal_to('With description')
示例#21
0
 def test_generates_test_names_from_scenario_title(self):
     feature = loader.load_feature('''
     Feature: Load feature file
       Scenario: Has a nice Title
     ''')
     test_case = six.next(iter(feature))
     scenario_method = test_case._testMethodName
     scenario_method |should| be_equal_to('test_Scenario_Has_a_nice_Title')
示例#22
0
 def test_loads_feature_with_description(self):
     feature = loader.load_feature('''
     Feature: Load feature file
         With description
       Scenario: pending
     ''')
     test_case = six.next(iter(feature))
     test_case.description | should | be_equal_to('With description')
示例#23
0
 def test_can_use_custom_scenario_class(self):
     class MyScenario(Scenario):
         pass
     feature = loader.load_feature('''
     Feature: Load feature file
       Scenario: pending
     ''', scenario_class=MyScenario)
     test_case = six.next(iter(feature))
     test_case.scenario |should| be_instance_of(MyScenario)
示例#24
0
 def test_marks_scenarios_without_steps_as_skipped(self):
     feature = loader.load_feature('''
     Feature: Load feature file
       Scenario: pending
     ''')
     result = unittest.TestResult()
     feature.run(result)
     len(result.skipped) |should| be(1)
     result.skipped[0][1] |should| be_equal_to('no steps defined')
示例#25
0
 def test_marks_scenarios_without_steps_as_skipped(self):
     feature = loader.load_feature('''
     Feature: Load feature file
       Scenario: pending
     ''')
     result = unittest.TestResult()
     feature.run(result)
     len(result.skipped) | should | be(1)
     result.skipped[0][1] | should | be_equal_to('no steps defined')
示例#26
0
 def test_generates_test_names_from_scenario_title(self):
     feature = loader.load_feature('''
     Feature: Load feature file
       Scenario: Has a nice Title
     ''')
     test_case = six.next(iter(feature))
     scenario_method = test_case._testMethodName
     scenario_method | should | be_equal_to(
         'test_Scenario_Has_a_nice_Title')
示例#27
0
 def test_reports_undefined_step_to_result_object(self):
     feature = load_feature('''
     Feature: report steps
       Scenario: with a step
         Given there is some undefined step
     ''')
     result = self.run_feature_with_result_step_handlers(feature, 'addStepUndefined')
     len(result.skipped) |should| be(1)
     result.wasSuccessful() |should| be(True)
     result.addStepUndefined.call_count |should| be(1)
示例#28
0
 def test_stores_tags_with_scenario(self):
     feature = loader.load_feature('''
     Feature: features can have tags
       @tag_1 @tag_2
       @tag_3
       Scenario: with tags
     ''')
     test_case = six.next(iter(feature))
     tags = get_tags(test_case)
     sorted(tags) |should| each_be_equal_to(['tag_1', 'tag_2', 'tag_3'])
示例#29
0
 def test_stores_tags_with_scenario(self):
     feature = loader.load_feature('''
     Feature: features can have tags
       @tag_1 @tag_2
       @tag_3
       Scenario: with tags
     ''')
     test_case = six.next(iter(feature))
     tags = get_tags(test_case)
     sorted(tags) | should | each_be_equal_to(['tag_1', 'tag_2', 'tag_3'])
示例#30
0
 def test_clears_tags_between_scenarios(self):
     feature = loader.load_feature('''
     Feature: scenarios can have tags
       @tag
       Scenario: a) with a tag
       Scenario: b) without tags
     ''')
     test_case = list(feature)[1]
     tags = get_tags(test_case)
     tags | should | be_empty
示例#31
0
 def test_clears_tags_between_scenarios(self):
     feature = loader.load_feature('''
     Feature: scenarios can have tags
       @tag
       Scenario: a) with a tag
       Scenario: b) without tags
     ''')
     test_case = list(feature)[1]
     tags = get_tags(test_case)
     tags |should| be_empty
示例#32
0
 def test_passes_on_steps_to_scenario_add_step_method(self):
     calls = []
     class MyScenario(Scenario):
         def add_step(self, *args, **kwargs):
             calls.append((args, kwargs))
     feature = loader.load_feature('''
     Feature: Load feature file
       Scenario: with step
         When step is defined
     ''', scenario_class=MyScenario)
     len(calls) |should| be(1)
示例#33
0
 def test_stores_background_tags_with_scenarios(self):
     feature = loader.load_feature('''
     Feature: background can have tags
       @background
       Background: with tag
       Scenario: without tags
       Scenario: also without tags
     ''')
     for test_case in feature:
         tags = get_tags(test_case)
         sorted(tags) |should| each_be_equal_to(['background'])
示例#34
0
    def test_can_use_custom_scenario_class(self):
        class MyScenario(Scenario):
            pass

        feature = loader.load_feature('''
        Feature: Load feature file
          Scenario: pending
        ''',
                                      scenario_class=MyScenario)
        test_case = six.next(iter(feature))
        test_case.scenario | should | be_instance_of(MyScenario)
示例#35
0
 def test_stores_background_tags_with_scenarios(self):
     feature = loader.load_feature('''
     Feature: background can have tags
       @background
       Background: with tag
       Scenario: without tags
       Scenario: also without tags
     ''')
     for test_case in feature:
         tags = get_tags(test_case)
         sorted(tags) | should | each_be_equal_to(['background'])
示例#36
0
 def test_reports_undefined_step_to_result_object(self):
     feature = load_feature('''
     Feature: report steps
       Scenario: with a step
         Given there is some undefined step
     ''')
     result = self.run_feature_with_result_step_handlers(
         feature, 'addStepUndefined')
     len(result.skipped) | should | be(1)
     result.wasSuccessful() | should | be(True)
     result.addStepUndefined.call_count | should | be(1)
示例#37
0
 def test_reports_steps_to_result_object(self):
     @step('some step')
     def some_step(step):
         pass
     feature = load_feature('''
     Feature: report steps
       Scenario: with a step
         Given there is some step
     ''')
     result = self.run_feature_with_result_step_handlers(feature)
     result.wasSuccessful() |should| be(True)
示例#38
0
 def test_reports_step_failure_to_result_object(self):
     @step('some failing step')
     def some_step(step):
         1 |should| be(2)
     feature = load_feature('''
     Feature: report steps
       Scenario: with a step
         Given there is some failing step
     ''')
     result = self.run_feature_with_result_step_handlers(feature, 'addStepFailure')
     result.wasSuccessful() |should| be(False)
     result.addStepFailure.call_count |should| be(1)
示例#39
0
    def test_reports_steps_to_result_object(self):
        @step('some step')
        def some_step(step):
            pass

        feature = load_feature('''
        Feature: report steps
          Scenario: with a step
            Given there is some step
        ''')
        result = self.run_feature_with_result_step_handlers(feature)
        result.wasSuccessful() | should | be(True)
示例#40
0
 def test_reports_step_error_to_result_object(self):
     @step('some error step')
     def some_step(step):
         raise Exception('hey')
     feature = load_feature('''
     Feature: report steps
       Scenario: with a step
         Given there is some error step
     ''')
     result = self.run_feature_with_result_step_handlers(feature, 'addStepError')
     result.wasSuccessful() |should| be(False)
     result.addStepError.call_count |should| be(1)
示例#41
0
 def test_mixes_tags_of_feature_and_scenario(self):
     feature = loader.load_feature('''
     @feature
     Feature: scenarios can have tags
       @scenario
       Scenario: with tag
       Scenario: without tags
     ''')
     test_cases = list(feature)
     tags = get_tags(test_cases[0])
     sorted(tags) | should | each_be_equal_to(['feature', 'scenario'])
     tags = get_tags(test_cases[1])
     sorted(tags) | should | each_be_equal_to(['feature'])
示例#42
0
 def test_mixes_tags_of_feature_and_scenario(self):
     feature = loader.load_feature('''
     @feature
     Feature: scenarios can have tags
       @scenario
       Scenario: with tag
       Scenario: without tags
     ''')
     test_cases = list(feature)
     tags = get_tags(test_cases[0])
     sorted(tags) |should| each_be_equal_to(['feature', 'scenario'])
     tags = get_tags(test_cases[1])
     sorted(tags) |should| each_be_equal_to(['feature'])
示例#43
0
 def test_stores_examples_tags_with_scenarios(self):
     feature = loader.load_feature('''
     Feature: examples can have tags
       Scenario Outline: with tag
       @example
       Examples:
       | {a} | {var} |
       | one | line  |
       | and | next  |
     ''')
     for test_case in feature:
         tags = get_tags(test_case)
         sorted(tags) |should| each_be_equal_to(['example'])
示例#44
0
 def test_stores_examples_tags_with_scenarios(self):
     feature = loader.load_feature('''
     Feature: examples can have tags
       Scenario Outline: with tag
       @example
       Examples:
       | {a} | {var} |
       | one | line  |
       | and | next  |
     ''')
     for test_case in feature:
         tags = get_tags(test_case)
         sorted(tags) | should | each_be_equal_to(['example'])
示例#45
0
    def test_reports_step_error_to_result_object(self):
        @step('some error step')
        def some_step(step):
            raise Exception('hey')

        feature = load_feature('''
        Feature: report steps
          Scenario: with a step
            Given there is some error step
        ''')
        result = self.run_feature_with_result_step_handlers(
            feature, 'addStepError')
        result.wasSuccessful() | should | be(False)
        result.addStepError.call_count | should | be(1)
示例#46
0
    def test_passes_on_steps_to_scenario_add_step_method(self):
        calls = []

        class MyScenario(Scenario):
            def add_step(self, *args, **kwargs):
                calls.append((args, kwargs))

        feature = loader.load_feature('''
        Feature: Load feature file
          Scenario: with step
            When step is defined
        ''',
                                      scenario_class=MyScenario)
        len(calls) | should | be(1)
示例#47
0
 def test_mixes_tags_of_background_and_scenario(self):
     feature = loader.load_feature('''
     Feature: background can have tags
       @background
       Background: with tag
       Scenario: a) without tags
       @scenario
       Scenario: b) with tag
     ''')
     test_cases = list(feature)
     tags = get_tags(test_cases[0])
     sorted(tags) |should| each_be_equal_to(['background'])
     tags = get_tags(test_cases[1])
     sorted(tags) |should| each_be_equal_to(['background', 'scenario'])
示例#48
0
    def test_reports_step_failure_to_result_object(self):
        @step('some failing step')
        def some_step(step):
            1 | should | be(2)

        feature = load_feature('''
        Feature: report steps
          Scenario: with a step
            Given there is some failing step
        ''')
        result = self.run_feature_with_result_step_handlers(
            feature, 'addStepFailure')
        result.wasSuccessful() | should | be(False)
        result.addStepFailure.call_count | should | be(1)
示例#49
0
 def test_mixes_tags_of_background_and_scenario(self):
     feature = loader.load_feature('''
     Feature: background can have tags
       @background
       Background: with tag
       Scenario: a) without tags
       @scenario
       Scenario: b) with tag
     ''')
     test_cases = list(feature)
     tags = get_tags(test_cases[0])
     sorted(tags) | should | each_be_equal_to(['background'])
     tags = get_tags(test_cases[1])
     sorted(tags) | should | each_be_equal_to(['background', 'scenario'])
示例#50
0
 def test_makes_itself_accessible_through_world(self):
     @step('feature attribute is set to "(.*)"')
     def feature_attribute(step, name):
         step.world.feature |should| be_instance_of(FeatureTest)
         step.world.feature.__class__.__name__ |should| be_equal_to(name)
     feature = load_feature('''
     Feature: accessible through world
       Scenario: test
         Then the feature attribute is set to "Feature_accessible_through_world"
     ''')
     result = unittest.TestResult()
     
     feature.run(result)
     
     result.testsRun |should| be(1)
     result.wasSuccessful() |should| be(True)
示例#51
0
 def test_passes_on_multiline_content_to_scenario_add_step_method(self):
     calls = []
     class MyScenario(Scenario):
         def add_step(self, *args, **kwargs):
             calls.append((args, kwargs))
     feature = loader.load_feature('''
     Feature: Load feature file
       Scenario: with step
         Given a multiline step
           """
           multiline content
           """
     ''', scenario_class=MyScenario)
     len(calls) |should| be(1)
     calls[0] |should| each_be_equal_to((
         ('Given', 'a multiline step'), dict(multilines=['multiline content\n'])
     ))
示例#52
0
    def test_makes_itself_accessible_through_world(self):
        @step('feature attribute is set to "(.*)"')
        def feature_attribute(step, name):
            step.world.feature | should | be_instance_of(FeatureTest)
            step.world.feature.__class__.__name__ | should | be_equal_to(name)

        feature = load_feature('''
        Feature: accessible through world
          Scenario: test
            Then the feature attribute is set to "Feature_accessible_through_world"
        ''')
        result = unittest.TestResult()

        feature.run(result)

        result.testsRun | should | be(1)
        result.wasSuccessful() | should | be(True)
示例#53
0
 def test_mixes_tags_of_outline_and_examples_group(self):
     feature = loader.load_feature('''
     Feature: background can have tags
       @outline
       Scenario Outline: with tag
       Examples: 1
       | {a} | {var} |
       | one | line  |
       @example
       Examples: 2
       | {a} | {var} |
       | and | next  |
     ''')
     test_cases = list(feature)
     tags = get_tags(test_cases[0])
     sorted(tags) |should| each_be_equal_to(['outline'])
     tags = get_tags(test_cases[1])
     sorted(tags) |should| each_be_equal_to(['example', 'outline'])
示例#54
0
 def test_mixes_tags_of_outline_and_examples_group(self):
     feature = loader.load_feature('''
     Feature: background can have tags
       @outline
       Scenario Outline: with tag
       Examples: 1
       | {a} | {var} |
       | one | line  |
       @example
       Examples: 2
       | {a} | {var} |
       | and | next  |
     ''')
     test_cases = list(feature)
     tags = get_tags(test_cases[0])
     sorted(tags) | should | each_be_equal_to(['outline'])
     tags = get_tags(test_cases[1])
     sorted(tags) | should | each_be_equal_to(['example', 'outline'])
示例#55
0
 def test_can_provide_custom_world_class(self):
     class MyWorld(World):
         pass
     class MyFeature(unittest.TestCase):
         World = MyWorld
     @step('world is an instance of the MyWorld class')
     def world_is_instance_of(step):
         step.world |should| be_instance_of(MyWorld)
     feature = load_feature('''
     Feature: custom world class
       Scenario: test
         Then world is an instance of the MyWorld class
     ''', test_case_class=MyFeature)
     result = unittest.TestResult()
     
     feature.run(result)
     
     result.testsRun |should| be(1)
     result.wasSuccessful() |should| be(True)
示例#56
0
    def test_passes_on_multiline_content_to_scenario_add_step_method(self):
        calls = []

        class MyScenario(Scenario):
            def add_step(self, *args, **kwargs):
                calls.append((args, kwargs))

        feature = loader.load_feature('''
        Feature: Load feature file
          Scenario: with step
            Given a multiline step
              """
              multiline content
              """
        ''',
                                      scenario_class=MyScenario)
        len(calls) | should | be(1)
        calls[0] | should | each_be_equal_to(
            (('Given', 'a multiline step'),
             dict(multilines=['multiline content\n'])))
示例#57
0
 def test_clears_world_between_scenarios(self):
     @step('set a world var')
     def set_world(step):
         step.world.var = 'set'
     @step('check that world var')
     def check_var(step):
         getattr(step.world, 'var', None) |should| be(None)
     feature = load_feature('''
     Feature: clears world between scenarios
       Scenario: first
         When I set a world var
       Scenario: second
         Then I check that world var
     ''')
     result = unittest.TestResult()
     
     feature.run(result)
     
     result.testsRun |should| be(2)
     result.wasSuccessful() |should| be(True)
示例#58
0
 def test_passes_on_hashes_to_scenario_add_step_method(self):
     calls = []
     class MyScenario(Scenario):
         def add_step(self, *args, **kwargs):
             calls.append((args, kwargs))
     feature = loader.load_feature('''
     Feature: with multiline scenarnio
       Scenario: with multiline step
         Given a step with hashes
           | first   | second    | third     |
           | first 1 | second 1  | third 1   |
           | first 2 | second 2  | third 2   |
     ''', scenario_class=MyScenario)
     len(calls) |should| be(1)
     args, kwargs = calls[0]
     args |should| be_equal_to(('Given', 'a step with hashes'))
     'hashes' |should| be_in(kwargs)
     list(kwargs['hashes']) |should| each_be_equal_to([
         dict(first='first 1', second='second 1', third='third 1'),
         dict(first='first 2', second='second 2', third='third 2'),
     ])
示例#59
0
    def test_can_run_feature_with_multiline_step(self):
        @step('multiline step')
        def multiline_step(step):
            my_world.multiline = step.multiline

        feature = load_feature('''
        Feature: with multiline scenarnio
          Scenario: with multiline step
            Given a multiline step
              """
              multiline content
              """
        ''')
        my_world = World()
        my_world.multiline = None
        result = unittest.TestResult()

        feature.run(result)

        result.testsRun | should | be(1)
        result.wasSuccessful() | should | be(True)
        my_world.multiline | should | be_equal_to('multiline content\n')
示例#60
0
    def test_clears_world_between_scenarios(self):
        @step('set a world var')
        def set_world(step):
            step.world.var = 'set'

        @step('check that world var')
        def check_var(step):
            getattr(step.world, 'var', None) | should | be(None)

        feature = load_feature('''
        Feature: clears world between scenarios
          Scenario: first
            When I set a world var
          Scenario: second
            Then I check that world var
        ''')
        result = unittest.TestResult()

        feature.run(result)

        result.testsRun | should | be(2)
        result.wasSuccessful() | should | be(True)