cexpect 0.1.0 → 0.1.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: 1ccc43da0141c2168408e3a9f931f58e37c0a71edab8b2bcd40066396ed8dfbe
4
- data.tar.gz: 543082cfb8016426f41aad970df5cadee7109f285aec39b8062cb097662ab49a
3
+ metadata.gz: 8c069d8b016446307cbdc97331682a9aac2a0bdb0a70fefb40c5fdd946f71cef
4
+ data.tar.gz: 8f0b4dabc8fd1d75b223c3a55822ab26400b3e6fa96ef0178f4b18f4e6fc1e7a
5
5
  SHA512:
6
- metadata.gz: faf35c685141bbe365000a483594932614fc9b5873b152a5fff7fdbdc961b769f62c91f69b8553f6265b31cf4d9beaf5913f0736e5d21c4f9e644d48b27c98cb
7
- data.tar.gz: '0383c442a569ac777e57f9bd38b2c63025ad2d1bfb2748ddc6adf0859f32cdc85c755a66d9dfc6c15a336ed5258bafd2566652299954d56d357d3fcb6d9f025f'
6
+ metadata.gz: 6a73e2690ed2625d7be89045cf65ed3601301fb3f8afd581464231daba94cfed43cc51d2185159ea5d2df64585db9f24580e307f7af8b721be7aa42c2dfb1e3c
7
+ data.tar.gz: e2713329c4fb95c1e78d4107dfebd052548b7db5a6211fbdabdb38b51ef374afa934479a742d903ce886575d86e7ce710ce48006b9b71fd18358c60e11b37f88
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --format documentation
2
2
  --color
3
3
  --require spec_helper
4
+ -Ilib
@@ -0,0 +1,43 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - 'bin/{console,setup}' # not mine
6
+ - 'Gemfile' # maintained through "bundle" command
7
+
8
+ # TODO: Clean up tests
9
+ RSpec/ExpectInHook:
10
+ Enabled: false
11
+ RSpec/FilePath:
12
+ Exclude:
13
+ - spec/cexpect_spec.rb
14
+ RSpec/MessageSpies:
15
+ Enabled: false
16
+ RSpec/NestedGroups:
17
+ Enabled: false
18
+ RSpec/VerifiedDoubles:
19
+ Enabled: false
20
+
21
+ # Personal preferences
22
+ Layout/DotPosition:
23
+ EnforcedStyle: trailing
24
+ Style/PercentLiteralDelimiters:
25
+ PreferredDelimiters:
26
+ '%i': '()'
27
+
28
+ # New stuff in rubocop, not yet enabled/disabled by default
29
+ Layout/SpaceAroundMethodCallOperator:
30
+ Enabled: true
31
+ Lint/RaiseException:
32
+ Enabled: true
33
+ Lint/StructNewOverride:
34
+ Enabled: true
35
+ Style/HashEachMethods:
36
+ Enabled: true
37
+ Style/HashTransformKeys:
38
+ Enabled: true
39
+ Style/HashTransformValues:
40
+ Enabled: true
41
+
42
+ Style/ExponentialNotation:
43
+ Enabled: false
data/Gemfile CHANGED
@@ -5,3 +5,6 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
+
9
+ gem "rubocop", "~> 0.82.0"
10
+ gem "rubocop-rspec", "~> 1.38"
@@ -1,13 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cexpect (0.1.0)
4
+ cexpect (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ast (2.4.0)
9
10
  diff-lcs (1.3)
11
+ jaro_winkler (1.5.4)
12
+ parallel (1.19.1)
13
+ parser (2.7.1.1)
14
+ ast (~> 2.4.0)
15
+ rainbow (3.0.0)
10
16
  rake (12.3.3)
17
+ rexml (3.2.4)
11
18
  rspec (3.9.0)
12
19
  rspec-core (~> 3.9.0)
13
20
  rspec-expectations (~> 3.9.0)
@@ -21,6 +28,18 @@ GEM
21
28
  diff-lcs (>= 1.2.0, < 2.0)
22
29
  rspec-support (~> 3.9.0)
23
30
  rspec-support (3.9.2)
31
+ rubocop (0.82.0)
32
+ jaro_winkler (~> 1.5.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.7.0.1)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ rexml
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 2.0)
39
+ rubocop-rspec (1.38.1)
40
+ rubocop (>= 0.68.1)
41
+ ruby-progressbar (1.10.1)
42
+ unicode-display_width (1.7.0)
24
43
 
25
44
  PLATFORMS
26
45
  ruby
@@ -29,6 +48,8 @@ DEPENDENCIES
29
48
  cexpect!
30
49
  rake (~> 12.0)
31
50
  rspec (~> 3.0)
51
+ rubocop (~> 0.82.0)
52
+ rubocop-rspec (~> 1.38)
32
53
 
33
54
  BUNDLED WITH
34
55
  2.1.4
data/README.md CHANGED
@@ -62,6 +62,13 @@ end
62
62
 
63
63
  wr.puts('cat very-large-file')
64
64
  contents = rd.fexpect('$ ')
