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.

banner_spec.rb 3.0 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. require 'cucumber/term/banner'
  2. describe Cucumber::Term::Banner do
  3. include Cucumber::Term::Banner
  4. context '.display_banner' do
  5. let(:io) { StringIO.new }
  6. context 'when a string is provided' do
  7. it 'outputs a nice banner to IO surrounded by a bold green border' do
  8. display_banner('Oh, this is a banner', io)
  9. io.rewind
  10. expect(io.read).to eq(<<~BANNER)
  11. \e[1m\e[32m┌──────────────────────┐\e[0m\e[0m
  12. \e[1m\e[32m│\e[0m\e[0m Oh, this is a banner \e[1m\e[32m│\e[0m\e[0m
  13. \e[1m\e[32m└──────────────────────┘\e[0m\e[0m
  14. BANNER
  15. end
  16. it 'supports multi-lines' do
  17. display_banner("Oh, this is a banner\nwhich spreads on\nmultiple lines", io, [])
  18. io.rewind
  19. expect(io.read).to eq(<<~BANNER)
  20. ┌──────────────────────┐
  21. │ Oh, this is a banner │
  22. │ which spreads on │
  23. │ multiple lines │
  24. └──────────────────────┘
  25. BANNER
  26. end
  27. end
  28. context 'when an array is provided' do
  29. it 'outputs a nice banner with each item on a line' do
  30. display_banner(
  31. [
  32. 'Oh, this is a banner',
  33. 'It has two lines'
  34. ],
  35. io,
  36. []
  37. )
  38. io.rewind
  39. expect(io.read).to eq(<<~BANNER)
  40. ┌──────────────────────┐
  41. │ Oh, this is a banner │
  42. │ It has two lines │
  43. └──────────────────────┘
  44. BANNER
  45. end
  46. context 'when specifying spans' do
  47. it 'can render special characters inside the lines' do
  48. display_banner(
  49. [
  50. 'Oh, this is a banner',
  51. ['It has ', ['two', :bold, :blue], ' lines']
  52. ],
  53. io,
  54. []
  55. )
  56. io.rewind
  57. expect(io.read).to eq(<<~BANNER)
  58. ┌──────────────────────┐
  59. │ Oh, this is a banner │
  60. │ It has \e[34m\e[1mtwo\e[0m\e[0m lines │
  61. └──────────────────────┘
  62. BANNER
  63. end
  64. end
  65. end
  66. context 'with custom borders' do
  67. it 'process the border with the provided attributes' do
  68. display_banner('this is a banner', io, %i[bold blue])
  69. io.rewind
  70. expect(io.read).to eq(<<~BANNER)
  71. \e[34m\e[1m┌──────────────────┐\e[0m\e[0m
  72. \e[34m\e[1m│\e[0m\e[0m this is a banner \e[34m\e[1m│\e[0m\e[0m
  73. \e[34m\e[1m└──────────────────┘\e[0m\e[0m
  74. BANNER
  75. end
  76. end
  77. end
  78. end

No Description

Contributors (1)