rib 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGES.md +32 -0
  4. data/README.md +5 -4
  5. data/TODO.md +2 -0
  6. data/lib/rib.rb +1 -1
  7. data/lib/rib/api.rb +29 -8
  8. data/lib/rib/app/auto.rb +2 -3
  9. data/lib/rib/app/rack.rb +2 -3
  10. data/lib/rib/app/rails.rb +2 -3
  11. data/lib/rib/core/completion.rb +6 -13
  12. data/lib/rib/core/history.rb +3 -3
  13. data/lib/rib/core/last_value.rb +3 -3
  14. data/lib/rib/core/multiline.rb +3 -3
  15. data/lib/rib/core/readline.rb +3 -3
  16. data/lib/rib/core/squeeze_history.rb +3 -3
  17. data/lib/rib/core/strip_backtrace.rb +3 -3
  18. data/lib/rib/extra/autoindent.rb +3 -3
  19. data/lib/rib/extra/hirb.rb +3 -3
  20. data/lib/rib/extra/paging.rb +3 -3
  21. data/lib/rib/more/anchor.rb +13 -4
  22. data/lib/rib/more/beep.rb +4 -4
  23. data/lib/rib/more/bottomup_backtrace.rb +3 -3
  24. data/lib/rib/more/caller.rb +3 -3
  25. data/lib/rib/more/color.rb +11 -6
  26. data/lib/rib/more/edit.rb +3 -3
  27. data/lib/rib/more/multiline_history.rb +3 -3
  28. data/lib/rib/more/multiline_history_file.rb +3 -3
  29. data/lib/rib/plugin.rb +15 -4
  30. data/lib/rib/runner.rb +4 -3
  31. data/lib/rib/shell.rb +19 -6
  32. data/lib/rib/test.rb +25 -14
  33. data/lib/rib/test/history.rb +25 -0
  34. data/lib/rib/test/multiline.rb +8 -16
  35. data/lib/rib/version.rb +1 -1
  36. data/rib.gemspec +7 -6
  37. data/task/README.md +5 -5
  38. data/task/gemgem.rb +6 -1
  39. data/test/core/test_completion.rb +13 -6
  40. data/test/core/test_history.rb +42 -52
  41. data/test/core/test_last_value.rb +22 -23
  42. data/test/core/test_readline.rb +7 -14
  43. data/test/core/test_squeeze_history.rb +29 -36
  44. data/test/extra/test_autoindent.rb +8 -3
  45. data/test/more/test_anchor.rb +85 -0
  46. data/test/more/test_beep.rb +1 -1
  47. data/test/more/test_color.rb +16 -0
  48. data/test/more/test_multiline_history.rb +12 -7
  49. data/test/test_api.rb +39 -3
  50. data/test/test_plugin.rb +25 -13
  51. data/test/test_runner.rb +12 -10
  52. data/test/test_shell.rb +72 -23
  53. metadata +6 -5
  54. data/test/extra/test_anchor.rb +0 -18
@@ -4,12 +4,12 @@
4
4
 
5
5
  Provided tasks:
6
6
 
7
- rake clean # Remove ignored files
7
+ rake clean # Trash ignored files
8
8
  rake gem:build # Build gem
9
9
  rake gem:install # Install gem
10
10
  rake gem:release # Release gem
11
11
  rake gem:spec # Generate gemspec
12
- rake test # Run tests in memory
12
+ rake test # Run tests
13
13
 
14
14
  ## REQUIREMENTS:
15
15
 
@@ -25,7 +25,7 @@ And in Rakefile:
25
25
  begin
26
26
  require "#{__dir__}/task/gemgem"
27
27
  rescue LoadError
28
- sh 'git submodule update --init'
28
+ sh 'git submodule update --init --recursive'
29
29
  exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
30
30
  end
31
31
 
@@ -37,9 +37,9 @@ end
37
37
 
38
38
  ## LICENSE:
39
39
 
40
- Apache License 2.0
40
+ Apache License 2.0 (Apache-2.0)
41
41
 
42
- Copyright (c) 2011-2016, Lin Jen-Shin (godfat)
42
+ Copyright (c) 2011-2017, Lin Jen-Shin (godfat)
43
43
 
44
44
  Licensed under the Apache License, Version 2.0 (the "License");
45
45
  you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ module Gemgem
28
28
 
29
29
  s.description = description.join
30
30
  s.summary = description.first
31
- s.license = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
31
+ s.license = license
32
32
 
33
33
  s.date = Time.now.strftime('%Y-%m-%d')
34
34
  s.files = gem_files
@@ -208,6 +208,11 @@ module Gemgem
208
208
  @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
209
209
  end
210
210
 
211
+ def license
212
+ readme['LICENSE'].sub(/.+\n\n/, '').lines.first.
213
+ split(/[()]/).map(&:strip).reject(&:empty?).last
214
+ end
215
+
211
216
  def all_files
212
217
  @all_files ||= fold_files(glob).sort
213
218
  end
@@ -6,13 +6,20 @@ describe Rib::Completion do
6
6
  paste :rib
7
7
 
8
8
  before do
9
- @completion = Class.new do
10
- include Rib::Completion
11
- end.new
9
+ Rib::Completion.enable
12
10
  end
13
11
 
14
- would 'find correct ripl plugins' do
15
- $LOADED_FEATURES << '/dir/ripl/some_plugin.rb'
16
- @completion.send(:ripl_plugins).should.eq ['ripl/some_plugin.rb']
12
+ would 'start bond' do
13
+ new_shell do |sh|
14
+ eval_binding = sh.method(:eval_binding).source_location
15
+
16
+ mock(Bond).start(having(eval_binding: is_a(Proc))).peek_args do |*args|
17
+ expect(args.first[:eval_binding].source_location).eq eval_binding
18
+
19
+ args
20
+ end
21
+ end
22
+
23
+ expect(Bond).started?
17
24
  end
18
25
  end
@@ -1,71 +1,61 @@
1
1
 
2
2
  require 'rib/test'
3
+ require 'rib/test/history'
3
4
  require 'rib/core/history'
4
- require 'tempfile'
5
5
 
6
- copy :history do
7
- would '#after_loop save history' do
8
- inputs = %w[blih blah]
9
- @shell.history.clear
10
- @shell.history.push(*inputs)
6
+ describe Rib::History do
7
+ paste :rib
11
8
 
12
- @shell.after_loop
13
- File.read(@history_file).should.eq "#{inputs.join("\n")}\n"
14
- end
9
+ test_for Rib::History do
10
+ paste :setup_history
15
11
 
16
- would '#before_loop load previous history' do
17
- File.write(@history_file, "check\nthe\nmike")
18
- @shell.before_loop
19
- @shell.history.to_a.should.eq %w[check the mike]
20
- end
12
+ would '#after_loop save history' do
13
+ inputs = %w[blih blah]
14
+ shell.history.push(*inputs)
21
15
 
22
- would '#before_loop have empty history if no history file exists' do
23
- @shell.before_loop
24
- @shell.history.to_a.should.eq []
25
- end
16
+ shell.after_loop
26
17
 
27
- would '#read_history be accessible to plugins in #before_loop' do
28
- mod = Module.new do
29
- def read_history
30
- config[:history] = ['pong_read_history']
31
- end
18
+ expect(File.read(history_file)).eq "#{inputs.join("\n")}\n"
32
19
  end
33
- shell = Rib::Shell.dup
34
- shell.use(mod)
35
- shell.new.before_loop.history.should.eq ['pong_read_history']
36
- end
37
20
 
