Class: Clack::Testing::PromptDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/clack/testing.rb

Overview

DSL for building a key sequence to feed to a prompt.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePromptDriver

Returns a new instance of PromptDriver.



61
62
63
# File 'lib/clack/testing.rb', line 61

def initialize
  @keys = []
end

Instance Attribute Details

#keysArray<String> (readonly)

Returns accumulated key sequence.

Returns:

  • (Array<String>)

    accumulated key sequence



59
60
61
# File 'lib/clack/testing.rb', line 59

def keys
  @keys
end

Instance Method Details

#backspaceObject

Press Backspace.



96
# File 'lib/clack/testing.rb', line 96

def backspace = @keys << KEYS[:backspace]

#cancelObject

Press Escape to cancel.



75
# File 'lib/clack/testing.rb', line 75

def cancel = @keys << KEYS[:escape]

#ctrl_dObject

Press Ctrl+D (submit multiline text).



99
# File 'lib/clack/testing.rb', line 99

def ctrl_d = @keys << KEYS[:ctrl_d]

#downObject

Press arrow down.



78
# File 'lib/clack/testing.rb', line 78

def down = @keys << KEYS[:down]

#key(key) ⇒ Object

Press an arbitrary key by name or character.

Parameters:

  • key (Symbol, String)

    key name (e.g. :escape) or raw character



103
104
105
# File 'lib/clack/testing.rb', line 103

def key(key)
  @keys << (key.is_a?(Symbol) ? KEYS.fetch(key) : key)
end

#leftObject

Press arrow left.



84
# File 'lib/clack/testing.rb', line 84

def left = @keys << KEYS[:left]

#rightObject

Press arrow right.



87
# File 'lib/clack/testing.rb', line 87

def right = @keys << KEYS[:right]

#submitObject

Press Enter to submit.



72
# File 'lib/clack/testing.rb', line 72

def submit = @keys << KEYS[:enter]

#tabObject

Press Tab.



93
# File 'lib/clack/testing.rb', line 93

def tab = @keys << KEYS[:tab]

#toggleObject

Press Space (toggle selection in multiselect).



90
# File 'lib/clack/testing.rb', line 90

def toggle = @keys << KEYS[:space]

#type(text) ⇒ Object

Type a string of text character by character.

Parameters:

  • text (String)

    text to type



67
68
69
# File 'lib/clack/testing.rb', line 67

def type(text)
  text.each_char { |char| @keys << char }
end

#upObject

Press arrow up.



81
# File 'lib/clack/testing.rb', line 81

def up = @keys << KEYS[:up]