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.

snippets.feature 3.7 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. Feature: Snippets
  2. Cucumber helpfully prints out any undefined step definitions as a code
  3. snippet suggestion, which you can then paste into a step definitions
  4. file of your choosing.
  5. Scenario: Snippet for undefined step with a Doc String
  6. Given a file named "features/undefined_steps.feature" with:
  7. """
  8. Feature:
  9. Scenario: Doc String
  10. Given a Doc String
  11. \"\"\"
  12. example with <html> entities
  13. \"\"\"
  14. When 1 simple when step
  15. And another "when" step
  16. Then a simple then step
  17. """
  18. When I run `cucumber features/undefined_steps.feature -s`
  19. Then the output should contain:
  20. """
  21. Given('a Doc String') do |doc_string|
  22. pending # Write code here that turns the phrase above into concrete actions
  23. end
  24. When('{int} simple when step') do |int|
  25. # When('{float} simple when step') do |float|
  26. pending # Write code here that turns the phrase above into concrete actions
  27. end
  28. When('another {string} step') do |string|
  29. pending # Write code here that turns the phrase above into concrete actions
  30. end
  31. Then('a simple then step') do
  32. pending # Write code here that turns the phrase above into concrete actions
  33. end
  34. """
  35. Scenario: Snippet for undefined step with a step table
  36. Given a file named "features/undefined_steps.feature" with:
  37. """
  38. Feature:
  39. Scenario: table
  40. Given a table
  41. | table |
  42. |example|
  43. """
  44. When I run `cucumber features/undefined_steps.feature -s`
  45. Then the output should contain:
  46. """
  47. Given('a table') do |table|
  48. # table is a Cucumber::MultilineArgument::DataTable
  49. pending # Write code here that turns the phrase above into concrete actions
  50. end
  51. """
  52. Scenario: Snippet for undefined step with multiple params
  53. Given a file named "features/undefined_steps.feature" with:
  54. """
  55. Feature:
  56. Scenario: Send emails
  57. Given I send an email entitled "Hi from Cucumber" to john@example.org with content:
  58. \"\"\"
  59. Hello there!
  60. \"\"\"
  61. """
  62. And a file named "features/support/parameter_types.rb" with:
  63. """
  64. ParameterType(
  65. name: 'email_address',
  66. regexp: /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/,
  67. transformer: -> (email) { email }
  68. )
  69. """
  70. When I run `cucumber features/undefined_steps.feature -s`
  71. Then the output should contain:
  72. """
  73. Given('I send an email entitled {string} to {email_address} with content:') do |string, email_address, doc_string|
  74. pending # Write code here that turns the phrase above into concrete actions
  75. end
  76. """
  77. Scenario: Snippet for step definition with undefined parameter type
  78. Given a file named "features/undefined_parameter_type.feature" with:
  79. """
  80. Feature:
  81. Scenario: Delayed flight
  82. Given leg LHR-OSL is cancelled
  83. """
  84. And a file named "features/steps.rb" with:
  85. """
  86. Given('leg {flight-leg} is cancelled') do |flight|
  87. log flight.to_s
  88. end
  89. """
  90. When I run `cucumber features/undefined_parameter_type.feature -s`
  91. Then the output should contain:
  92. """
  93. The parameter flight-leg is not defined. You can define a new one with:
  94. ParameterType(
  95. name: 'flight-leg',
  96. regexp: /some regexp here/,
  97. type: FlightLeg,
  98. # The transformer takes as many arguments as there are capture groups in the regexp,
  99. # or just one if there are none.
  100. transformer: ->(s) { FlightLeg.new(s) }
  101. )
  102. """

No Description

Contributors (1)