Beispiel #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')],
     ])
Beispiel #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',
     ])
Beispiel #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',
     ])
Beispiel #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))
Beispiel #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])
Beispiel #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'),
     ])
Beispiel #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)
Beispiel #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'),
     ])
Beispiel #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'),
        ])
Beispiel #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'),
        ])
Beispiel #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])
Beispiel #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)
Beispiel #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',
        ])
Beispiel #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))
Beispiel #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')],
        ])
Beispiel #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)
Beispiel #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',
        ])
Beispiel #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')
Beispiel #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')
Beispiel #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')
Beispiel #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')
Beispiel #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')
Beispiel #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)
Beispiel #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')
Beispiel #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')
Beispiel #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')
Beispiel #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)
Beispiel #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'])
Beispiel #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'])
Beispiel #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
Beispiel #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
Beispiel #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)
Beispiel #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'])
Beispiel #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)
Beispiel #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'])
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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'])
Beispiel #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'])
Beispiel #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'])
Beispiel #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'])
Beispiel #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)
Beispiel #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)
Beispiel #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'])
Beispiel #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)
Beispiel #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'])
Beispiel #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)
Beispiel #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'])
     ))
Beispiel #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)
Beispiel #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'])
Beispiel #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'])
Beispiel #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)
Beispiel #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'])))
Beispiel #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)
Beispiel #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'),
     ])
Beispiel #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')
Beispiel #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)