ttytest2 0.9.6 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 196acc1f485c7ad416fbdbe07c94f0829bfb53a57c852a85bf79d72655f4debb
4
- data.tar.gz: a2afc1f836dff32a2e2aa53a90137ce9bd768a20907855defae05da66af821e4
3
+ metadata.gz: ad00f4819b188050fb5882adeac6578525082d1740c3b17a4320ec56b3f68b51
4
+ data.tar.gz: bf5dcc48c03fa7ab3cbf0c4e5780e479482f68fc19c149accd4e46c39d655cb2
5
5
  SHA512:
6
- metadata.gz: 762f9246cadb92d30ef2d8535b135cb9d72270d8e24bc100c8d18e18ecdd949e35560a7ff6fdc3b413a7dffbacbef56cf712c0b459b4cc3f8f7797dbfeca61d3
7
- data.tar.gz: 2e099fda420602c981073d9cb39d9be307e261086ac8682ec4b213b6a061eded99a9ccff73df9e6c16a9157676fc4dea03a33d834d643fcfdf63631090807156
6
+ metadata.gz: 8357acea4da5433d9131d72ab29c21a73c38f7c53140a0eff2a0ece7393eb47b2fb749b2539dee905bd4c3baa9f7aa2e502921a33a777b060cfe32568752933d
7
+ data.tar.gz: c4ecdc9782d7c1e0633dc5b3ff4579bcbac288e6cc4628a9e496ea91fe0777ab2e028896db6f398e1f2e9b66d050b2e9a04260da636dc2a1a2c7693640555ed0
data/README.md CHANGED
@@ -57,6 +57,13 @@ $
57
57
  TTY
58
58
  @tty.assert_cursor_position(x: 2, y: 2)
59
59
 
60
+ @tty.assert_contents_at(0, 0, '$ echo "Hello, world"')
61
+
62
+ @tty.assert_row_starts_with(0, '$ echo')
63
+ @tty.assert_row_ends_with(0, '"Hello, world"')
64
+ @tty.assert_row_starts_with(1, 'Hello')
65
+ @tty.assert_row_ends_with(1, ', world')
66
+
60
67
  @tty.print_rows # => ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ...]
61
68
 
62
69
  @tty.print # prints out the contents of the terminal
@@ -79,16 +86,15 @@ require 'ttytest'
79
86
 
80
87
  @tty.send_keys_one_at_a_time('ls')
81
88
  @tty.assert_row_ends_with(0, 'ls')
82
- @tty.send_keys(%(\n)) # make sure to use send_keys for 'multi-character' characters like \n, \r, \t, etc.
89
+ @tty.send_newline # builtins for common outputs line newline
83
90
 
84
91
  @tty.send_keys_one_at_a_time('ps')
85
92
  @tty.assert_row_ends_with(1, 'ps')
86
93
  @tty.send_keys(TTYtest:NEWLINE) # can use constants instead
87
94
 
88
-
89
95
  @tty.assert_row_starts_with(2, ENV['USER'])
90
96
  @tty.assert_row_ends_with(2, '$')
91
- @tty.send_newline # an alternative to the 2 above methods to send \n to the terminal
97
+ @tty.send_newline
92
98
 
93
99
  puts "\n#{@tty.capture}" # prints out the contents of the terminal, equivalent to @tty.print
