pry 0.8.4pre1-java → 0.9.0pre1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. data/.gitignore +1 -0
  2. data/README.markdown +1 -1
  3. data/Rakefile +11 -5
  4. data/TODO +28 -2
  5. data/bin/pry +5 -9
  6. data/examples/example_basic.rb +2 -4
  7. data/examples/example_command_override.rb +2 -5
  8. data/examples/example_commands.rb +1 -4
  9. data/examples/example_hooks.rb +2 -5
  10. data/examples/example_image_edit.rb +4 -8
  11. data/examples/example_input.rb +1 -4
  12. data/examples/example_input2.rb +1 -4
  13. data/examples/example_output.rb +1 -4
  14. data/examples/example_print.rb +2 -5
  15. data/examples/example_prompt.rb +2 -5
  16. data/examples/helper.rb +6 -0
  17. data/lib/pry.rb +61 -4
  18. data/lib/pry/command_context.rb +10 -9
  19. data/lib/pry/command_processor.rb +29 -68
  20. data/lib/pry/command_set.rb +79 -28
  21. data/lib/pry/commands.rb +10 -121
  22. data/lib/pry/completion.rb +30 -29
  23. data/lib/pry/config.rb +93 -0
  24. data/lib/pry/default_commands/basic.rb +37 -0
  25. data/lib/pry/default_commands/context.rb +15 -15
  26. data/lib/pry/default_commands/documentation.rb +49 -48
  27. data/lib/pry/default_commands/easter_eggs.rb +1 -20
  28. data/lib/pry/default_commands/gems.rb +32 -41
  29. data/lib/pry/default_commands/input.rb +95 -19
  30. data/lib/pry/default_commands/introspection.rb +54 -60
  31. data/lib/pry/default_commands/ls.rb +2 -2
  32. data/lib/pry/default_commands/shell.rb +29 -39
  33. data/lib/pry/extended_commands/experimental.rb +48 -0
  34. data/lib/pry/extended_commands/user_command_api.rb +22 -0
  35. data/lib/pry/helpers.rb +1 -0
  36. data/lib/pry/helpers/base_helpers.rb +9 -106
  37. data/lib/pry/helpers/command_helpers.rb +96 -59
  38. data/lib/pry/helpers/text.rb +83 -0
  39. data/lib/pry/plugins.rb +79 -0
  40. data/lib/pry/pry_class.rb +96 -111
  41. data/lib/pry/pry_instance.rb +87 -55
  42. data/lib/pry/version.rb +1 -1
  43. data/test/helper.rb +56 -7
  44. data/test/test_command_processor.rb +99 -0
  45. data/test/{test_commandset.rb → test_command_set.rb} +18 -12
  46. data/test/test_default_commands.rb +59 -0
  47. data/test/test_default_commands/test_context.rb +64 -0
  48. data/test/test_default_commands/test_documentation.rb +31 -0
  49. data/test/test_default_commands/test_input.rb +157 -0
  50. data/test/test_default_commands/test_introspection.rb +146 -0
  51. data/test/test_pry.rb +430 -313
  52. metadata +25 -9
  53. data/lib/pry/hooks.rb +0 -17
  54. data/lib/pry/print.rb +0 -16
  55. data/lib/pry/prompts.rb +0 -31
