rib 0.1.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/.gitignore +0 -4
  2. data/CHANGES.md +6 -0
  3. data/README +107 -113
  4. data/README.md +107 -113
  5. data/Rakefile +5 -3
  6. data/TODO.md +6 -0
  7. data/bin/rib-all +5 -0
  8. data/bin/rib-auto +9 -0
  9. data/bin/rib-min +5 -0
  10. data/bin/rib-rails +9 -0
  11. data/bin/rib-ramaze +9 -0
  12. data/lib/rib.rb +70 -6
  13. data/lib/rib/all.rb +0 -1
  14. data/lib/rib/api.rb +60 -64
  15. data/lib/rib/app/auto.rb +25 -0
  16. data/lib/rib/app/rails.rb +41 -0
  17. data/lib/rib/app/ramaze.rb +25 -0
  18. data/lib/rib/config.rb +3 -0
  19. data/lib/rib/core.rb +13 -1
  20. data/lib/rib/core/completion.rb +15 -3
  21. data/lib/rib/core/history.rb +56 -0
  22. data/lib/rib/core/multiline.rb +104 -0
  23. data/lib/rib/core/readline.rb +3 -1
  24. data/lib/rib/core/squeeze_history.rb +45 -0
  25. data/lib/rib/core/strip_backtrace.rb +45 -0
  26. data/lib/rib/core/underscore.rb +17 -8
  27. data/lib/rib/debug.rb +2 -1
  28. data/lib/rib/dep/hirb.rb +24 -0
  29. data/lib/rib/more.rb +4 -3
  30. data/lib/rib/more/anchor.rb +85 -0
  31. data/lib/rib/more/color.rb +44 -43
  32. data/lib/rib/{zore → more}/edit.rb +3 -3
  33. data/lib/rib/more/multiline_history.rb +24 -12
  34. data/lib/rib/more/multiline_history_file.rb +7 -3
  35. data/lib/rib/plugin.rb +2 -4
  36. data/lib/rib/runner.rb +84 -49
  37. data/lib/rib/shell.rb +4 -2
  38. data/lib/rib/test.rb +55 -2
  39. data/lib/rib/test/multiline.rb +140 -0
  40. data/lib/rib/version.rb +1 -1
  41. data/rib.gemspec +54 -22
  42. data/screenshot.png +0 -0
  43. data/task/gemgem.rb +3 -1
  44. data/test/core/{test_history_file.rb → test_history.rb} +29 -19
  45. data/test/core/test_multiline.rb +22 -0
  46. data/test/core/test_readline.rb +13 -8
  47. data/test/{more → core}/test_squeeze_history.rb +24 -18
  48. data/test/core/test_underscore.rb +32 -21
  49. data/test/more/test_multiline_history.rb +42 -0
  50. data/test/test_shell.rb +13 -8
  51. metadata +72 -27
  52. data/2011-02-28.md +0 -203
  53. data/CHANGES +0 -86
  54. data/TODO +0 -6
  55. data/lib/rib/core/history_file.rb +0 -38
  56. data/lib/rib/more/multiline.rb +0 -77
  57. data/lib/rib/more/squeeze_history.rb +0 -37
  58. data/lib/rib/more/strip_backtrace.rb +0 -43
  59. data/lib/rib/zore.rb +0 -3
  60. data/lib/rib/zore/anchor.rb +0 -69
@@ -0,0 +1,22 @@
1
+
2
+ require 'rib/test'
3
+ require 'rib/test/multiline'
4
+ require 'rib/core/multiline'
5
+
6
+ describe Rib::Multiline do
7
+ behaves_like :rib
8
+ behaves_like :setup_multiline
9
+
10
+ def check str, err=nil
11
+ lines = str.split("\n")
12
+ lines[0...-1].each{ |line|
13
+ input(line)
14
+ @shell.loop_once
15
+ }
16
+ input_done(lines.last, err)
17
+ end
18
+
19
+ test_for Rib::Multiline do
20
+ behaves_like :multiline
21
+ end
22
+ end
@@ -2,14 +2,7 @@
2
2
  require 'rib/test'