94
100
  ```
@@ -108,6 +114,7 @@ Available assertions:
108
114
  * `assert_cursor_visible`
109
115
  * `assert_cursor_hidden`
110
116
  * `assert_contents(lines_of_terminal)`
117
+ * `assert_contents_at(row_start, row_end, expected_text)`
111
118
 
112
119
  ### Output
113
120
 
@@ -51,10 +51,7 @@ module TTYtest
51
51
  def print
52
52
  puts "\n#{self}"
53
53
  end
54
-
55
- def print_rows
56
- puts rows
57
- end
54
+ alias print_rows print
58
55
 
59
56
  # @return [String] All rows of the captured terminal, separated by newlines
60
57
  def to_s
@@ -25,7 +25,7 @@ module TTYtest
25
25
  def assert_row_at(row_number, column_start, column_end, expected)
26
26
  expected = expected.rstrip
27
27
  actual = row(row_number)
28
- column_end += 1 if column_end.positive?
28
+ column_end += 1
29
29
  return if actual[column_start, column_end].eql?(expected)
30
30
 
31
31
  raise MatchError,
@@ -125,6 +125,33 @@ module TTYtest
125
125
  end
126
126
  alias assert_matches assert_contents
127
127
 
128
+ # Asserts the contents of the terminal at specified rows
129
+ # @param [String] expected the expected contents of the terminal at specified rows. Trailing whitespace on each line is ignored
130
+ # @raise [MatchError] if the terminal doesn't match the expected content
131
+ def assert_contents_at(row_start, row_end, expected)
132
+ expected_rows = expected.split("\n")
133
+ diff = []
134
+ matched = true
135
+ row_end += 1 if row_end.zero?
136
+
137
+ rows.slice(row_start, row_end).each_with_index do |actual_row, index|
138
+ expected_row = (expected_rows[index] || '').rstrip
139
+ if actual_row != expected_row
140
+ diff << "-#{expected_row}"
141
+ diff << "+#{actual_row}"
142
+ matched = false
143
+ else
144
+ diff << " #{actual_row}".rstrip
145
+ end
146
+ end
147
+
148
+ return if matched
149
+
150
+ raise MatchError,
151
+ "screen did not match expected content:\n--- expected\n+++ actual\n#{diff.join("\n")}"
152
+ end
153
+ alias assert_matches_at assert_contents_at
154
+
128
155
  METHODS = public_instance_methods
129
156
  end
130
157
  end
@@ -61,13 +61,15 @@ module TTYtest
61
61
  # @param [Integer] number of times to send up arrow
62
62
  # @!method send_keys_exact
63
63
  # Send tmux send-keys command to the terminal, such as DC or Enter, to simulate pressing that key in the terminal.
64
+ # @!method send_home
65
+ # Simulates typing in the Home key in the terminal.
66
+ # @!method send_end
67
+ # Simulates typing in the End key in the terminal.
68
+ # @!method send_clear
69
+ # Clears the screen in the terminal using ascii clear command.
64
70
  # @!method capture
65
71
  # Capture the current state of the terminal
66
72
  # @return [Capture] instantaneous state of the terminal when called
67
- # @!method print
68
- # Prints the current state of the terminal to stdout. See capture to get the raw string.
69
- # @!method print_rows
70
- # Prints the current state of the terminal as an array to stdout. See rows to get the raw array.
71
73
  def_delegators :@driver_terminal,
72
74
  :send_keys, :send_keys_one_at_a_time,
73
75
  :send_newline, :send_newlines,
@@ -78,6 +80,10 @@ module TTYtest
78
80
  :send_keys_exact, :send_home, :send_end, :send_clear,
79
81
  :capture
80
82
 
83
+ # @!method print
84
+ # Prints the current state of the terminal to stdout. See capture to get the raw string.
85
+ # @!method print_rows
86
+ # Prints the current state of the terminal as an array to stdout. See rows to get the raw array.
81
87
  # @!method rows
82
88
  # @return [Array<String>]
83
89
  # @see Capture#rows
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTYtest
4
- VERSION = '0.9.6'
4
+ VERSION = '0.9.7'
5
5
  end
data/notes.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  to push new version to github
2
- git tag v0.9.6
2
+ git tag v0.9.7
3
3
  git push origin --tags
4
4
 
5
5
  to push new version to rubygems.org
6
6
  gem build ttytest2.gemspec
7
- gem push ttytest2-0.9.6.gem
7
+ gem push ttytest2-0.9.7.gem
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttytest2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Eski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-04 00:00:00.000000000 Z
11
+ date: 2024-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler