rib 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGES.md +32 -0
- data/README.md +5 -4
- data/TODO.md +2 -0
- data/lib/rib.rb +1 -1
- data/lib/rib/api.rb +29 -8
- data/lib/rib/app/auto.rb +2 -3
- data/lib/rib/app/rack.rb +2 -3
- data/lib/rib/app/rails.rb +2 -3
- data/lib/rib/core/completion.rb +6 -13
- data/lib/rib/core/history.rb +3 -3
- data/lib/rib/core/last_value.rb +3 -3
- data/lib/rib/core/multiline.rb +3 -3
- data/lib/rib/core/readline.rb +3 -3
- data/lib/rib/core/squeeze_history.rb +3 -3
- data/lib/rib/core/strip_backtrace.rb +3 -3
- data/lib/rib/extra/autoindent.rb +3 -3
- data/lib/rib/extra/hirb.rb +3 -3
- data/lib/rib/extra/paging.rb +3 -3
- data/lib/rib/more/anchor.rb +13 -4
- data/lib/rib/more/beep.rb +4 -4
- data/lib/rib/more/bottomup_backtrace.rb +3 -3
- data/lib/rib/more/caller.rb +3 -3
- data/lib/rib/more/color.rb +11 -6
- data/lib/rib/more/edit.rb +3 -3
- data/lib/rib/more/multiline_history.rb +3 -3
- data/lib/rib/more/multiline_history_file.rb +3 -3
- data/lib/rib/plugin.rb +15 -4
- data/lib/rib/runner.rb +4 -3
- data/lib/rib/shell.rb +19 -6
- data/lib/rib/test.rb +25 -14
- data/lib/rib/test/history.rb +25 -0
- data/lib/rib/test/multiline.rb +8 -16
- data/lib/rib/version.rb +1 -1
- data/rib.gemspec +7 -6
- data/task/README.md +5 -5
- data/task/gemgem.rb +6 -1
- data/test/core/test_completion.rb +13 -6
- data/test/core/test_history.rb +42 -52
- data/test/core/test_last_value.rb +22 -23
- data/test/core/test_readline.rb +7 -14
- data/test/core/test_squeeze_history.rb +29 -36
- data/test/extra/test_autoindent.rb +8 -3
- data/test/more/test_anchor.rb +85 -0
- data/test/more/test_beep.rb +1 -1
- data/test/more/test_color.rb +16 -0
- data/test/more/test_multiline_history.rb +12 -7
- data/test/test_api.rb +39 -3
- data/test/test_plugin.rb +25 -13
- data/test/test_runner.rb +12 -10
- data/test/test_shell.rb +72 -23
- metadata +6 -5
- data/test/extra/test_anchor.rb +0 -18
data/test/more/test_beep.rb
CHANGED
data/test/more/test_color.rb
CHANGED
@@ -5,11 +5,19 @@ require 'rib/more/color'
|
|
5
5
|
describe Rib::Color do
|
6
6
|
paste :rib
|
7
7
|
|
8
|
+
before do
|
9
|
+
Rib::Color.enable
|
10
|
+
end
|
11
|
+
|
8
12
|
color = Class.new do
|
9
13
|
include Rib::Color
|
10
14
|
def colors
|
11
15
|
@colors ||= Rib::Shell.new.before_loop.config[:color]
|
12
16
|
end
|
17
|
+
|
18
|
+
def inspect_result result
|
19
|
+
result.inspect
|
20
|
+
end
|
13
21
|
end.new
|
14
22
|
|
15
23
|
would 'give correct color' do
|
@@ -49,4 +57,12 @@ describe Rib::Color do
|
|
49
57
|
"#{Regexp.escape(msg)}`.+'#{Regexp.escape(Rib::Color.reset)}")
|
50
58
|
end
|
51
59
|
end
|
60
|
+
|
61
|
+
would 'colorize warnings' do
|
62
|
+
shell = new_shell
|
63
|
+
|
64
|
+
shell.warn('test')
|
65
|
+
|
66
|
+
expect(shell.warnings).eq ["\e[31mtest\e[0m"]
|
67
|
+
end
|
52
68
|
end
|
@@ -8,13 +8,14 @@ describe Rib::MultilineHistory do
|
|
8
8
|
paste :setup_multiline
|
9
9
|
|
10
10
|
def check str, err=nil
|
11
|
-
|
11
|
+
shell.history.clear
|
12
12
|
with_history(str, err)
|
13
13
|
|
14
|
-
|
14
|
+
@shell = nil
|
15
|
+
stub_output
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
shell.history.clear
|
18
|
+
shell.history << 'old history'
|
18
19
|
with_history(str, err, 'old history')
|
19
20
|
end
|
20
21
|
|
@@ -22,18 +23,22 @@ describe Rib::MultilineHistory do
|
|
22
23
|
lines = str.split("\n")
|
23
24
|
lines[0...-1].inject([]){ |result, line|
|
24
25
|
input(line)
|
25
|
-
|
26
|
+
shell.loop_once
|
26
27
|
result << line
|
27
|
-
|
28
|
+
|
29
|
+
expect(shell.history.to_a).eq prefix + result
|
30
|
+
|
28
31
|
result
|
29
32
|
}
|
30
33
|
input_done(lines.last, err)
|
34
|
+
|
31
35
|
history = if lines.size == 1
|
32
36
|
lines.first
|
33
37
|
else
|
34
38
|
"\n#{lines.join("\n")}"
|
35
39
|
end
|
36
|
-
|
40
|
+
|
41
|
+
expect(shell.history.to_a).eq prefix + [history]
|
37
42
|
end
|
38
43
|
|
39
44
|
test_for Rib::History, Rib::Multiline, Rib::MultilineHistory do
|
data/test/test_api.rb
CHANGED
@@ -12,9 +12,45 @@ describe Rib::API do
|
|
12
12
|
"pong_#{meth}"
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
klass = Rib::Shell.dup
|
16
|
+
klass.use(mod)
|
17
|
+
|
18
|
+
expect(klass.new.send(meth)).eq "pong_#{meth}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
would 'emit a warning whenever result is not a string' do
|
23
|
+
object = Class.new{ alias_method :inspect, :object_id }.new
|
24
|
+
|
25
|
+
mock(shell).get_input{'object'}
|
26
|
+
mock(shell).loop_eval('object'){object}
|
27
|
+
mock(shell).puts("=> #{object.object_id}"){}
|
28
|
+
mock($stderr).puts(including("#{object.class}#inspect")){}
|
29
|
+
|
30
|
+
shell.loop_once
|
31
|
+
|
32
|
+
ok
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#warn' do
|
36
|
+
would 'append a warning message to warnings' do
|
37
|
+
shell.warn('test')
|
38
|
+
|
39
|
+
expect(shell.warnings).eq ['test']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#flush_warnings' do
|
44
|
+
before do
|
45
|
+
shell.warn('test')
|
46
|
+
|
47
|
+
mock($stderr).puts('rib: test'){}
|
48
|
+
end
|
49
|
+
|
50
|
+
would 'warn to $stderr from #warnings' do
|
51
|
+
shell.send(:flush_warnings)
|
52
|
+
|
53
|
+
ok
|
18
54
|
end
|
19
55
|
end
|
20
56
|
end
|
data/test/test_plugin.rb
CHANGED
@@ -13,26 +13,38 @@ describe Rib::Plugin do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
would 'have shortcut methods' do
|
16
|
-
@names.each
|
17
|
-
%w[enable disable].each
|
18
|
-
Rib.respond_to?("#{meth}_#{name}")
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
@names.each do |name|
|
17
|
+
%w[enable disable].each do |meth|
|
18
|
+
expect(Rib).respond_to?("#{meth}_#{name}")
|
19
|
+
end
|
20
|
+
|
21
|
+
%w[enabled? disabled?].each do |meth|
|
22
|
+
expect(Rib).respond_to?("#{name}_#{meth}")
|
23
|
+
end
|
24
|
+
end
|
24
25
|
end
|
25
26
|
|
26
27
|
would 'be the same as mod methods' do
|
27
28
|
@mods.shuffle.take(@mods.size/2).each(&:disable)
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
|
30
|
+
@names.each do |name|
|
31
|
+
%w[enabled? disabled?].each do |meth|
|
32
|
+
expect(Rib.send("#{name}_#{meth}")).eq \
|
31
33
|
@mods.find{ |mod|
|
32
34
|
mod.name[/::\w+$/].tr(':', '') ==
|
33
35
|
name.gsub(/([^_]+)/){$1.capitalize}.tr('_', '') }.
|
34
36
|
send(meth)
|
35
|
-
|
36
|
-
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
would 'have backward compatibility for accessing Shell' do
|
42
|
+
mock(Rib).warn(
|
43
|
+
is_a(String), is_a(String), including("#{__FILE__}:47")){ok}
|
44
|
+
|
45
|
+
Module.new.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
46
|
+
extend Rib::Plugin
|
47
|
+
Shell
|
48
|
+
RUBY
|
37
49
|
end
|
38
50
|
end
|
data/test/test_runner.rb
CHANGED
@@ -6,31 +6,31 @@ describe Rib::Runner do
|
|
6
6
|
paste :rib
|
7
7
|
|
8
8
|
before do
|
9
|
-
Rib.
|
10
|
-
@shell = Rib::Shell.new
|
11
|
-
mock(Rib).shell{ @shell }.times(2)
|
9
|
+
mock(Rib).shell{ shell }.times(2)
|
12
10
|
end
|
13
11
|
|
14
12
|
def input *args
|
15
|
-
args.each{ |item| mock(
|
16
|
-
mock(
|
13
|
+
args.each{ |item| mock(shell).get_input{ item } }
|
14
|
+
mock(shell).get_input{}
|
17
15
|
end
|
18
16
|
|
19
17
|
def output *args
|
20
|
-
args.each{ |item| mock(
|
21
|
-
mock(
|
18
|
+
args.each{ |item| mock(shell).puts("=> #{item}"){} }
|
19
|
+
mock(shell).puts{}
|
22
20
|
end
|
23
21
|
|
24
22
|
would '-e' do
|
25
23
|
input('a')
|
26
24
|
output('1')
|
27
|
-
|
25
|
+
|
26
|
+
expect(Rib::Runner.run(%w[-ea=1])).eq shell
|
28
27
|
end
|
29
28
|
|
30
29
|
would '-e nothing' do
|
31
30
|
input
|
32
31
|
output
|
33
|
-
|
32
|
+
|
33
|
+
expect(Rib::Runner.run(%w[-e])).eq shell
|
34
34
|
end
|
35
35
|
|
36
36
|
def verify_app_e argv
|
@@ -38,10 +38,12 @@ describe Rib::Runner do
|
|
38
38
|
output('1')
|
39
39
|
conf = {:name => 'rib'}
|
40
40
|
min = 'rib-min'
|
41
|
+
|
41
42
|
mock(Rib::Runner).which_bin(min){ min }
|
42
43
|
mock(Rib::Runner).load(min){ Rib::Runner.run(argv) }
|
43
44
|
stub(Rib).config{ conf }
|
44
|
-
|
45
|
+
|
46
|
+
expect(Rib::Runner.run(argv)).eq shell
|
45
47
|
end
|
46
48
|
|
47
49
|
would 'min -e' do
|
data/test/test_shell.rb
CHANGED
@@ -5,26 +5,26 @@ require 'rib/shell'
|
|
5
5
|
describe Rib::Shell do
|
6
6
|
paste :rib
|
7
7
|
|
8
|
-
before do
|
9
|
-
Rib.disable_plugins
|
10
|
-
@shell = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
def shell
|
14
|
-
@shell ||= Rib::Shell.new
|
15
|
-
end
|
16
|
-
|
17
8
|
describe '#loop' do
|
18
9
|
def input str
|
19
10
|
mock(shell).get_input{str}
|
20
11
|
shell.loop
|
21
|
-
|
12
|
+
ok
|
22
13
|
end
|
23
|
-
|
24
|
-
would '
|
14
|
+
|
15
|
+
would 'exit' do input('exit' ) end
|
16
|
+
would 'also exit' do input(' exit') end
|
25
17
|
would 'ctrl+d' do mock(shell).puts{} ; input(nil) end
|
26
18
|
would ':q' do shell.config[:exit] << ':q'; input(':q') end
|
27
19
|
would '\q' do shell.config[:exit] << '\q'; input('\q') end
|
20
|
+
|
21
|
+
would 'not puts anything if it is not running' do
|
22
|
+
mock(shell).puts.times(0)
|
23
|
+
|
24
|
+
shell.eval_binding.eval('self').instance_variable_set(:@shell, shell)
|
25
|
+
|
26
|
+
input('@shell.stop; throw :rib_exit')
|
27
|
+
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe '#loop_once' do
|
@@ -34,32 +34,39 @@ describe Rib::Shell do
|
|
34
34
|
else
|
35
35
|
mock(shell).get_input{ str }
|
36
36
|
end
|
37
|
+
|
37
38
|
shell.loop_once
|
38
|
-
|
39
|
+
|
40
|
+
ok
|
39
41
|
end
|
40
42
|
|
41
43
|
would 'handles ctrl+c' do
|
42
44
|
mock(shell).handle_interrupt{}
|
45
|
+
|
43
46
|
input{ raise Interrupt }
|
44
47
|
end
|
45
48
|
|
46
49
|
would 'prints result' do
|
47
50
|
mock(shell).puts('=> "mm"'){}
|
51
|
+
|
48
52
|
input('"m" * 2')
|
49
53
|
end
|
50
54
|
|
51
55
|
would 'error in print_result' do
|
52
56
|
mock(Rib).warn(matching(/Error while printing result.*BOOM/m)){}
|
57
|
+
|
53
58
|
input('obj = Object.new; def obj.inspect; raise "BOOM"; end; obj')
|
54
59
|
end
|
55
60
|
|
56
61
|
would 'not crash if user input is a blackhole' do
|
57
62
|
mock(Rib).warn(matching(/Error while printing result/)){}
|
63
|
+
|
58
64
|
input('Rib::Blackhole')
|
59
65
|
end
|
60
66
|
|
61
67
|
would 'print error from eval' do
|
62
68
|
mock(shell).puts(matching(/RuntimeError/)){}
|
69
|
+
|
63
70
|
input('raise "blah"')
|
64
71
|
end
|
65
72
|
end
|
@@ -67,7 +74,8 @@ describe Rib::Shell do
|
|
67
74
|
describe '#prompt' do
|
68
75
|
would 'be changeable' do
|
69
76
|
shell.config[:prompt] = '> '
|
70
|
-
|
77
|
+
|
78
|
+
expect(shell.prompt).eq '> '
|
71
79
|
end
|
72
80
|
end
|
73
81
|
|
@@ -78,14 +86,50 @@ describe Rib::Shell do
|
|
78
86
|
|
79
87
|
would 'line' do
|
80
88
|
shell.eval_input('10 ** 2')
|
81
|
-
|
89
|
+
|
90
|
+
expect(shell.config[:line]).eq @line + 1
|
82
91
|
end
|
83
92
|
|
84
93
|
would 'print error and increments line' do
|
85
94
|
result, err = shell.eval_input('{')
|
86
|
-
|
87
|
-
|
88
|
-
|
95
|
+
|
96
|
+
expect(result).eq nil
|
97
|
+
expect(err).kind_of?(SyntaxError)
|
98
|
+
expect(shell.config[:line]).eq @line + 1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#running?' do
|
103
|
+
would 'have complete flow' do
|
104
|
+
expect(shell).not.running?
|
105
|
+
|
106
|
+
mock(shell).get_input do
|
107
|
+
expect(shell).running?
|
108
|
+
|
109
|
+
mock(shell).puts{}
|
110
|
+
|
111
|
+
nil
|
112
|
+
end
|
113
|
+
|
114
|
+
shell.loop
|
115
|
+
|
116
|
+
expect(shell).not.running?
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#stop' do
|
121
|
+
would 'stop the loop if it is stopped' do
|
122
|
+
mock(shell).get_input do
|
123
|
+
expect(shell).running?
|
124
|
+
|
125
|
+
shell.stop
|
126
|
+
|
127
|
+
expect(shell).not.running?
|
128
|
+
|
129
|
+
'Rib::Skip'
|
130
|
+
end
|
131
|
+
|
132
|
+
shell.loop
|
89
133
|
end
|
90
134
|
end
|
91
135
|
|
@@ -93,15 +137,18 @@ describe Rib::Shell do
|
|
93
137
|
mock(shell).loop_once{ raise 'boom' }
|
94
138
|
mock(Rib).warn(is_a(String)){}
|
95
139
|
mock(shell).after_loop{}
|
96
|
-
|
140
|
+
|
141
|
+
expect.raise(RuntimeError) do
|
142
|
+
shell.loop
|
143
|
+
end
|
97
144
|
end
|
98
145
|
|
99
146
|
would 'have empty binding' do
|
100
|
-
shell.eval_input('local_variables').first.
|
147
|
+
expect(shell.eval_input('local_variables').first).empty?
|
101
148
|
end
|
102
149
|
|
103
150
|
would 'not pollute main' do
|
104
|
-
shell.eval_input('main').first.
|
151
|
+
expect(shell.eval_input('main').first).eq 'rib'
|
105
152
|
end
|
106
153
|
|
107
154
|
would 'warn on removing main' do
|
@@ -110,11 +157,13 @@ describe Rib::Shell do
|
|
110
157
|
def main; end
|
111
158
|
end
|
112
159
|
RUBY
|
160
|
+
|
113
161
|
mock(Rib).warn(is_a(String)){}
|
114
|
-
|
162
|
+
|
163
|
+
expect(shell.eval_input('main').first).eq 'rib'
|
115
164
|
end
|
116
165
|
|
117
166
|
would 'be main' do
|
118
|
-
shell.eval_input('self.inspect').first.
|
167
|
+
expect(shell.eval_input('self.inspect').first).eq 'main'
|
119
168
|
end
|
120
169
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin Jen-Shin (godfat)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Ruby-Interactive-ruBy -- Yet another interactive Ruby shell
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/rib/runner.rb
|
82
82
|
- lib/rib/shell.rb
|
83
83
|
- lib/rib/test.rb
|
84
|
+
- lib/rib/test/history.rb
|
84
85
|
- lib/rib/test/multiline.rb
|
85
86
|
- lib/rib/version.rb
|
86
87
|
- rib.gemspec
|
@@ -93,8 +94,8 @@ files:
|
|
93
94
|
- test/core/test_readline.rb
|
94
95
|
- test/core/test_squeeze_history.rb
|
95
96
|
- test/core/test_strip_backtrace.rb
|
96
|
-
- test/extra/test_anchor.rb
|
97
97
|
- test/extra/test_autoindent.rb
|
98
|
+
- test/more/test_anchor.rb
|
98
99
|
- test/more/test_beep.rb
|
99
100
|
- test/more/test_caller.rb
|
100
101
|
- test/more/test_color.rb
|
@@ -105,7 +106,7 @@ files:
|
|
105
106
|
- test/test_shell.rb
|
106
107
|
homepage: https://github.com/godfat/rib
|
107
108
|
licenses:
|
108
|
-
- Apache
|
109
|
+
- Apache-2.0
|
109
110
|
metadata: {}
|
110
111
|
post_install_message:
|
111
112
|
rdoc_options: []
|
@@ -135,8 +136,8 @@ test_files:
|
|
135
136
|
- test/core/test_readline.rb
|
136
137
|
- test/core/test_squeeze_history.rb
|
137
138
|
- test/core/test_strip_backtrace.rb
|
138
|
-
- test/extra/test_anchor.rb
|
139
139
|
- test/extra/test_autoindent.rb
|
140
|
+
- test/more/test_anchor.rb
|
140
141
|
- test/more/test_beep.rb
|
141
142
|
- test/more/test_caller.rb
|
142
143
|
- test/more/test_color.rb
|