ttytest2 0.7.1 → 0.8.1

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: b9eaa16f80b9604b9b174e0e7cba8fe5552c453d928d7f543dbf0d1498726516
4
- data.tar.gz: a8b0cad547df8948c71951817ad7c9fbaa74a8d1a17e7e0bf61c94911c4a6d13
3
+ metadata.gz: 7a35421907aa8999c90ba5e18959aa659bf6a9b14248ae46acddb7d18f1db0f5
4
+ data.tar.gz: bbf9762f20e681e29861f9f04090afa03c238fccee3ea6e3d2e8314fb6fa88c1
5
5
  SHA512:
6
- metadata.gz: 6b64fa53f510b203ea188a715e76ea524564dab12e5718d3c93e57c2182d8a192c263511492667703a155e3b8b8d68293ffa8ab835f606117b603696c92e0159
7
- data.tar.gz: 1f16083d91f27ccc16064a5d23bff87e03b18b5185ce206ad3efe8efeec0e1b0c6a32d947b4078f49b929c31e4be13f311bd6fd3dacf8af7e03bdf86e7873d5f
6
+ metadata.gz: 978ca3331442680de64cd74fdd9e7167526c4a521dc9ed41fdbd8e08d89d9caebb617d6427edb58b5bc79b1b0a522cbb4a54d0854a5f8a3953f22777adebc0d9
7
+ data.tar.gz: 4115b6301cba03d98b92a6b40f9264b3a0630f28421fae34d402bbfef941f6704895e6b73fee83ddde511b2523f602a16d351434366392a75a1e61457164432d
data/README.md CHANGED
@@ -6,7 +6,7 @@ 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/ttytest.svg)](https://rubygems.org/gems/ttytest)
9
+ [![Gem Version](https://badge.fury.io/rb/ttytest2.svg)](https://rubygems.org/gems/ttytest2)
10
10
 
11
11
  ## Minimum Requirements
12
12
 
@@ -18,6 +18,8 @@ It works by running commands inside a tmux session, capturing the pane, and comp
18
18
  ### Example
19
19
 
20
20
  ``` ruby
21
+ require 'ttytest'
22
+
21
23
  @tty = TTYtest.new_terminal(%{PS1='$ ' /bin/sh}, width: 80, height: 24)
22
24
  @tty.assert_row(0, '$')
23
25
  @tty.assert_cursor_position(x: 2, y: 0)
@@ -41,6 +43,8 @@ The main way to use TTYtest is through assertions. When called on a `TTYtest::Te
41
43
  Available assertions:
42
44
  * `assert_row(row_number, expected_text)`
43
45
  * `assert_row_like(row_number, expected_text)`
46
+ * `assert_row_starts_with(row_number, expected_text)`
47
+ * `assert_row_ends_with(row_number, expected_text)`
44
48
  * `assert_cursor_position(x: x, y: y)`
45
49
  * `assert_cursor_visible`
46
50
  * `assert_cursor_hidden`
@@ -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,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TTYtest
4
+ # Assertions for ttytest2.
2
5
  module Matchers
3
6
  # Asserts the contents of a single row
4
7
  # @param [Integer] row_number the row (starting from 0) to test against
@@ -7,15 +10,15 @@ module TTYtest
7
10
  def assert_row(row_number, expected)
8
11
  expected = expected.rstrip
9
12
  actual = row(row_number)
10
- return unless actual != expected
13
+ return if actual == expected
11
14
 
12
15
  raise MatchError,
13
16
  "expected row #{row_number} to be #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}"
14
17
  end
15
18
 
16
- # Asserts the contents of a single row
19
+ # Asserts the contents of a single row contains expected
17
20
  # @param [Integer] row_number the row (starting from 0) to test against
18
- # @param [String] expected the expected value of the row. Any trailing whitespace is ignored
21
+ # @param [String] expected the expected value contained in the row. Any trailing whitespace is ignored
19
22
  # @raise [MatchError] if the row doesn't match
20
23
  def assert_row_like(row_number, expected)
21
24
  expected = expected.rstrip
@@ -26,6 +29,32 @@ module TTYtest
26
29
  "expected row #{row_number} to be like #{expected.inspect} but got #{actual.inspect}\nEntire screen:\n#{self}"
27
30
  end
28
31
 
32
+ # Asserts the contents of a single row start with expected
33
+ # @param [Integer] row_number the row (starting from 0) to test against
34
+ # @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
35
+ # @raise [MatchError] if the row doesn't match
36
+ def assert_row_starts_with(row_number, expected)
37
+ expected = expected.rstrip
38
+ actual = row(row_number)
39
+ return if actual.start_with?(expected)
40
+
41
+ raise MatchError,
42
+ "expected row #{row_number} to start with #{expected.inspect} and got #{actual.inspect}\nEntire screen:\n#{self}"
43
+ end
44
+
45
+ # Asserts the contents of a single row end with expected
46
+ # @param [Integer] row_number the row (starting from 0) to test against
47
+ # @param [String] expected the expected value that the row starts with. Any trailing whitespace is ignored
48
+ # @raise [MatchError] if the row doesn't match
49
+ def assert_row_ends_with(row_number, expected)
50
+ expected = expected.rstrip
51
+ actual = row(row_number)
52
+ return if actual.end_with?(expected)
53
+
54
+ raise MatchError,
55
+ "expected row #{row_number} to end with #{expected.inspect} and got #{actual.inspect}\nEntire screen:\n#{self}"
56
+ end
57
+
29
58
  # Asserts that the cursor is in the expected position
30
59
  # @param [Integer] x cursor x (row) position, starting from 0
31
60
  # @param [Integer] y cursor y (column) position, starting from 0
@@ -33,7 +62,7 @@ module TTYtest
33
62
  def assert_cursor_position(x, y)
34
63
  expected = [x, y]
35
64
  actual = [cursor_x, cursor_y]
36
- return unless actual != expected
65
+ return if actual == expected
37
66
 
38
67
  raise MatchError,
39
68
  "expected cursor to be at #{expected.inspect} but was at #{actual.inspect}\nEntire screen:\n#{self}"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'forwardable'
2
4
  require 'ttytest/matchers'
3
5
  require 'ttytest/capture'
@@ -2,19 +2,20 @@
2
2
 
3
3
  module TTYtest
4
4
  module Tmux
5
+ # tmux session manager
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])
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TTYtest
2
- VERSION = '0.7.1'.freeze
4
+ VERSION = '0.8.1'
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.7.0
2
+ git tag v0.8.1
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.7.0.gem
7
+ gem push ttytest2-0.8.1.gem
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.7.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Eski