ttytest 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: ec223f6306af46c375d8682b34246d96a35bfeb2
4
- data.tar.gz: '08f13d79052c316a5890b396004dae0d4b00c748'
3
+ metadata.gz: 78021e6870947818ac2d9be3fe3d83fe5070662d
4
+ data.tar.gz: d3cc412b912956ef3ea44948f6a656b3bfca644f
5
5
  SHA512:
6
- metadata.gz: 1ce7169be0b7222a5becc34ff849d76d401b64596e7538796da2425b6bc8eb8d3bb7dba19eaa247ef48ac65ba9ff9c71270237ab842c79e9ad1fec55e370ca0c
7
- data.tar.gz: 3a4c6dcc1a0c6d7360344fca24d2eac9b5c1b218f42efb58fe1318b09164f76e0bf6d10a93aa191688cc7173dff5a3ca5e11777747e91cdef1ca9f36ba49fba2
6
+ metadata.gz: 6fc3b334c3c43bbe3fe518f74ca5be4b262f60014f564443433a41fb2b503905264ff2df725379cd173729ce5fdca7638848a991a78ee6056f36c75c8c838669
7
+ data.tar.gz: 371818454cdc7df5cd7d6ceef162ddf0075ad5f6bd425122457fb0ef1e4c02e99d776c9eda2faf3adf31a01530fdbe57e04905a31f52fc216c76b6359c589df3
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- TTYtest is an integration test framework for interactive tty applications. It's like [capybara](https://github.com/teamcapybara/capybara) for the terminal.
1
+ TTYtest is an integration test framework for interactive console applications. It's like [capybara](https://github.com/teamcapybara/capybara) for the terminal.
2
+
3
+ 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.
2
4
 
