Exemplo n.º 1
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))
Exemplo n.º 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',
        ])
Exemplo n.º 3
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'),
        ])
Exemplo n.º 4
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'),
        ])
Exemplo n.º 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])
Exemplo n.º 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'),
     ])
Exemplo n.º 7
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',
        ])
Exemplo n.º 8
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')],
     ])
Exemplo n.º 9
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',
     ])
Exemplo n.º 10
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',
     ])
Exemplo n.º 11
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))
Exemplo n.º 12
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'),
     ])
Exemplo n.º 13
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')],
        ])
Exemplo n.º 14
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])
Exemplo n.º 15
0
 def test_can_run_if_defined(self):
     @step('there is a step')
     def there_is_a_step(step):
         world.run_count += 1
     step_ = Step('Given', 'there is a step')
     world = World()
     world.run_count = 0
     step_.run()
     world.run_count |should| be(1)
Exemplo n.º 16
0
 def test_passes_capture_groups_to_definition(self):
     @step('this is (.*)')
     def this_is_captured(step, capture):
         my_world.capture = capture
     step_ = Step('Given', 'this is captured')
     my_world = World()
     my_world.capture = None
     step_.run()
     my_world.capture |should| be_equal_to('captured')
Exemplo n.º 17
0
    def test_passes_capture_groups_to_definition(self):
        @step('this is (.*)')
        def this_is_captured(step, capture):
            my_world.capture = capture

        step_ = Step('Given', 'this is captured')
        my_world = World()
        my_world.capture = None
        step_.run()
        my_world.capture | should | be_equal_to('captured')
Exemplo n.º 18
0
    def test_can_run_if_defined(self):
        @step('there is a step')
        def there_is_a_step(step):
            world.run_count += 1

        step_ = Step('Given', 'there is a step')
        world = World()
        world.run_count = 0
        step_.run()
        world.run_count | should | be(1)
Exemplo n.º 19
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')
Exemplo n.º 20
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')