You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

world.feature 4.7 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. Feature: World
  2. In order to isolate each test scenario, the steps definitions belonging to the
  3. same scenario will run in a isolated context, called 'world'. A world also
  4. contains the helpers methods that will be used in the step definitions.
  5. It is possible to add helpers methods to a world in three different ways:
  6. 1. Passing a module. In this case its methods will be added directly to the
  7. world and be usable in the step definitions.
  8. 2. Passing a block, where the return value is the world object.
  9. 3. Passing a hash, where the keys are namespaces and the values are
  10. modules. In this case, the methods of each module will be accessible using
  11. the key as prefix.
  12. Scenario: A world is extended using a module
  13. Given a file named "features/support/helpers.rb" with:
  14. """
  15. module Helpers
  16. def helper_method
  17. 42
  18. end
  19. end
  20. World(Helpers)
  21. """
  22. And a file named "features/step_definitions/step.rb" with:
  23. """
  24. Then /^the helper method is called$/ do
  25. expect(helper_method).to eql(42)
  26. end
  27. """
  28. And a file named "features/f.feature" with:
  29. """
  30. Feature: Calling a method
  31. Scenario: I call a method without namespaces
  32. Then the helper method is called
  33. """
  34. When I run `cucumber features/f.feature`
  35. Then it should pass
  36. Scenario: A world is created using a block
  37. Given a file named "features/support/helpers.rb" with:
  38. """
  39. class Helper
  40. def helper_method
  41. 42
  42. end
  43. end
  44. World do
  45. Helper.new
  46. end
  47. """
  48. And a file named "features/step_definitions/step.rb" with:
  49. """
  50. Then /^the helper method is called$/ do
  51. expect(helper_method).to eql(42)
  52. end
  53. """
  54. And a file named "features/f.feature" with:
  55. """
  56. Feature: Calling a method
  57. Scenario: I call a method from a namespace
  58. Then the helper method is called
  59. """
  60. When I run `cucumber features/f.feature`
  61. Then it should pass
  62. Scenario: A world is extended using a module with namespace
  63. Given a file named "features/support/helpers.rb" with:
  64. """
  65. module Helpers
  66. def helper_method
  67. 42
  68. end
  69. end
  70. World(my_namespace: Helpers)
  71. """
  72. And a file named "features/step_definitions/step.rb" with:
  73. """
  74. Then /^the helper method is called$/ do
  75. expect(my_namespace.helper_method).to eql(42)
  76. end
  77. """
  78. And a file named "features/f.feature" with:
  79. """
  80. Feature: Calling a method
  81. Scenario: I call a method from a namespace
  82. Then the helper method is called
  83. """
  84. When I run `cucumber features/f.feature`
  85. Then it should pass
  86. Scenario: A world is existing over multiple scenarios
  87. Given a file named "features/support/helpers.rb" with:
  88. """
  89. module Helpers
  90. def helper_method
  91. 42
  92. end
  93. end
  94. World(my_namespace: Helpers)
  95. """
  96. And a file named "features/step_definitions/step.rb" with:
  97. """
  98. Then /^my_namespace is not nil$/ do
  99. expect(my_namespace).not_to be_nil
  100. end
  101. Then /^the helper method is called$/ do
  102. expect(my_namespace.helper_method).to eql(42)
  103. end
  104. """
  105. And a file named "features/f.feature" with:
  106. """
  107. Feature: Calling a method
  108. Scenario: The namespace exists
  109. Then my_namespace is not nil
  110. And the helper method is called
  111. Scenario: The namespace still exists
  112. Then my_namespace is not nil
  113. And the helper method is called
  114. """
  115. When I run `cucumber features/f.feature`
  116. Then it should pass with:
  117. """
  118. 2 scenarios (2 passed)
  119. """
  120. Scenario: A world is extended using multiple modules with different namespaces
  121. Given a file named "features/support/helpers.rb" with:
  122. """
  123. module ModuleOne
  124. def forty_one
  125. 41
  126. end
  127. end
  128. module ModuleTwo
  129. def forty_two
  130. 42
  131. end
  132. end
  133. World(module_one: ModuleOne, module_two: ModuleTwo)
  134. """
  135. And a file named "features/step_definitions/step.rb" with:
  136. """
  137. Then /^the helper method is called$/ do
  138. expect(module_one.forty_one).to eql(41)
  139. expect(module_two.forty_two).to eql(42)
  140. end
  141. """
  142. And a file named "features/f.feature" with:
  143. """
  144. Feature: Calling a method
  145. Scenario: I call a method from two namespaces
  146. Then the helper method is called
  147. """
  148. When I run `cucumber features/f.feature`
  149. Then it should pass

No Description

Contributors (1)