38
- would '#write_history be accessible to plugins in #after_loop' do
39
- mod = Module.new do
40
- def write_history
41
- config[:history] = ['pong_write_history']
42
- end
21
+ would '#before_loop load previous history' do
22
+ File.write(history_file, "check\nthe\nmike")
23
+
24
+ shell.before_loop
25
+
26
+ expect(shell.history.to_a).eq %w[check the mike]
43
27
  end
44
- shell = Rib::Shell.dup
45
- shell.use(mod)
46
- shell.new.before_loop.after_loop.history.should.eq ['pong_write_history']
47
- end
48
- end
49
28
 
50
- describe Rib::History do
51
- paste :rib
29
+ would '#before_loop have empty history if no history file exists' do
30
+ expect(shell.history.to_a).eq []
31
+ end
52
32
 
53
- test_for Rib::History do
54
- before do
55
- if readline?
56
- ::Readline::HISTORY.clear
57
- stub_readline
33
+ would '#read_history be accessible to plugins in #before_loop' do
34
+ mod = Module.new do
35
+ def read_history
36
+ config[:history] = ['pong_read_history']
37
+ end
58
38
  end
59
- @tempfile = Tempfile.new('rib')
60
- @history_file = @tempfile.path
61
- @shell = Rib::Shell.new(
62
- :history_file => @history_file).before_loop
63
- end
39
+ klass = Rib::Shell.dup
40
+ klass.use(mod)
64
41
 
65
- after do
66
- @tempfile.unlink
42
+ shell = klass.new.before_loop
43
+
44
+ expect(shell.history).eq ['pong_read_history']
67
45
  end
68
46
 
69
- paste :history
47
+ would '#write_history be accessible to plugins in #after_loop' do
48
+ mod = Module.new do
49
+ def write_history
50
+ config[:history] = ['pong_write_history']
51
+ end
52
+ end
53
+ klass = Rib::Shell.dup
54
+ klass.use(mod)
55
+
56
+ shell = klass.new.before_loop.after_loop
57
+
58
+ expect(shell.history).eq ['pong_write_history']
59
+ end
70
60
  end
71
61
  end
@@ -2,35 +2,34 @@
2
2
  require 'rib/test'
3
3
  require 'rib/core/last_value'
4
4
 
5
- copy :last_value do
6
- would 'set last_value' do
7
- mock(@shell).get_input{'Rib.last_value'}
8
- mock(@shell).get_input{'10**2'}
9
- mock(@shell).get_input{'Rib.last_value'}
10
- @shell.loop_once.should.eq [nil, nil]
11
- @shell.loop_once
12
- @shell.loop_once.should.eq [100, nil]
13
- end
14
-
15
- would 'set last_exception' do
16
- stub(@shell).puts{}.with_any_args
17
- mock(@shell).get_input{'XD'}
18
- mock(@shell).get_input{'Rib.last_exception'}
19
- @shell.loop_once
20
- @shell.loop_once.first.should.kind_of?(NameError)
21
- end
22
- end
23
-
24
5
  describe Rib::LastValue do
25
6
  paste :rib
26
7
 
27
8
  before do
28
- @shell = new_shell
29
- stub(@shell).puts(is_a(String)){}
30
- stub(Rib).shell{ @shell }
9
+ stub_output
10
+ stub(Rib).shell{shell}
31
11
  end
32
12
 
33
13
  test_for Rib::LastValue do
34
- paste :last_value
14
+ would 'set last_value' do
15
+ mock(shell).get_input{'Rib.last_value'}
16
+ mock(shell).get_input{'10**2'}
17
+ mock(shell).get_input{'Rib.last_value'}
18
+
19
+ expect(shell.loop_once).eq [nil, nil]
20
+
21
+ shell.loop_once
22
+
23
+ expect(shell.loop_once).eq [100, nil]
24
+ end
25
+
26
+ would 'set last_exception' do
27
+ mock(shell).get_input{'XD'}
28
+ mock(shell).get_input{'Rib.last_exception'}
29
+
30
+ shell.loop_once
31
+
32
+ expect(shell.loop_once.first).kind_of?(NameError)
33
+ end
35
34
  end