3
3
  require 'rib/core/readline'
4
4
 
5
- describe Rib::Readline do
6
- behaves_like :rib
7
-
8
- before do
9
- Rib::Readline.enable
10
- @shell = Rib::Shell.new.before_loop
11
- end
12
-
5
+ shared :readline do
13
6
  should '#before_loop set @history' do
14
7
  @shell.history.should.eq Readline::HISTORY
15
8
  end
@@ -19,3 +12,15 @@ describe Rib::Readline do
19
12
  @shell.get_input.should.eq 'ok'
20
13
  end
21
14
  end
15
+
16
+ describe Rib::Readline do
17
+ behaves_like :rib
18
+
19
+ before do
20
+ @shell = Rib::Shell.new.before_loop
21
+ end
22
+
23
+ test_for Rib::Readline do
24
+ behaves_like :readline
25
+ end
26
+ end
@@ -1,22 +1,8 @@
1
1
 
2
2
  require 'rib/test'
3
- require 'rib/more/squeeze_history'
4
-
5
- describe Rib::SqueezeHistory do
6
- behaves_like :rib
7
-
8
- before do
9
- Rib::HistoryFile.enable
10
- Rib::SqueezeHistory.enable
11
- @history = "/tmp/test_rib_#{rand}"
12
- @shell = Rib::Shell.new(:history_file => @history).before_loop
13
- @input = %w[foo bar bar foo bar]
14
- end
15
-
16
- after do
17
- FileUtils.rm_f(@history)
18
- end
3
+ require 'rib/core/squeeze_history'
19
4
 
5
+ shared :squeeze_history do
20
6
  should 'after_loop saves squeezed history' do
21
7
  @shell.history.push(*@input)
22
8
  @shell.after_loop
@@ -26,7 +12,7 @@ describe Rib::SqueezeHistory do
26
12
  should 'loop_once squeeze history' do
27
13
  times = @input.size
28
14
  stub(@shell).get_input{ (@shell.history << "'#{@input.shift}'")[-1] }
29
- stub(@shell).print_result(anything)
15
+ stub(@shell).print_result
30
16
  times.times{ @shell.loop_once }
31
17
  @shell.history.to_a.should.eq %w[foo bar foo bar].map{ |i| "'#{i}'" }
32
18
  end
@@ -36,8 +22,28 @@ describe Rib::SqueezeHistory do
36
22
  times = @input.size
37
23
  input = @input.dup
38
24
  stub(@shell).get_input{ (@shell.history << "'#{@input.shift}'")[-1] }
39
- stub(@shell).print_result(anything)
25
+ stub(@shell).print_result
40
26
  times.times{ @shell.loop_once }
41
27
  @shell.history.to_a.should.eq input.map{ |i| "'#{i}'" }
28
+ Rib::SqueezeHistory.enable
29
+ end
30
+ end
31
+
32
+ describe Rib::SqueezeHistory do
33
+ behaves_like :rib
34
+
35
+ before do
36
+ @history = "/tmp/test_rib_#{rand}"
37
+ @shell = Rib::Shell.new(:history_file => @history).before_loop
38
+ @input = %w[foo bar bar foo bar]
39
+ @shell.history.clear
40
+ end
41
+
42
+ after do
43
+ FileUtils.rm_f(@history)
44
+ end
45
+
46
+ test_for Rib::History, Rib::SqueezeHistory do
47
+ behaves_like :squeeze_history
42
48
  end
43
49
  end
@@ -2,23 +2,15 @@
2
2
  require 'rib/test'
3
3
  require 'rib/core/underscore'
4
4
 
5
- describe Rib::Underscore do
6
- behaves_like :rib
7
-
8
- before do
9
- Rib::Underscore.enable
10
- end
11
-
12
- def setup bound=Object.new
13
- @shell = Rib::Shell.new(
14
- :binding => bound.instance_eval{binding}).before_loop
15
- end
16
-
5
+ shared :underscore do
17
6
  should 'set _' do
18
7
  setup
