File: convert_array_spec.rb

package info (click to toggle)
ruby-tty-prompt 0.23.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,452 kB
  • sloc: ruby: 8,847; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 735 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

RSpec.describe TTY::Prompt::Question, "convert to array" do
  subject(:prompt) { TTY::Prompt::Test.new }

  it "converts answer to an array" do
    prompt.input << "a,b,c"
    prompt.input.rewind
    answer = prompt.ask("Tags?", convert: :list)
    expect(answer).to eq(%w[a b c])
  end

  it "converts answer to an array of integers" do
    prompt.input << "1,2,3"
    prompt.input.rewind
    answer = prompt.ask("Numbers?", convert: :integers)
    expect(answer).to eq([1, 2, 3])
  end

  it "converts answer to an array of booleans" do
    prompt.input << "t,f,t"
    prompt.input.rewind
    answer = prompt.ask("Numbers?", convert: :bool_list)
    expect(answer).to eq([true, false, true])
  end
end