36
35
  end
@@ -2,25 +2,18 @@
2
2
  require 'rib/test'
3
3
  require 'rib/core/readline'
4
4
 
5
- copy :readline do
6
- would '#before_loop set @history' do
7
- @shell.history.should.eq Readline::HISTORY
8
- end
9
-
10
- would '#get_input calling Readline.readline' do
11
- mock(Readline).readline(@shell.prompt, true){'ok'}
12
- @shell.get_input.should.eq 'ok'
13
- end
14
- end
15
-
16
5
  describe Rib::Readline do
17
6
  paste :rib
18
7
 
19
8
  test_for Rib::Readline do
20
- before do
21
- @shell = Rib::Shell.new.before_loop
9
+ would '#before_loop set @history' do
10
+ expect(shell.history).eq Readline::HISTORY
22
11
  end
23
12
 
24
- paste :readline
13
+ would '#get_input calling Readline.readline' do
14
+ mock(Readline).readline(shell.prompt, true){'ok'}
15
+
16
+ expect(shell.get_input).eq 'ok'
17
+ end
25
18
  end
26
19
  end
@@ -1,51 +1,44 @@
1
1
 
2
2
  require 'rib/test'
3
+ require 'rib/test/history'
3
4
  require 'rib/core/squeeze_history'
4
- require 'tempfile'
5
-
6
- copy :squeeze_history do
7
- would 'after_loop saves squeezed history' do
8
- @shell.history.push(*@input)
9
- @shell.after_loop
10
- File.read(@history).should.eq %w[foo bar foo bar].join("\n") + "\n"
11
- end
12
-
13
- would 'loop_once squeeze history' do
14
- times = @input.size
15
- stub(@shell).get_input{ (@shell.history << "'#{@input.shift}'").last }
16
- stub(@shell).print_result{}.with_any_args
17
- times.times{ @shell.loop_once }
18
- @shell.history.to_a.should.eq %w[foo bar foo bar].map{ |i| "'#{i}'" }
19
- end
20
-
21
- would 'be disabled if disabled' do
22
- Rib::SqueezeHistory.disable do
23
- times = @input.size
24
- input = @input.dup
25
- stub(@shell).get_input{ (@shell.history << "'#{@input.shift}'").last }
26
- stub(@shell).print_result{}.with_any_args
27
- times.times{ @shell.loop_once }
28
- @shell.history.to_a.should.eq input.map{ |i| "'#{i}'" }
29
- end
30
- end
31
- end
32
5
 
33
6
  describe Rib::SqueezeHistory do
34
7
  paste :rib
35
8
 
36
9
  test_for Rib::History, Rib::SqueezeHistory do
10
+ paste :setup_history
11
+
37
12
  before do
38
- @tempfile = Tempfile.new('rib')
39
- @history = @tempfile.path
40
- @shell = Rib::Shell.new(:history_file => @history).before_loop
41
- @input = %w[foo bar bar foo bar]
42
- @shell.history.clear
13
+ @input = %w[foo bar bar foo bar]
43
14
  end
44
15
 
45
- after do
46
- @tempfile.unlink
16
+ would 'after_loop saves squeezed history' do
17
+ shell.history.push(*@input)
18
+ shell.after_loop
19
+
20
+ expect(File.read(history_file)).eq %w[foo bar foo bar].join("\n") + "\n"
21
+ end
22
+
23
+ would 'loop_once squeeze history' do
24
+ stub_output
25
+ stub(shell).get_input{ (shell.history << "'#{@input.shift}'").last }
26
+
27
+ @input.size.times{ shell.loop_once }
28
+
29
+ expect(shell.history.to_a).eq %w[foo bar foo bar].map{ |i| "'#{i}'" }
47
30
  end
48
31
 