@@ -0,0 +1,59 @@
1
+ require 'helper'
2
+
3
+ describe "Pry::Commands" do
4
+ describe "help" do
5
+ it 'should display help for a specific command' do
6
+ str_output = StringIO.new
7
+ redirect_pry_io(InputTester.new("help ls", "exit-all"), str_output) do
8
+ pry
9
+ end
10
+ str_output.string.each_line.count.should == 1
11
+ str_output.string.should =~ /ls --help/
12
+ end
13
+
14
+ it 'should display help for a regex command with a "listing"' do
15
+ set = Pry::CommandSet.new do
16
+ command /bar(.*)/, "Test listing", :listing => "foo" do
17
+ end
18
+ end
19
+
20
+ str_output = StringIO.new
21
+ redirect_pry_io(InputTester.new("help foo"), str_output) do
22
+ Pry.new(:commands => set).rep
23
+ end
24
+ str_output.string.each_line.count.should == 1
25
+ str_output.string.should =~ /Test listing/
26
+ end
27
+
28
+ it 'should display help for a command with a spaces in its name' do
29
+ set = Pry::CommandSet.new do
30
+ command "command with spaces", "description of a command with spaces" do
31
+ end
32
+ end
33
+
34
+ str_output = StringIO.new
35
+ redirect_pry_io(InputTester.new("help \"command with spaces\""), str_output) do
36
+ Pry.new(:commands => set).rep
37
+ end
38
+ str_output.string.each_line.count.should == 1
39
+ str_output.string.should =~ /description of a command with spaces/
40
+ end
41
+
42
+ it 'should display help for all commands with a description' do
43
+ set = Pry::CommandSet.new do
44
+ command /bar(.*)/, "Test listing", :listing => "foo" do; end
45
+ command "b", "description for b", :listing => "foo" do; end
46
+ command "c" do;end
47
+ command "d", "" do;end
48
+ end
49
+
50
+ str_output = StringIO.new
51
+ redirect_pry_io(InputTester.new("help"), str_output) do
52
+ Pry.new(:commands => set).rep
53
+ end
54
+ str_output.string.should =~ /Test listing/
55
+ str_output.string.should =~ /description for b/
56
+ str_output.string.should =~ /No description/
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,64 @@
1
+ require 'helper'
2
+
3
+ describe "Pry::DefaultCommands::Context" do
4
+ describe "cd" do
5
+ after do
6
+ $obj = nil
7
+ end
8
+
9
+ it 'should cd into simple input' do
10
+ b = Pry.binding_for(Object.new)
11
+ b.eval("x = :mon_ouie")
12
+
13
+ redirect_pry_io(InputTester.new("cd x", "$obj = self", "exit-all"), StringIO.new) do
14
+ b.pry
15
+ end
16
+
17
+ $obj.should == :mon_ouie
18
+ end
19
+
20
+ it 'should break out of session with cd ..' do
21
+ b = Pry.binding_for(:outer)
22
+ b.eval("x = :inner")
23
+
24
+ redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd ..", "$outer = self", "exit-all"), StringIO.new) do
25
+ b.pry
26
+ end
27
+ $inner.should == :inner
28
+ $outer.should == :outer
29
+ end
30
+
31
+ it 'should break out to outer-most session with cd /' do
32
+ b = Pry.binding_for(:outer)
33
+ b.eval("x = :inner")
34
+
35
+ redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd 5", "$five = self", "cd /", "$outer = self", "exit-all"), StringIO.new) do
36
+ b.pry
37
+ end
38
+ $inner.should == :inner
39
+ $five.should == 5
40
+ $outer.should == :outer
41
+ end
42
+
43
+ it 'should start a session on TOPLEVEL_BINDING with cd ::' do
44
+ b = Pry.binding_for(:outer)
45
+
46
+ redirect_pry_io(InputTester.new("cd ::", "$obj = self", "exit-all"), StringIO.new) do
47
+ 5.pry
48
+ end
49
+ $obj.should == TOPLEVEL_BINDING.eval('self')
50
+ end
51
+
52
+ it 'should cd into complex input (with spaces)' do
53
+ o = Object.new
54
+ def o.hello(x, y, z)
55
+ :mon_ouie
56
+ end
57
+
58
+ redirect_pry_io(InputTester.new("cd hello 1, 2, 3", "$obj = self", "exit-all"), StringIO.new) do
59
+ o.pry
60
+ end
61
+ $obj.should == :mon_ouie
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ describe "Pry::DefaultCommands::Documentation" do
4
+ describe "show-doc" do
5
+ it 'should output a method\'s documentation' do
6
+ str_output = StringIO.new
7
+ redirect_pry_io(InputTester.new("show-doc sample_method", "exit-all"), str_output) do
8
+ pry
9
+ end
10
+
11
+ str_output.string.should =~ /sample doc/
12
+ end
13
+
14
+ it 'should output a method\'s documentation if inside method without needing to use method name' do
15
+ $str_output = StringIO.new
16
+
17
+ o = Object.new
18
+
19
+ # sample comment
20
+ def o.sample
21
+ redirect_pry_io(InputTester.new("show-doc", "exit-all"), $str_output) do
22
+ binding.pry
23
+ end
24
+ end
25
+ o.sample
26
+
27
+ $str_output.string.should =~ /sample comment/
28
+ $str_output = nil
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,157 @@
1
+ require 'helper'
2
+
3
+ describe "Pry::DefaultCommands::Input" do
4
+
5
+ describe "amend-line-N" do
6
+ it 'should correctly amend the last line of input when no line number specified ' do
7
+ str_output = StringIO.new
8
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "amend-line puts :blah", "show-input", "exit-all"), str_output) do
9
+ pry
10
+ end
11
+ str_output.string.should =~ /\A\d+: def hello\n\d+: puts :blah/
12
+ end
13
+
14
+ it 'should correctly amend the specified line of input when line number given ' do
15
+ str_output = StringIO.new
16
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line-0 def goodbye", "show-input", "exit-all"), str_output) do
17
+ pry
18
+ end
19
+ str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/
20
+ end
21
+ end
22
+
23
+ describe "show-input" do
24
+ it 'should correctly show the current lines in the input buffer' do
25
+ str_output = StringIO.new
26
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "show-input", "exit-all"), str_output) do
27
+ pry
28
+ end
29
+ str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing/
30
+ end
31
+ end
32
+
33
+ describe "!" do
34
+ it 'should correctly clear the input buffer ' do
35
+ str_output = StringIO.new
36
+ redirect_pry_io(InputTester.new("def hello", "puts :bing", "!", "show-input", "exit-all"), str_output) do
37
+ pry
38
+ end
39
+ stripped_output = str_output.string.strip!
40
+ stripped_output.each_line.count.should == 1
41
+ stripped_output.should =~ /Input buffer cleared!/
42
+ end
43
+ end
44
+
45
+ describe "hist" do
46
+ push_first_hist_line = lambda do |hist, line|
47
+ hist.push line
48
+ end
49
+
50
+ before do
51
+ Readline::HISTORY.shift until Readline::HISTORY.empty?
52
+ @hist = Readline::HISTORY
53
+ end
54
+
55
+ it 'should display the correct history' do
56
+ push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'")
57
+ @hist.push "hello"
58
+ @hist.push "world"
59
+ str_output = StringIO.new
60
+ redirect_pry_io(InputTester.new("hist", "exit-all"), str_output) do
61
+ pry
62
+ end
63
+ str_output.string.should =~ /hello\n.*world/
64
+ end
65
+
66
+ it 'should replay history correctly (single item)' do
67
+ push_first_hist_line.call(@hist, ":hello")
68
+ @hist.push ":blah"
69
+ @hist.push ":bucket"
70
+ @hist.push ":ostrich"
71
+ str_output = StringIO.new
72
+ redirect_pry_io(InputTester.new("hist --replay -1", "exit-all"), str_output) do
73
+ pry
74
+ end
75
+ str_output.string.should =~ /ostrich/
76
+ end
77
+
78
+ it 'should replay a range of history correctly (range of items)' do
79
+ push_first_hist_line.call(@hist, "'bug in 1.8 means this line is ignored'")
80
+ @hist.push ":hello"
81
+ @hist.push ":carl"
82
+ str_output = StringIO.new
83
+ redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all"), str_output) do
84
+ pry
85
+ end
86
+ str_output.string.should =~ /:hello\n.*:carl/
87
+ end
88
+
89
+ it 'should grep for correct lines in history' do
90
+ push_first_hist_line.call(@hist, "apple")
91
+ @hist.push "abby"
92
+ @hist.push "box"
93
+ @hist.push "button"
94
+ @hist.push "pepper"
95
+ @hist.push "orange"
96
+ @hist.push "grape"
97
+
98
+ str_output = StringIO.new
99
+ redirect_pry_io(InputTester.new("hist --grep o", "exit-all"), str_output) do
100
+ pry
101
+ end
102
+
103
+ str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/
104
+ end
105
+
106
+ it 'should return last N lines in history with --tail switch' do
107
+ push_first_hist_line.call(@hist, "0")
108
+ ("a".."z").each do |v|
109
+ @hist.push v
110
+ end
111
+
112
+ str_output = StringIO.new
113
+ redirect_pry_io(InputTester.new("hist --tail 3", "exit-all"), str_output) do
114
+ pry
115
+ end
116
+
117
+ str_output.string.each_line.count.should == 3
118
+ str_output.string.should =~ /x\n\d+:.*y\n\d+:.*z/
119
+ end
120
+
121
+ # strangeness in this test is due to bug in Readline::HISTORY not
122
+ # always registering first line of input
123
+ it 'should return first N lines in history with --head switch' do
124
+ push_first_hist_line.call(@hist, "0")
125
+ ("a".."z").each do |v|
126
+ @hist.push v
127
+ end
128
+
129
+ str_output = StringIO.new
130
+ redirect_pry_io(InputTester.new("hist --head 4", "exit-all"), str_output) do
131
+ pry
132
+ end
133
+
134
+ str_output.string.each_line.count.should == 4
135
+ str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/
136
+ end
137
+
138
+ # strangeness in this test is due to bug in Readline::HISTORY not
139
+ # always registering first line of input
140
+ it 'should show lines between lines A and B with the --show switch' do
141
+ push_first_hist_line.call(@hist, "0")
142
+ ("a".."z").each do |v|
143
+ @hist.push v
144
+ end
145
+
146
+ str_output = StringIO.new
147
+ redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), str_output) do
148
+ pry
149
+ end
150
+
151
+ str_output.string.each_line.count.should == 4
152
+ str_output.string.should =~ /b\n\d+:.*c\n\d+:.*d/
153
+ end
154
+ end
155
+
156
+
157
+ end
@@ -0,0 +1,146 @@
1
+ require 'helper'
2
+
3
+ describe "Pry::DefaultCommands::Introspection" do
4
+ describe "show-method" do
5
+ it 'should output a method\'s source' do
6
+ str_output = StringIO.new
7
+ redirect_pry_io(InputTester.new("show-method sample_method", "exit-all"), str_output) do
8
+ pry
9
+ end
10
+
11
+ str_output.string.should =~ /def sample/
12
+ end
13
+
14
+ it 'should output a method\'s source with line numbers' do
15
+ str_output = StringIO.new
16
+ redirect_pry_io(InputTester.new("show-method -l sample_method", "exit-all"), str_output) do
17
+ pry
18
+ end
19
+
20
+ str_output.string.should =~ /\d+: def sample/
21
+ end
22
+
23
+ it 'should output a method\'s source if inside method without needing to use method name' do
24
+ $str_output = StringIO.new
25
+
26
+ o = Object.new
27
+ def o.sample
28
+ redirect_pry_io(InputTester.new("show-method", "exit-all"), $str_output) do
29
+ binding.pry
30
+ end
31
+ end
32
+ o.sample
33
+
34
+ $str_output.string.should =~ /def o.sample/
35
+ $str_output = nil
36
+ end
37
+
38
+ it 'should output a method\'s source if inside method without needing to use method name, and using the -l switch' do
39
+ $str_output = StringIO.new
40
+
41
+ o = Object.new
42
+ def o.sample
43
+ redirect_pry_io(InputTester.new("show-method -l", "exit-all"), $str_output) do
44
+ binding.pry
45
+ end
46
+ end
47
+ o.sample
48
+
49
+ $str_output.string.should =~ /\d+: def o.sample/
50
+ $str_output = nil
51
+ end
52
+
53
+ # dynamically defined method source retrieval is only supported in
54
+ # 1.9 - where Method#source_location is native
55
+ if RUBY_VERSION =~ /1.9/
56
+ it 'should output a method\'s source for a method defined inside pry' do
57
+ str_output = StringIO.new
58
+ redirect_pry_io(InputTester.new("def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do
59
+ TOPLEVEL_BINDING.pry
60
+ end
61
+
62
+ str_output.string.should =~ /def dyna_method/
63
+ Object.remove_method :dyna_method
64
+ end
65
+
66
+ it 'should output a method\'s source for a method defined inside pry, even if exceptions raised before hand' do
67
+ str_output = StringIO.new
68
+ redirect_pry_io(InputTester.new("bad code", "123", "bad code 2", "1 + 2", "def dyna_method", ":testing", "end", "show-method dyna_method"), str_output) do
69
+ TOPLEVEL_BINDING.pry
70
+ end
71
+
72
+ str_output.string.should =~ /def dyna_method/
73
+ Object.remove_method :dyna_method
74
+ end
75
+
76
+ it 'should output an instance method\'s source for a method defined inside pry' do
77
+ str_output = StringIO.new
78
+ redirect_pry_io(InputTester.new("class A", "def yo", "end", "end", "show-method A#yo"), str_output) do
79
+ TOPLEVEL_BINDING.pry
80
+ end
81
+
82
+ str_output.string.should =~ /def yo/
83
+ Object.remove_const :A
84
+ end
85
+
86
+ it 'should output an instance method\'s source for a method defined inside pry using define_method' do
87
+ str_output = StringIO.new
88
+ redirect_pry_io(InputTester.new("class A", "define_method(:yup) {}", "end", "end", "show-method A#yup"), str_output) do
89
+ TOPLEVEL_BINDING.pry
90
+ end
91
+
92
+ str_output.string.should =~ /define_method\(:yup\)/
93
+ Object.remove_const :A
94
+ end
95
+ end
96
+ end
97
+
98
+ # show-command only works in implementations that support Proc#source_location
99
+ if Proc.method_defined?(:source_location)
100
+ describe "show-command" do
101
+ it 'should show source for an ordinary command' do
102
+ set = Pry::CommandSet.new do
103
+ import_from Pry::Commands, "show-command"
104
+ command "foo" do
105
+ :body_of_foo
106
+ end
107
+ end
108
+ str_output = StringIO.new
109
+ redirect_pry_io(InputTester.new("show-command foo"), str_output) do
110
+ Pry.new(:commands => set).rep
111
+ end
112
+ str_output.string.should =~ /:body_of_foo/
113
+ end
114
+
115
+ it 'should show source for a command with spaces in its name' do
116
+ set = Pry::CommandSet.new do
117
+ import_from Pry::Commands, "show-command"
118
+ command "foo bar" do
119
+ :body_of_foo_bar
120
+ end
121
+ end
122
+ str_output = StringIO.new
123
+ redirect_pry_io(InputTester.new("show-command \"foo bar\""), str_output) do
124
+ Pry.new(:commands => set).rep
125
+ end
126
+ str_output.string.should =~ /:body_of_foo_bar/
127
+ end
128
+
129
+ it 'should show source for a command by listing name' do
130
+ set = Pry::CommandSet.new do
131
+ import_from Pry::Commands, "show-command"
132
+ command /foo(.*)/, "", :listing => "bar" do
133
+ :body_of_foo_regex
134
+ end
135
+ end
136
+ str_output = StringIO.new
137
+ redirect_pry_io(InputTester.new("show-command bar"), str_output) do
138
+ Pry.new(:commands => set).rep
139
+ end
140
+ str_output.string.should =~ /:body_of_foo_regex/
141
+ end
142
+ end
143
+ end
144
+
145
+
146
+ end