19
- @shell.eval_input('_').should.eq nil
20
- @shell.eval_input('10 ** 2')
21
- @shell.eval_input('_').should.eq 100
8
+ mock(@shell).get_input{'_'}
9
+ mock(@shell).get_input{'10**2'}
10
+ mock(@shell).get_input{'_'}
11
+ @shell.loop_once.should.eq [nil, nil]
12
+ @shell.loop_once
13
+ @shell.loop_once.should.eq [100, nil]
22
14
  end
23
15
 
24
16
  should 'not set _ if already there' do
@@ -27,15 +19,34 @@ describe Rib::Underscore do
27
19
  'hey'
28
20
  end
29
21
  setup(bound)
30
- @shell.eval_input('_').should.eq 'hey'
31
- @shell.eval_input('10 ** 2')
32
- @shell.eval_input('_').should.eq 'hey'
22
+ mock(@shell).get_input{'_'}
23
+ mock(@shell).get_input{'10**2'}
24
+ mock(@shell).get_input{'_'}
25
+ @shell.loop_once.should.eq ['hey', nil]
26
+ @shell.loop_once
27
+ @shell.loop_once.should.eq ['hey', nil]
33
28
  end
34
29
 
35
30
  should 'set __' do
36
31
  setup
37
- stub(@shell).warn
38
- @shell.eval_input('XD')
39
- @shell.eval_input('__').should.kind_of?(NameError)
32
+ stub(@shell).puts
33
+ mock(@shell).get_input{'XD'}
34
+ mock(@shell).get_input{'__'}
35
+ @shell.loop_once
36
+ @shell.loop_once.first.should.kind_of?(NameError)
37
+ end
38
+ end
39
+
40
+ describe Rib::Underscore do
41
+ behaves_like :rib
42
+
43
+ def setup bound=Object.new
44
+ @shell = Rib::Shell.new(
45
+ :binding => bound.instance_eval{binding}).before_loop
46
+ stub(@shell).puts
47
+ end
48
+
49
+ test_for Rib::Underscore do
50
+ behaves_like :underscore
40
51
  end
41
52
  end
@@ -0,0 +1,42 @@
1
+
2
+ require 'rib/test'
3
+ require 'rib/test/multiline'
4
+ require 'rib/more/multiline_history'
5
+
6
+ describe Rib::MultilineHistory do
7
+ behaves_like :rib
8
+ behaves_like :setup_multiline
9
+
10
+ def check str, err=nil
11
+ @shell.history.clear
12
+ with_history(str, err)
13
+
14
+ setup_shell
15
+
16
+ @shell.history.clear
17
+ @shell.history << 'old history'
18
+ with_history(str, err, 'old history')
19
+ end
20
+
21
+ def with_history str, err, *prefix
22
+ lines = str.split("\n")
23
+ lines[0...-1].inject([]){ |result, line|
24
+ input(line)
25
+ @shell.loop_once
26
+ result << line
27
+ @shell.history.to_a.should.eq prefix + result
28
+ result
29
+ }
30
+ input_done(lines.last, err)
31
+ history = if lines.size == 1
32
+ lines.first
33
+ else
34
+ "\n#{lines.join("\n")}"
35
+ end
36
+ @shell.history.to_a.should.eq prefix + [history]
37
+ end
38
+
39
+ test_for Rib::History, Rib::Multiline, Rib::MultilineHistory do
40
+ behaves_like :multiline
41
+ end
42
+ end
data/test/test_shell.rb CHANGED
@@ -6,13 +6,15 @@ describe Rib::Shell do
6
6
  behaves_like :rib
7
7
 
8
8
  before do
9
+ Rib.disable_plugins
9
10
  @shell = Rib::Shell.new
10
11
  end
11
12
 
12
13
  describe '#loop' do
13
14
  def input str
14
15
  mock(@shell).get_input{str}
15
- @shell.loop.should.eq @shell
16
+ @shell.loop
17
+ true.should.eq true
16
18
  end
17
19
  should 'exit' do input('exit') end
18
20
  should 'quit' do input('quit') end