65
+
66
+ # If CExpect.spawn doesn't suit you
67
+ orig_rd, wr = IO.pipe
68
+ rd = CExpect::Reader.new(orig_rd)
69
+
70
+ wr.puts "Hello, World!\n"
71
+ greeting = rd.fexpect("\n")
65
72
  ```
66
73
 
67
74
  ## Development
data/Rakefile CHANGED
@@ -1,6 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
3
6
 
4
7
  RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
5
9
 
6
- task :default => :spec
10
+ task default: %i(spec rubocop)
@@ -1,27 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/cexpect/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
4
- spec.name = "cexpect"
6
+ spec.name = 'cexpect'
5
7
  spec.version = Cexpect::VERSION
6
- spec.authors = ["Christer Jansson"]
7
- spec.email = ["christer@janssons.org"]
8
+ spec.authors = ['Christer Jansson']
9
+ spec.email = ['christer@janssons.org']
8
10
 
9
- spec.summary = %q{An improved expect method}
10
- spec.description = %q{An expect method with more reasonable return values and logging functionality}
11
- spec.homepage = "https://github.com/kondensatorn/cexpect"
12
- spec.license = "BSD 2-clause"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
11
+ spec.summary = 'An improved expect method'
12
+ spec.description = 'An expect method with more reasonable return' \
13
+ ' values and logging functionality'
14
+ spec.homepage = 'https://github.com/kondensatorn/cexpect'
15
+ spec.license = 'BSD 2-clause'
16
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
17
 
15
- spec.metadata["homepage_uri"] = spec.homepage
16
- spec.metadata["source_code_uri"] = spec.homepage
17
- spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = spec.homepage
20
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG.md"
18
21
 
19
22
  # Specify which files should be added to the gem when it is released.
20
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ # The `git ls-files -z` loads the files in the RubyGem that have
24
+ # been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.
27
+ split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
28
  end
24
- spec.bindir = "exe"
29
+ spec.bindir = 'exe'
25
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
- spec.require_paths = ["lib"]
31
+ spec.require_paths = ['lib']
27
32
  end
@@ -1,7 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'delegate'
2
4
  require 'observer'
3
5
  require 'pty'
4
6
 
7
+ #
8
+ # A module for supplying a different expect method
9
+ #
5
10
  module CExpect
6
11
  def self.spawn(*args)
7
12
  original_rd, wr, pid = PTY.spawn(*args)
@@ -13,6 +18,10 @@ module CExpect
13
18
  end
14
19
  end
15
20
 
21
+ #
22
+ # A class delegating normal operations to a wrapped IO, adding an
23
+ # expect method
24
+ #
16
25
  class Reader < SimpleDelegator
17
26
  include Observable
18
27
 
@@ -21,11 +30,11 @@ module CExpect
21
30
  super
22
31
  end
23
32
 
24
- def expect(pat, timeout = nil, match_method: :_expect_re_match)
33
+ def expect(pat, timeout = nil, match_method: :re_match)
25
34
  buf = +''
26
35
 
27
36
  result = catch(:result) do
28
- loop { _expect_try(pat, buf, timeout, match_method) }
37
+ loop { expect_try(pat, buf, timeout, match_method) }
29
38
  end
30
39
 
31
40
  if block_given?
@@ -36,13 +45,13 @@ module CExpect
36
45
  end
37
46
 
38
47
  def fexpect(pat, timeout = nil)
39
- expect(pat, timeout, match_method: :_expect_string_match)
48
+ expect(pat, timeout, match_method: :string_match)
40
49
  end
41
50
 
42
51
  private
43
52
 
44
- def _expect_try(pat, buf, timeout, match_method)
45
- c = _expect_getc(timeout)
53
+ def expect_try(pat, buf, timeout, match_method)
54
+ c = getc(timeout)
46
55
 
47
56
  if c.nil?
48
57
  @leftovers = buf
@@ -51,32 +60,34 @@ module CExpect
51
60
 
52
61
  buf << c
53
62
 
54
- _expect_log(pat, buf)
63
+ log(pat, buf)
55
64
 
56
65
  result = send(match_method, buf, pat)
57
66
  throw(:result, result) if result
58
67
  end
59
68
 
60
- def _expect_getc(timeout)
69
+ def getc(timeout)
61
70
  return @leftovers.slice!(0).chr unless @leftovers.empty?
62
71
 
63
- return nil if !IO.select([self], nil, nil, timeout) || eof?
72
+ rd = __getobj__
73
+
74
+ return nil if !IO.select([rd], nil, nil, timeout) || eof?
64
75
 
65
- getc.chr
76
+ rd.getc.chr
66
77
  end
67
78
 
68
- def _expect_log(pat, buf)
79
+ def log(pat, buf)
69
80
  return if count_observers.zero?
70
81
 
71
82
  changed
72
- notify_observers("pat: #{pat.inspect}\nbuf: #{buf.inspect}\n")
83
+ notify_observers(pat, buf)
73
84
  end
74
85
 
75
- def _expect_re_match(buf, pat)
86
+ def re_match(buf, pat)
76
87
  buf.match(pat)
77
88
  end
78
89
 
79
- def _expect_string_match(buf, pat)
90
+ def string_match(buf, pat)
80
91
  buf[0, buf.size - pat.size] if buf.end_with?(pat)
81
92
  end
82
93
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Cexpect
2
- VERSION = "0.1.0"
4
+ VERSION = '0.1.1'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cexpect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christer Jansson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-28 00:00:00.000000000 Z
11
+ date: 2020-04-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An expect method with more reasonable return values and logging functionality
14
14
  email:
@@ -19,6 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - ".gitignore"
21
21
  - ".rspec"
22
+ - ".rubocop.yml"
22
23
  - ".travis.yml"
23
24
  - CHANGELOG.md
24
25
  - Gemfile