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.

printing_messages.feature 3.8 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. Feature: Pretty formatter - Printing messages
  2. When you want to print to Cucumber's output, call `log` from
  3. a step definition. Cucumber will grab the output and print it via
  4. the formatter that you're using.
  5. Your message will be printed out after the step has run.
  6. Background:
  7. Given the standard step definitions
  8. And a file named "features/step_definitions/log_steps.rb" with:
  9. """
  10. Given /^I use log with text "(.*)"$/ do |ann|
  11. log(ann)
  12. end
  13. Given /^I use multiple logs$/ do
  14. log("Multiple")
  15. log("Announce\nMe")
  16. end
  17. Given /^I use message (.+) in line (.+) (?:with result (.+))$/ do |ann, line, result|
  18. log("Last message") if line == "3"
  19. log("Line: #{line}: #{ann}")
  20. fail if result =~ /fail/i
  21. end
  22. Given /^I use log and step fails$/ do
  23. log("Announce with fail")
  24. fail
  25. end
  26. Given /^I log the world$/ do
  27. log(self.to_s)
  28. end
  29. """
  30. And a file named "features/f.feature" with:
  31. """
  32. Feature:
  33. Scenario:
  34. Given I use log with text "Ann"
  35. And this step passes
  36. Scenario:
  37. Given I use multiple logs
  38. And this step passes
  39. Scenario Outline:
  40. Given I use message <ann> in line <line>
  41. Examples:
  42. | line | ann |
  43. | 1 | anno1 |
  44. | 2 | anno2 |
  45. | 3 | anno3 |
  46. Scenario:
  47. Given I use log and step fails
  48. And this step passes
  49. Scenario Outline:
  50. Given I use message <ann> in line <line> with result <result>
  51. Examples:
  52. | line | ann | result |
  53. | 1 | anno1 | fail |
  54. | 2 | anno2 | pass |
  55. """
  56. And a file named "features/log_world.feature" with:
  57. """
  58. Feature: log_world
  59. Scenario: log_world
  60. Given I log the world
  61. """
  62. Scenario: Delayed messages feature
  63. When I run `cucumber --quiet --format pretty features/f.feature`
  64. Then the stderr should not contain anything
  65. And the output should contain:
  66. """
  67. Feature:
  68. Scenario:
  69. Given I use log with text "Ann"
  70. Ann
  71. And this step passes
  72. Scenario:
  73. Given I use multiple logs
  74. Multiple
  75. Announce
  76. Me
  77. And this step passes
  78. Scenario Outline:
  79. Given I use message <ann> in line <line>
  80. Examples:
  81. | line | ann |
  82. | 1 | anno1 |
  83. | 2 | anno2 |
  84. | 3 | anno3 |
  85. Scenario:
  86. Given I use log and step fails
  87. Announce with fail
  88. (RuntimeError)
  89. ./features/step_definitions/log_steps.rb:18:in `/^I use log and step fails$/'
  90. features/f.feature:21:in `I use log and step fails'
  91. And this step passes
  92. Scenario Outline:
  93. Given I use message <ann> in line <line> with result <result>
  94. Examples:
  95. | line | ann | result |
  96. | 1 | anno1 | fail | Line: 1: anno1
  97. (RuntimeError)
  98. ./features/step_definitions/log_steps.rb:13:in `/^I use message (.+) in line (.+) (?:with result (.+))$/'
  99. features/f.feature:29:25:in `I use message anno1 in line 1 with result fail'
  100. | 2 | anno2 | pass | Line: 2: anno2
  101. """
  102. Scenario: Non-delayed messages feature (progress formatter)
  103. When I run `cucumber --format progress features/f.feature`
  104. Then the output should contain:
  105. """
  106. Ann
  107. ..
  108. Multiple
  109. Announce
  110. Me
  111. ..UUU
  112. Announce with fail
  113. F-
  114. Line: 1: anno1
  115. F
  116. Line: 2: anno2
  117. .
  118. """

No Description

Contributors (1)