ttytest2 0.8.0 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3f08a4827e337de7e9124c7c0daf929922f9c6dfb573a03e88ee5e23b243cf9
4
- data.tar.gz: 1f4ae48c6dff1ce25ea0a22c6f29c188b98caee3efa2a512132e4c416a522185
3
+ metadata.gz: 000e855fe9017a84a4041ff693e8037d7ce134231699fb5e4440be428d7f068b
4
+ data.tar.gz: fac1531d712a1f276a3b861fc9f3cb1a21b6a3849433bf4bfff76ec852b39637
5
5
  SHA512:
6
- metadata.gz: edc7cb24ffec16991743b8dd104050f594f78a68ed44b88df91e2ce3ba52045dd0d37548b978a1bc47e0bd424d3dd8b1b75b9cce231f323bb6f860e2fb6ef7e4
7
- data.tar.gz: 8d7e3f220552cc6485fa848e046eb6711e18117f43d6fb99d1fdc1751391da3e0aa719cc5c50b34dd3a4256eb89e17fec5a3868d32084074909af68110570283
6
+ metadata.gz: 93ee5ba6fad1d8f44f000de98a2acd17fa7cb4d19e96dec87f2ea83a718d95db2eaf59b98d9430f8c4009d6f2808a066da31027d28b6005dd97e1906da16a783
7
+ data.tar.gz: 1d9de87f136ae70629a67e21570f325f1cd18e6ce243a0cd000b0f5217efc4222144e52ae1eaa2ba6658d2434c8a3293be83d407adda6e23e6e403432df1f94f
data/README.md CHANGED
@@ -6,7 +6,10 @@ Forked from https://github.com/jhawthorn/ttytest, because I had some features I
6
6
 
7
7
  It works by running commands inside a tmux session, capturing the pane, and comparing the content. The assertions will wait a specified amount of time (default 2 seconds) for the expected content to appear.
8
8
 
9
- [![Gem Version](https://badge.fury.io/rb/ttytest2.svg)](https://rubygems.org/gems/ttytest2)
9
+ [![Gem Version](https://badge.fury.io/rb/ttytest2.svg)](https://badge.fury.io/rb/ttytest2)
10
+
11
+ ## Gem at RubyGems.org
12
+ https://rubygems.org/gems/ttytest2
10
13
 
11
14
  ## Minimum Requirements
12
15
 
@@ -15,7 +18,8 @@ It works by running commands inside a tmux session, capturing the pane, and comp
15
18
 
16
19
  ## Usage
17
20
 
18
- ### Example
21
+ ### Example Canonical CLI/Shell
22
+ Most people should use send_keys, if you are writing or working with a noncanonical shell/CLI, you will probably know it. Most are canonical.
19
23
 
20
24
  ``` ruby
21
25
  require 'ttytest'
@@ -36,6 +40,21 @@ TTY
36
40
  p @tty.rows # => ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ...]
37
41
  ```
38
42
 
43
+ ### Example Noncanonical CLI/Shell
44
+ If you are working with a noncanonical shell, you need to use send_keys_one_at_a_time to have your shell/CLI process the input correctly.
45
+
46
+ ``` ruby
47
+ require 'ttytest'
48
+
49
+ @tty = TTYtest.new_terminal(%{PS1='$ ' /bin/noncanonical-sh}, width: 80, height: 24)
50
+ @tty.assert_row_starts_with(0, ENV['USER'])
51
+ @tty.assert_row_ends_with(0, '$')
52
+
53
+ @tty.send_keys_one_at_a_time('ls')
54
+ @tty.assert_row_ends_with(0, 'ls')
55
+ @tty.send_keys_one_at_a_time(%(\n))
56
+ ```
57
+
39
58
  ### Assertions
40
59
 
41
60
  The main way to use TTYtest is through assertions. When called on a `TTYtest::Terminal`, each of these will be retried (for up to 2 seconds by default).
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
  require 'yard'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TTYtest
2
4
  # Represents the complete state of a {TTYtest::Terminal} at the time it was captured (contents, cursor position, etc).
3
5
  # @attr_reader [Integer] width the number of columns in the captured terminal
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TTYtest
2
4
  # Assertions for ttytest2.
3
5
  module Matchers
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'forwardable'
2
4
  require 'ttytest/matchers'
3
5
  require 'ttytest/capture'
@@ -17,12 +19,15 @@ module TTYtest
17
19
  end
18
20
 
19
21
  # @!method send_keys(*keys)
20
- # Simulate typing keys into the terminal
22
+ # Simulate typing keys into the terminal. For canonical cli's/shells which read line by line.
23
+ # @param [String] keys keys to send to the terminal
24
+ # @!method send_keys_one_at_a_time(*keys)
25
+ # Simulate typing keys into the terminal. For noncanonical cli's/shells which read character by character.
21
26
  # @param [String] keys keys to send to the terminal
22
27
  # @!method capture
23
28
  # Capture the current state of the terminal
24
29
  # @return [Capture] instantaneous state of the terminal when called
25
- def_delegators :@driver_terminal, :send_keys, :capture
30
+ def_delegators :@driver_terminal, :send_keys, :send_keys_one_at_a_time, :capture
26
31
 
27
32
  # @!method rows
28
33
  # @return [Array<String>]
@@ -8,6 +8,7 @@ require 'ttytest/tmux/session'
8
8
 
9
9
  module TTYtest
10
10
  module Tmux
11
+ # tmux driver
11
12
  class Driver
12
13
  COMMAND = 'tmux'
13
14
  SOCKET_NAME = 'ttytest'
@@ -2,19 +2,20 @@
2
2
 
3
3
  module TTYtest
4
4
  module Tmux
5
+ # represents a tmux session and how to send output to the current tmux session
5
6
  class Session
6
7
  # @api private
7
8
  def initialize(driver, name)
8
9
  @driver = driver
9
10
  @name = name
10
11
 
11
- ObjectSpace.define_finalizer(self, self.class.finalize(driver, name))
12
+ # ObjectSpace.define_finalizer(self, self.class.finalize(driver, name))
12
13
  end
13
14
 
14
15
  # @api private
15
- def self.finalize(driver, name)
16
- proc { driver.tmux(*%W[kill-session -t #{name}]) }
17
- end
16
+ # def self.finalize(driver, name)
17
+ # proc { driver.tmux(*%W[kill-session -t #{name}]) }
18
+ # end
18
19
 
19
20
  def capture
20
21
  contents = driver.tmux(*%W[capture-pane -t #{name} -p])
@@ -41,6 +42,12 @@ module TTYtest
41
42
  driver.tmux(*%W[send-keys -t #{name} -l], *keys)
42
43
  end
43
44
 
45
+ def send_keys_one_at_a_time(*keys)
46
+ keys.each do |key|
47
+ driver.tmux(*%W[send-keys -t #{name} -l], key)
48
+ end
49
+ end
50
+
44
51
  private
45
52
 
46
53
  attr_reader :driver, :name
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TTYtest
2
- VERSION = '0.8.0'.freeze
4
+ VERSION = '0.8.2'
3
5
  end
data/lib/ttytest.rb CHANGED
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'forwardable'
2
4
  require 'ttytest/tmux/driver'
3
5
  require 'ttytest/tmux/session'
4
6
 
7
+ # ttytest2 main module
5
8
  module TTYtest
6
9
  class << self
7
10
  attr_accessor :driver, :default_max_wait_time
data/notes.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  to push new version to github,
2
- git tag v0.8.0
2
+ git tag v0.8.2
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.8.0.gem
7
+ gem push ttytest2-0.8.2.gem
data/ttytest2.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'ttytest/version'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttytest2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Eski