File: step.execute_steps.feature

package info (click to toggle)
behave 1.2.6-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,160 kB
  • sloc: python: 19,857; makefile: 137; sh: 18
file content (59 lines) | stat: -rw-r--r-- 1,919 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Feature: Execute Steps within a Step Function (Nested Steps)

    As a tester
    I want to reuse existing steps and call several ones within another step
    So that I can comply with the the DRY principle.

  Scenario: Execute a number of simple steps (GOOD CASE)
    Given a new working directory
    And   a file named "features/steps/steps.py" with:
      """
      from behave import given, when, then

      @given(u'I go to the supermarket')
      def step_given_I_go_to_the_supermarket(context):
          context.shopping_cart = {}

      @when(u'I buy {amount:n} {item:w}')
      def step_when_I_buy(context, amount, item):
          assert amount >= 0
          if not item in context.shopping_cart:
              context.shopping_cart[item] = 0
          context.shopping_cart[item] += amount

      # -- HERE: Is the interesting functionality.
      @when(u'I buy the usual things')
      def step_when_I_buy_the_usual_things(context):
          context.execute_steps(u'''
              When I buy 2 apples
              And  I buy 3 bananas
          ''')

      @then(u'I have {amount:n} {item:w}')
      def step_then_I_have(context, amount, item):
          actual = context.shopping_cart.get(item, 0)
          assert amount == actual
      """
    And   a file named "features/use_nested_steps.feature" with:
      """
      Feature:
        Scenario:
          Given I go to the supermarket
          When  I buy the usual things
          Then  I have 2 apples
          And   I have 3 bananas
      """
    When I run "behave -f plain features/use_nested_steps.feature"
    Then it should pass with:
      """
      1 feature passed, 0 failed, 0 skipped
      1 scenario passed, 0 failed, 0 skipped
      4 steps passed, 0 failed, 0 skipped, 0 undefined
      """

  @not_implemented
  Scenario: A Nested Step Fails with Assert

  @not_implemented
  Scenario: A Nested Step Fails with Exception