3
5
  [![Build Status](https://travis-ci.org/jhawthorn/ttytest.svg?branch=master)](https://travis-ci.org/jhawthorn/ttytest)
4
6
 
@@ -10,20 +12,21 @@ TTYtest is an integration test framework for interactive tty applications. It's
10
12
  ## Usage
11
13
 
12
14
  ``` ruby
13
- class TTYtestTest < Minitest::Test
14
- def test_shell_hello_world
15
- @tty = TTYtest.driver.new_terminal(%{PS1='$ ' /bin/sh})
16
- @tty.assert_row(0, '$')
17
-
18
- @tty.send_raw('echo "Hello, world"', "\n")
19
-
20
- @tty.assert_row(0, '$ echo "Hello, world"')
21
- @tty.assert_row(1, 'Hello, world')
22
- @tty.assert_cursor_position(2, 2)
23
- end
24
- end
15
+ @tty = TTYtest.new_terminal(%{PS1='$ ' /bin/sh}, width: 80, height: 24)
16
+ @tty.assert_row(0, '$')
17
+ @tty.assert_cursor_position(x: 2, y: 0)
18
+
19
+ @tty.send_keys(%{echo "Hello, world"\n})
20
+
21
+ @tty.assert_row(0, '$ echo "Hello, world"')
22
+ @tty.assert_row(1, 'Hello, world')
23
+ @tty.assert_cursor_position(x: 2, y: 2)
24
+
25
+ p @tty.rows # => ["$ echo \"Hello, world\"", "Hello, world", "$", "", "", "", ...]
25
26
  ```
26
27
 
28
+ See also [fzy's integration test](https://github.com/jhawthorn/fzy/blob/master/test/integration/integration_test.rb) for a full example.
29
+
27
30
  ## TravisCI
28
31
 
29
32
  TTYtest can run on [TravisCI](https://travis-ci.org/), but the version of tmux made available with their default ubuntu 12.04 environment is too old. However the TravisCI ubuntu 14.04 "trusty" image provides tmux 1.8, which works great.
@@ -1,3 +1,4 @@
1
+ require 'forwardable'
1
2
  require 'ttytest/tmux/driver'
2
3
  require 'ttytest/tmux/session'
3
4
 
@@ -5,6 +6,9 @@ module TTYtest
5
6
  class << self
6
7
  attr_accessor :driver
7
8
  attr_accessor :default_max_wait_time
9
+
10
+ extend Forwardable
11
+ def_delegators :driver, :new_terminal
8
12
  end
9
13
 
10
14
  class MatchError < StandardError; end
@@ -2,14 +2,17 @@ module TTYtest
2
2
  class Capture
3
3
  include TTYtest::Matchers
4
4
 
5
- attr_reader :cursor_x, :cursor_y, :cursor_visible
5
+ attr_reader :cursor_x, :cursor_y
6
+ attr_reader :width, :height
6
7
 
7
- def initialize(contents, cursor_x: 0, cursor_y: 0, cursor_visible: true)
8
+ def initialize(contents, cursor_x: 0, cursor_y: 0, width: nil, height: nil, cursor_visible: true)
8
9
  @rows = (contents+"\nEND").split("\n")[0...-1].map do |row|
9
10
  row || ""
10
11
  end
11
12
  @cursor_x = cursor_x
12
13
  @cursor_y = cursor_y
14
+ @width = width
15
+ @height = height
13
16
  @cursor_visible = cursor_visible
14
17
  end
15
18
 
@@ -25,6 +28,14 @@ module TTYtest
25
28
  rows[row]
26
29
  end
27
30
 
31
+ def cursor_visible?
32
+ @cursor_visible
33
+ end
34
+
35
+ def cursor_hidden?
36
+ !cursor_visible?
37
+ end
38
+
28
39
  def capture
29
40
  self
30
41
  end
@@ -15,6 +15,18 @@ module TTYtest
15
15
  end
16
16
  end
17
17
 
18
+ def assert_cursor_visible
19
+ if !cursor_visible?
20
+ raise MatchError, "expected cursor to be visible was hidden\nEntire screen:\n#{to_s}"
21
+ end
22
+ end
23
+
24
+ def assert_cursor_hidden
25
+ if !cursor_hidden?
26
+ raise MatchError, "expected cursor to be hidden was visible\nEntire screen:\n#{to_s}"
27
+ end
28
+ end
29
+
18
30
  METHODS = public_instance_methods
19
31
  end
20
32
  end
@@ -16,7 +16,17 @@ module TTYtest
16
16
  end
17
17
 
18
18
  def_delegators :@driver_terminal, :send_keys, :send_raw, :capture
19
- def_delegators :capture, :rows, :row, :cursor_position
19
+ def_delegators :capture, :rows, :row, :cursor_position, :width, :height, :cursor_visible?, :cursor_hidden?
20
+
21
+ TTYtest::Matchers::METHODS.each do |matcher_name|
22
+ define_method matcher_name do |*args|
23
+ synchronize do
24
+ capture.public_send(matcher_name, *args)
25
+ end
26
+ end
27
+ end
28
+
29
+ private
20
30
 
21
31
  def synchronize(seconds=max_wait_time)
22
32
  start_time = Time.now
@@ -28,13 +38,5 @@ module TTYtest
28
38
  retry
29
39
  end
30
40
  end
31
-
32
- TTYtest::Matchers::METHODS.each do |matcher_name|
33
- define_method matcher_name do |*args|
34
- synchronize do
35
- capture.public_send(matcher_name, *args)
36
- end
37
- end
38
- end
39
41
  end
40
42
  end
@@ -18,17 +18,19 @@ module TTYtest
18
18
 
19
19
  def capture
20
20
  contents = driver.tmux(*%W[capture-pane -t #{name} -p])
21
- str = driver.tmux(*%W[display-message -t #{name} -p #\{cursor_x},#\{cursor_y},#\{cursor_flag}])
22
- x, y, cursor_flag = str.split(',').map(&:to_i)
23
- cursor_visible = (cursor_flag != 0)
24
- TTYtest::Capture.new(contents, cursor_x: x, cursor_y: y, cursor_visible: cursor_visible)
21
+ str = driver.tmux(*%W[display-message -t #{name} -p #\{cursor_x},#\{cursor_y},#\{cursor_flag},#\{pane_width},#\{pane_height}])
22
+ x, y, cursor_flag, width, height = str.split(',')
23
+ TTYtest::Capture.new(
24
+ contents.chomp("\n"),
25
+ cursor_x: x.to_i,
26
+ cursor_y: y.to_i,
27
+ width: width.to_i,
28
+ height: height.to_i,
29
+ cursor_visible: (cursor_flag != '0')
30
+ )
25
31
  end
26
32
 
27
33
  def send_keys(*keys)
28
- driver.tmux(*%W[send-keys -t #{name}], *keys)
29
- end
30
-
31
- def send_raw(*keys)
32
34
  driver.tmux(*%W[send-keys -t #{name} -l], *keys)
33
35
  end
34
36
  end
@@ -0,0 +1 @@
1
+ set -g status off
@@ -1,3 +1,3 @@
1
1
  module TTYtest
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttytest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-28 00:00:00.000000000 Z
11
+ date: 2016-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.5.2
98
+ rubygems_version: 2.6.8
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: TTYtest is an integration test framework for interactive tty applications