repl_runner 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -4
- data/lib/repl_runner.rb +17 -8
- data/lib/repl_runner/default_config.rb +1 -1
- data/lib/repl_runner/multi_command_parser.rb +1 -1
- data/lib/repl_runner/multi_repl.rb +1 -1
- data/lib/repl_runner/version.rb +1 -1
- data/test/config_test.rb +5 -0
- data/test/pty_party_test.rb +14 -2
- data/test/repl_runner_test.rb +27 -14
- metadata +15 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17d75b996b5cda53bf314490ad7f65a014cae74f
|
4
|
+
data.tar.gz: 3d3a8e485b8ec3994c956c91155722788682efd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc1f2891ff45a80042105f1562fc86bca5de45964f7ff02079c9085220e6fc0b12c852bab3453fe9e5541928c1996cd11187b860590e9c803e3c9fa1833bd654
|
7
|
+
data.tar.gz: 4bf24b4a0f3275ae713a68098810bb33dc330065ddcef38b2605495daa59e54aa5cc838c216bf116e0c513740cfe91f6e6a896f711fa3b76857a3aa714b9dead
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -28,7 +28,7 @@ Then run `$ bundle install`.
|
|
28
28
|
|
29
29
|
To open a remote rails console on heroku with the heroku toolbelt installed, you could drive it like this:
|
30
30
|
|
31
|
-
```
|
31
|
+
```ruby
|
32
32
|
ReplRunner.new(:rails_console, "heroku run rails console -a testapp").run do |repl|
|
33
33
|
repl.run('a = 1 + 1') {|result| assert_match '2', result }
|
34
34
|
repl.run('"hello" + "world"') {|result| assert_match 'helloworld', result }
|
@@ -36,6 +36,8 @@ ReplRunner.new(:rails_console, "heroku run rails console -a testapp").run do |re
|
|
36
36
|
end
|
37
37
|
```
|
38
38
|
|
39
|
+
**Note:** do not forget to call `run` on the ReplRunner object.
|
40
|
+
|
39
41
|
The first argument `:rails_console` tells ReplReader what type of a session we are going to open up. The second `"heroku run rails console -a testapp"` is the command we want to use to start our psuedo remote terminal.
|
40
42
|
|
41
43
|
You can then call `run` on this and pass in a block. The block yields to a `MultiRepl` instance that can take the command `run` along with arguments to pass into the command line such as `'1+1'`
|
@@ -47,13 +49,13 @@ Also note that you will get the entire return including any prompts if you run a
|
|
47
49
|
```
|
48
50
|
$ irb
|
49
51
|
1.9.3p392 :001 > 1 + 1
|
50
|
-
|
52
|
+
=> 2
|
51
53
|
```
|
52
54
|
|
53
55
|
So when you run this via ReplRunner you will get a result string like this
|
54
56
|
|
55
|
-
```
|
56
|
-
ReplRunner.new(:irb) do |repl|
|
57
|
+
```ruby
|
58
|
+
ReplRunner.new(:irb).run do |repl|
|
57
59
|
repl.run('1 + 1') {|result| puts result }
|
58
60
|
end
|
59
61
|
" => 2\r\r\n"
|
data/lib/repl_runner.rb
CHANGED
@@ -6,11 +6,12 @@ require 'pty'
|
|
6
6
|
require 'active_support/core_ext/object/blank'
|
7
7
|
|
8
8
|
class ReplRunner
|
9
|
-
attr_accessor :command, :repl
|
9
|
+
attr_accessor :command, :repl, :config
|
10
10
|
|
11
|
-
class
|
12
|
-
def initialize(command, string)
|
13
|
-
msg =
|
11
|
+
class NoResultsError < StandardError
|
12
|
+
def initialize(command, regex, string)
|
13
|
+
msg = "No result found for command: #{command.inspect}\nIn output: \n #{string.inspect}\n"
|
14
|
+
msg << "Using regex: \n /#{regex}/\n"
|
14
15
|
super(msg)
|
15
16
|
end
|
16
17
|
end
|
@@ -23,15 +24,23 @@ class ReplRunner
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def initialize(cmd_type, command = nil, options = {})
|
27
|
+
raise "Unexpected block, use the `run` command instead?" if block_given?
|
26
28
|
command = cmd_type.to_s if command.nil?
|
27
29
|
cmd_type = cmd_type.chomp.gsub(/\s/, '_').to_sym if cmd_type.is_a?(String)
|
28
30
|
@command = command
|
29
31
|
@repl = nil
|
30
|
-
@config =
|
32
|
+
@config = get_config_for_command(cmd_type)
|
31
33
|
raise UnregisteredCommand.new(cmd_type) unless @config
|
32
34
|
@options = options
|
33
35
|
end
|
34
36
|
|
37
|
+
def get_config_for_command(cmd_type)
|
38
|
+
known_configs.detect do |cmd_match, config|
|
39
|
+
return config if cmd_match == cmd_type
|
40
|
+
return config if cmd_match.is_a?(Regexp) && cmd_match =~ cmd_type.to_s
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
35
44
|
def known_configs
|
36
45
|
self.class.known_configs
|
37
46
|
end
|
@@ -61,13 +70,13 @@ class ReplRunner
|
|
61
70
|
|
62
71
|
def zip(string)
|
63
72
|
results = []
|
64
|
-
|
73
|
+
inputs = string.lines.map(&:rstrip)
|
65
74
|
self.run do |repl|
|
66
|
-
|
75
|
+
inputs.each do |line|
|
67
76
|
repl.run(line) {|result| results << result }
|
68
77
|
end
|
69
78
|
end
|
70
|
-
|
79
|
+
inputs.zip(results)
|
71
80
|
end
|
72
81
|
|
73
82
|
def run(&block)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
ReplRunner.register_command(:rails_console, :irb) do |config|
|
1
|
+
ReplRunner.register_command(:rails_console, :irb, /^bin\/rails/) do |config|
|
2
2
|
config.terminate_command "exit" # the command you use to end the 'rails console'
|
3
3
|
config.startup_timeout 60 # seconds to boot
|
4
4
|
config.return_char "\n" # the character that submits the command
|
@@ -24,7 +24,7 @@ class ReplRunner
|
|
24
24
|
regex = command_to_regex(command)
|
25
25
|
before, match, result = string.rpartition(regex)
|
26
26
|
|
27
|
-
raise
|
27
|
+
raise NoResultsError.new(command, regex, raw) if result.empty?
|
28
28
|
|
29
29
|
string = before
|
30
30
|
@parsed_result << result.rpartition(STRIP_TRAILING_PROMPT_REGEX).first
|
data/lib/repl_runner/version.rb
CHANGED
data/test/config_test.rb
CHANGED
data/test/pty_party_test.rb
CHANGED
@@ -9,10 +9,22 @@ class StreamExecTest < Test::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_multi_command_read
|
12
|
-
repl = ReplRunner::PtyParty.new("irb --simple-prompt")
|
12
|
+
repl = ReplRunner::PtyParty.new("env TERM=ansi-mono irb --simple-prompt")
|
13
13
|
repl.write("STDOUT.sync = true\n")
|
14
14
|
repl.write("1+1\n")
|
15
15
|
repl.write("exit\n")
|
16
|
-
|
16
|
+
result = repl.read
|
17
|
+
[
|
18
|
+
"STDOUT.sync = true",
|
19
|
+
"1+1",
|
20
|
+
"exit",
|
21
|
+
">> STDOUT.sync = true",
|
22
|
+
"=> true",
|
23
|
+
">> 1+1",
|
24
|
+
"=> 2",
|
25
|
+
">> exit"
|
26
|
+
].each do |expected|
|
27
|
+
assert_match /#{Regexp.escape(expected)}/, result
|
28
|
+
end
|
17
29
|
end
|
18
30
|
end
|
data/test/repl_runner_test.rb
CHANGED
@@ -19,6 +19,13 @@ class ReplRunnerTest < Test::Unit::TestCase
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
def test_forgot_run
|
23
|
+
assert_raise RuntimeError do
|
24
|
+
ReplRunner.new(:irb, "irb") do |repl|
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
22
29
|
def test_does_not_have_trailing_prompts
|
23
30
|
ReplRunner.new(:irb, "irb ").run do |repl|
|
24
31
|
repl.run('111+111') {|r| assert_equal "=> 222", r.strip }
|
@@ -26,7 +33,7 @@ class ReplRunnerTest < Test::Unit::TestCase
|
|
26
33
|
end
|
27
34
|
|
28
35
|
def test_ensure_exit
|
29
|
-
assert_raise(ReplRunner::
|
36
|
+
assert_raise(ReplRunner::NoResultsError) do
|
30
37
|
ReplRunner.new(:irb, "irb -r ./test/require/never-boots.rb", startup_timeout: 2).run do |repl|
|
31
38
|
repl.run('111+111') {|r| }
|
32
39
|
end
|
@@ -46,19 +53,25 @@ class ReplRunnerTest < Test::Unit::TestCase
|
|
46
53
|
end
|
47
54
|
|
48
55
|
def test_zipping_commands
|
49
|
-
commands =
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
56
|
+
commands = []
|
57
|
+
results = []
|
58
|
+
commands << "a = 3\n"
|
59
|
+
commands << "b = 'foo' * a\n"
|
60
|
+
commands << "puts b"
|
61
|
+
|
62
|
+
repl = ReplRunner.new(:irb)
|
63
|
+
zip = repl.zip(commands.join(""))
|
64
|
+
|
65
|
+
repl.run do |repl|
|
66
|
+
commands.each do |command|
|
67
|
+
repl.run(command.rstrip) {|r| results << r }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
expected = [[commands[0].rstrip, results[0]],
|
71
|
+
[commands[1].rstrip, results[1]],
|
72
|
+
[commands[2].rstrip, results[2]]]
|
73
|
+
assert_equal expected, zip
|
55
74
|
|
56
|
-
expected
|
57
|
-
"=> 3\r",
|
58
|
-
"b = 'foo' * a",
|
59
|
-
"=> \"foofoofoo\"\r",
|
60
|
-
"puts b",
|
61
|
-
"foofoofoo\r\n=> nil\r"]
|
62
|
-
assert_equal expected, zip.flatten
|
75
|
+
assert_equal expected.flatten, zip.flatten
|
63
76
|
end
|
64
77
|
end
|
metadata
CHANGED
@@ -1,66 +1,66 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: repl_runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Schneeman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mocha
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description: " Programatically drive REPL like interfaces, irb, bash, etc. "
|
56
56
|
email:
|
57
57
|
- richard@heroku.com
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .travis.yml
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
64
|
- CHANGELOG.md
|
65
65
|
- Gemfile
|
66
66
|
- LICENSE
|
@@ -91,17 +91,17 @@ require_paths:
|
|
91
91
|
- lib
|
92
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
|
-
- -
|
99
|
+
- - ">="
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.0
|
104
|
+
rubygems_version: 2.2.0
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Run your REPL like interfaces like never before
|
@@ -113,3 +113,4 @@ test_files:
|
|
113
113
|
- test/repl_runner_test.rb
|
114
114
|
- test/require/never-boots.rb
|
115
115
|
- test/test_helper.rb
|
116
|
+
has_rdoc:
|