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.

proto_world_spec.rb 5.0 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # frozen_string_literal: true
  2. require 'spec_helper'
  3. require 'cucumber/formatter/spec_helper'
  4. require 'cucumber/formatter/pretty'
  5. module Cucumber
  6. module Glue
  7. describe ProtoWorld do
  8. let(:runtime) { double('runtime') }
  9. let(:language) { double('language') }
  10. let(:world) { Object.new.extend(ProtoWorld.for(runtime, language)) }
  11. describe '#table' do
  12. it 'produces Ast::Table by #table' do
  13. expect(world.table(%(
  14. | account | description | amount |
  15. | INT-100 | Taxi | 114 |
  16. | CUC-101 | Peeler | 22 |
  17. ))).to be_kind_of(MultilineArgument::DataTable)
  18. end
  19. end
  20. describe 'Handling logs in step definitions' do
  21. extend Cucumber::Formatter::SpecHelperDsl
  22. include Cucumber::Formatter::SpecHelper
  23. before(:each) do
  24. Cucumber::Term::ANSIColor.coloring = false
  25. @out = StringIO.new
  26. @formatter = Cucumber::Formatter::Pretty.new(actual_runtime.configuration.with_options(out_stream: @out, source: false))
  27. run_defined_feature
  28. end
  29. describe 'when modifying the printed variable after the call to log' do
  30. define_feature <<-FEATURE
  31. Feature: Banana party
  32. Scenario: Monkey eats banana
  33. When log is called twice for the same variable
  34. FEATURE
  35. define_steps do
  36. When(/^log is called twice for the same variable$/) do
  37. foo = String.new('a')
  38. log foo
  39. foo.upcase!
  40. log foo
  41. end
  42. end
  43. it 'prints the variable value at the time puts was called' do
  44. expect(@out.string).to include <<OUTPUT
  45. When log is called twice for the same variable
  46. a
  47. A
  48. OUTPUT
  49. end
  50. end
  51. describe 'when logging an object' do
  52. define_feature <<-FEATURE
  53. Feature: Banana party
  54. Scenario: Monkey eats banana
  55. When an object is logged
  56. FEATURE
  57. define_steps do
  58. When('an object is logged') do
  59. log(a: 1, b: 2, c: 3)
  60. end
  61. end
  62. it 'attached the styring version on the object' do
  63. expect(@out.string).to include '{:a=>1, :b=>2, :c=>3}'
  64. end
  65. end
  66. describe 'when logging multiple items on one call' do
  67. define_feature <<-FEATURE
  68. Feature: Banana party
  69. Scenario: Monkey eats banana
  70. When monkey eats banana
  71. FEATURE
  72. define_steps do
  73. When('{word} {word} {word}') do |subject, verb, complement|
  74. log "subject: #{subject}", "verb: #{verb}", "complement: #{complement}", subject: subject, verb: verb, complement: complement
  75. end
  76. end
  77. it 'logs each parameter independently' do
  78. expect(@out.string).to include [
  79. ' subject: monkey',
  80. ' verb: eats',
  81. ' complement: banana',
  82. ' {:subject=>"monkey", :verb=>"eats", :complement=>"banana"}'
  83. ].join("\n")
  84. end
  85. end
  86. describe 'when modifying the printed variable after the call to log' do
  87. define_feature <<-FEATURE
  88. Feature: Banana party
  89. Scenario: Monkey eats banana
  90. When puts is called twice for the same variable
  91. FEATURE
  92. define_steps do
  93. When(/^puts is called twice for the same variable$/) do
  94. foo = String.new('a')
  95. log foo
  96. foo.upcase!
  97. log foo
  98. end
  99. end
  100. it 'prints the variable value at the time puts was called' do
  101. expect(@out.string).to include <<OUTPUT
  102. When puts is called twice for the same variable
  103. a
  104. A
  105. OUTPUT
  106. end
  107. end
  108. end
  109. describe 'Handling attachments in step definitions' do
  110. extend Cucumber::Formatter::SpecHelperDsl
  111. include Cucumber::Formatter::SpecHelper
  112. before(:each) do
  113. Cucumber::Term::ANSIColor.coloring = false
  114. @out = StringIO.new
  115. @formatter = Cucumber::Formatter::Pretty.new(actual_runtime.configuration.with_options(out_stream: @out, source: false))
  116. run_defined_feature
  117. end
  118. describe 'when attaching data with null byte' do
  119. define_feature <<-FEATURE
  120. Feature: Banana party
  121. Scenario: Monkey eats banana
  122. When some data is attached
  123. FEATURE
  124. define_steps do
  125. When('some data is attached') do
  126. attach("'\x00'attachement", 'text/x.cucumber.log+plain')
  127. end
  128. end
  129. it 'does not report an error' do
  130. expect(@out.string).not_to include 'Error'
  131. end
  132. it 'properly attaches the data' do
  133. expect(@out.string).to include "'\x00'attachement"
  134. end
  135. end
  136. end
  137. end
  138. end
  139. end

No Description

Contributors (1)