49
- paste :squeeze_history
32
+ would 'be disabled if disabled' do
33
+ Rib::SqueezeHistory.disable do
34
+ stub_output
35
+ stub(shell).get_input{ (shell.history << "'#{@input.shift}'").last }
36
+ input = @input.dup
37
+
38
+ @input.size.times{ shell.loop_once }
39
+
40
+ expect(shell.history.to_a).eq input.map{ |i| "'#{i}'" }
41
+ end
42
+ end
50
43
  end
51
44
  end
@@ -19,22 +19,27 @@ describe Rib::Autoindent do
19
19
  Rib::Multiline.enable
20
20
  Rib::Autoindent.enable
21
21
  @indent = autoindent.new
22
+
22
23
  mock(@indent).puts(matching(/^\e/)).times(0)
24
+
25
+ expect(@indent.stack_size).eq 0
23
26
  end
24
27
 
25
28
  def ri input, size
26
29
  @indent.eval_input(input)
27
- @indent.stack_size.should.eq size
30
+
31
+ expect(@indent.stack_size).eq size
28
32
  end
29
33
 
30
34
  def le input, size
31
35
  mock(@indent).puts(matching(/^\e/)){}
36
+
32
37
  @indent.eval_input(input)
33
- @indent.stack_size.should.eq size
38
+
39
+ expect(@indent.stack_size).eq size
34
40
  end
35
41
 
36
42
  would 'begin rescue else end' do
37
- @indent.stack_size.should.eq 0
38
43
  ri('begin' , 1)
39
44
  ri( '1' , 1)
40
45
  le('rescue' , 1)
@@ -0,0 +1,85 @@
1
+
2
+ require 'rib/test'
3
+ require 'rib/more/anchor'
4
+ require 'rib/core/multiline'
5
+ require 'rib/test/multiline'
6
+
7
+ describe Rib::Anchor do
8
+ paste :rib
9
+ paste :setup_multiline
10
+
11
+ before do
12
+ Rib::Anchor.enable
13
+ end
14
+
15
+ describe '#anchor?' do
16
+ would 'give true when anchoring' do
17
+ stub(Rib).shell{shell}
18
+
19
+ mock(shell).get_input do
20
+ expect(shell).anchor?
21
+
22
+ mock(shell).puts{}
23
+
24
+ nil
25
+ end
26
+
27
+ Rib.anchor 'test'
28
+ end
29
+
30
+ would 'give false when not anchoring' do
31
+ expect(new_shell).not.anchor?
32
+ end
33
+ end
34
+
35
+ describe '.stop_anchors' do
36
+ def anchor_deeper shell, index
37
+ mock(shell).get_input do
38
+ mock(shell).puts.times(0)
39
+
40
+ expect(shell).anchor?
41
+ expect(shell.loop_eval('self')).eq index
42
+
43
+ mock_deeper(index + 1)
44
+ 'Rib.anchor self + 1'
45
+ end
46
+ end
47
+
48
+ def escape shell
49
+ mock(shell).get_input do
50
+ 'Rib.stop_anchors'
51
+ end
52
+ end
53
+
54
+ def mock_deeper index
55
+ mock(Rib).shell.times(2) # ignore first 2 calls, see Rib.anchor
56
+ mock(Rib).shell.peek_return do |deeper_shell|
57
+ if index < 5
58
+ anchor_deeper(deeper_shell, index)
59
+ else
60
+ escape(deeper_shell)
61
+ end
62
+
63
+ deeper_shell
64
+ end
65
+ end
66
+
67
+ would 'exit all anchors' do
68
+ shell = Rib.shell
69
+
70
+ mock(shell).get_input do
71
+ mock_deeper(0)
72
+ 'Rib.anchor 0'
73
+ end
74
+
75
+ mock(shell).get_input{}
76
+ mock(shell).puts{}
77
+
78
+ shell.loop
79
+ end
80
+ end
81
+
82
+ test_for Rib::Anchor, Rib::Multiline do
83
+ paste :multiline
84
+ end
85
+ end