File: test.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 (36 lines) | stat: -rw-r--r-- 700 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
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

require "stringio"

require_relative "../prompt"

module TTY
  # Used for initializing test cases
  class Prompt
    module StringIOExtensions
      def wait_readable(*)
        true
      end

      def ioctl(*)
        80
      end
    end

    class Test < TTY::Prompt
      def initialize(**options)
        @input = StringIO.new
        @input.extend(StringIOExtensions)
        @output = StringIO.new

        options.merge!({
          input: @input,
          output: @output,
          env: { "TTY_TEST" => true },
          enable_color: options.fetch(:enable_color, true)
        })
        super(**options)
      end
    end # Test
  end # Prompt
end # TTY