@@ -26,7 +28,8 @@ describe Rib::Shell do
26
28
  else
27
29
  mock(@shell).get_input{ str }
28
30
  end
29
- @shell.loop_once.should.eq nil
31
+ @shell.loop_once
32
+ true.should.eq true
30
33
  end
31
34
 
32
35
  should 'handles ctrl+c' do
@@ -40,12 +43,12 @@ describe Rib::Shell do
40
43
  end
41
44
 
42
45
  should 'error in print_result' do
43
- mock(@shell).warn(/rib: Error while printing result.*BOOM/m)
46
+ mock(Rib).warn(/Error while printing result.*BOOM/m)
44
47
  input('obj = Object.new; def obj.inspect; raise "BOOM"; end; obj')
45
48
  end
46
49
 
47
50
  should 'print error from eval' do
48
- mock(@shell).warn(/RuntimeError/)
51
+ mock(@shell).puts(/RuntimeError/)
49
52
  input('raise "blah"')
50
53
  end
51
54
  end
@@ -68,15 +71,17 @@ describe Rib::Shell do
68
71
  end
69
72
 
70
73
  should 'print error and increments line' do
71
- mock(@shell).warn(/^SyntaxError:/)
72
- @shell.eval_input('{').should.eq nil
73
- @shell.config[:line] .should.eq @line + 1
74
+ result, err = @shell.eval_input('{')
75
+ result.should.eq nil
76
+ err.should.kind_of?(SyntaxError)
77
+ @shell.config[:line].should.eq @line + 1
74
78
  end
75
79
  end
76
80
 
77
81
  should 'call after_loop even if in_loop raises' do
78
82
  mock(@shell).loop_once{ raise 'boom' }
83
+ mock(Rib).warn(is_a(String))
79
84
  mock(@shell).after_loop
80
- lambda{ @shell.loop }.should.raise(RuntimeError)
85
+ lambda{@shell.loop}.should.raise(RuntimeError)
81
86
  end
82
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-06 00:00:00.000000000Z
12
+ date: 2011-08-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bond
16
- requirement: &2157065040 !ruby/object:Gem::Requirement
16
+ requirement: &2169075740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
- type: :runtime
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2169075740
25
+ - !ruby/object:Gem::Dependency
26
+ name: hirb
27
+ requirement: &2169075260 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
23
34
  prerelease: false
24
- version_requirements: *2157065040
35
+ version_requirements: *2169075260
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: bacon
27
- requirement: &2157064560 !ruby/object:Gem::Requirement
38
+ requirement: &2169074780 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *2157064560
46
+ version_requirements: *2169074780
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: rr
38
- requirement: &2157064080 !ruby/object:Gem::Requirement
49
+ requirement: &2169074300 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,66 +54,98 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *2157064080
47
- description: ripl plugins collection, take you want, leave you don't.
57
+ version_requirements: *2169074300
58
+ description: ! 'Ruby-Interactive-ruBy -- Yet another interactive Ruby shell
59
+
60
+
61
+ Rib is based on the design of [ripl][] and the work of [ripl-rc][], some of
62
+
63
+ the features are also inspired by [pry][]. The aim of Rib is to be fully
64
+
65
+ featured and yet very easy to opt-out or opt-in other features. It shall
66
+
67
+ be simple, lightweight and modular so that everyone could customize Rib.
68
+
69
+
70
+ [ripl]: https://github.com/cldwalker/ripl
71
+
72
+ [ripl-rc]: https://github.com/godfat/ripl-rc
73
+
74
+ [pry]: https://github.com/pry/pry'
48
75
  email:
49
76
  - godfat (XD) godfat.org
50
77
  executables:
51
78
  - rib
79
+ - rib-all
80
+ - rib-auto
81
+ - rib-min
82
+ - rib-rails
83
+ - rib-ramaze
52
84
  extensions: []
53
85
  extra_rdoc_files:
54
- - CHANGES
55
86
  - CONTRIBUTORS
56
87
  - LICENSE
57
- - TODO
88
+ - CHANGES.md
89
+ - TODO.md
58
90
  files:
59
91
  - .gitignore
60
92
  - .gitmodules
61
93
  - .travis.yml
62
- - 2011-02-28.md
63
- - CHANGES
94
+ - CHANGES.md
64
95
  - CONTRIBUTORS
65
96
  - Gemfile
66
97
  - LICENSE
67
98
  - README
68
99
  - README.md
69
100
  - Rakefile
70
- - TODO
101
+ - TODO.md
71
102
  - bin/rib
103
+ - bin/rib-all
104
+ - bin/rib-auto
105
+ - bin/rib-min
106
+ - bin/rib-rails
107
+ - bin/rib-ramaze
72
108
  - lib/rib.rb
73
109
  - lib/rib/all.rb
74
110
  - lib/rib/api.rb
111
+ - lib/rib/app/auto.rb
112
+ - lib/rib/app/rails.rb
113
+ - lib/rib/app/ramaze.rb
114
+ - lib/rib/config.rb
75
115
  - lib/rib/core.rb
76
116
  - lib/rib/core/completion.rb
77
- - lib/rib/core/history_file.rb
117
+ - lib/rib/core/history.rb
118
+ - lib/rib/core/multiline.rb
78
119
  - lib/rib/core/readline.rb
120
+ - lib/rib/core/squeeze_history.rb
121
+ - lib/rib/core/strip_backtrace.rb
79
122
  - lib/rib/core/underscore.rb
80
123
  - lib/rib/debug.rb
124
+ - lib/rib/dep/hirb.rb
81
125
  - lib/rib/more.rb
126
+ - lib/rib/more/anchor.rb
82
127
  - lib/rib/more/color.rb
83
- - lib/rib/more/multiline.rb
128
+ - lib/rib/more/edit.rb
84
129
  - lib/rib/more/multiline_history.rb
85
130
  - lib/rib/more/multiline_history_file.rb
86
- - lib/rib/more/squeeze_history.rb
87
- - lib/rib/more/strip_backtrace.rb
88
131
  - lib/rib/plugin.rb
89
132
  - lib/rib/runner.rb
90
133
  - lib/rib/shell.rb
91
134
  - lib/rib/test.rb
135
+ - lib/rib/test/multiline.rb
92
136
  - lib/rib/version.rb
93
- - lib/rib/zore.rb
94
- - lib/rib/zore/anchor.rb
95
- - lib/rib/zore/edit.rb
96
137
  - rib.gemspec
97
138
  - screenshot.png
98
139
  - task/.gitignore
99
140
  - task/gemgem.rb
100
141
  - test/core/test_completion.rb
101
- - test/core/test_history_file.rb
142
+ - test/core/test_history.rb
143
+ - test/core/test_multiline.rb
102
144
  - test/core/test_readline.rb
145
+ - test/core/test_squeeze_history.rb
103
146
  - test/core/test_underscore.rb
104
147
  - test/more/test_color.rb
105
- - test/more/test_squeeze_history.rb
148
+ - test/more/test_multiline_history.rb
106
149
  - test/test_api.rb
107
150
  - test/test_plugin.rb
108
151
  - test/test_shell.rb
@@ -131,14 +174,16 @@ rubyforge_project:
131
174
  rubygems_version: 1.8.7
132
175
  signing_key:
133
176
  specification_version: 3
134
- summary: ripl plugins collection, take you want, leave you don't.
177
+ summary: Ruby-Interactive-ruBy -- Yet another interactive Ruby shell
135
178
  test_files:
136
179
  - test/core/test_completion.rb
137
- - test/core/test_history_file.rb
180
+ - test/core/test_history.rb
181
+ - test/core/test_multiline.rb
138
182
  - test/core/test_readline.rb
183
+ - test/core/test_squeeze_history.rb
139
184
  - test/core/test_underscore.rb
140
185
  - test/more/test_color.rb
141
- - test/more/test_squeeze_history.rb
186
+ - test/more/test_multiline_history.rb
142
187
  - test/test_api.rb
143
188
  - test/test_plugin.rb
144
189
  - test/test_shell.rb