pry 0.8.4pre1-i386-mingw32 → 0.9.0-i386-mingw32

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 +1 -0
  2. data/CHANGELOG +25 -6
  3. data/README.markdown +11 -4
  4. data/Rakefile +15 -19
  5. data/TODO +28 -2
  6. data/bin/pry +28 -11
  7. data/examples/example_basic.rb +2 -4
  8. data/examples/example_command_override.rb +2 -5
  9. data/examples/example_commands.rb +1 -4
  10. data/examples/example_hooks.rb +2 -5
  11. data/examples/example_image_edit.rb +4 -8
  12. data/examples/example_input.rb +1 -4
  13. data/examples/example_input2.rb +1 -4
  14. data/examples/example_output.rb +1 -4
  15. data/examples/example_print.rb +2 -5
  16. data/examples/example_prompt.rb +2 -5
  17. data/examples/helper.rb +6 -0
  18. data/lib/pry.rb +59 -3
  19. data/lib/pry/command_context.rb +10 -9
  20. data/lib/pry/command_processor.rb +51 -73
  21. data/lib/pry/command_set.rb +79 -28
  22. data/lib/pry/commands.rb +9 -123
  23. data/lib/pry/completion.rb +30 -29
  24. data/lib/pry/config.rb +100 -0
  25. data/lib/pry/default_commands/basic.rb +37 -0
  26. data/lib/pry/default_commands/context.rb +16 -15
  27. data/lib/pry/default_commands/documentation.rb +73 -54
  28. data/lib/pry/default_commands/easter_eggs.rb +1 -20
  29. data/lib/pry/default_commands/gems.rb +31 -40
  30. data/lib/pry/default_commands/input.rb +223 -15
  31. data/lib/pry/default_commands/introspection.rb +108 -73
  32. data/lib/pry/default_commands/ls.rb +25 -11
  33. data/lib/pry/default_commands/shell.rb +29 -39
  34. data/lib/pry/extended_commands/experimental.rb +17 -0
  35. data/lib/pry/extended_commands/user_command_api.rb +22 -0
  36. data/lib/pry/helpers.rb +1 -0
  37. data/lib/pry/helpers/base_helpers.rb +15 -104
  38. data/lib/pry/helpers/command_helpers.rb +96 -59
  39. data/lib/pry/helpers/text.rb +83 -0
  40. data/lib/pry/history_array.rb +105 -0
  41. data/lib/pry/plugins.rb +79 -0
  42. data/lib/pry/pry_class.rb +102 -114
  43. data/lib/pry/pry_instance.rb +123 -55
  44. data/lib/pry/version.rb +1 -1
  45. data/pry.gemspec +45 -0
  46. data/test/helper.rb +57 -7
  47. data/test/test_command_processor.rb +205 -0
  48. data/test/{test_commandset.rb → test_command_set.rb} +18 -12
  49. data/test/test_default_commands.rb +59 -0
  50. data/test/test_default_commands/test_context.rb +64 -0
  51. data/test/test_default_commands/test_documentation.rb +31 -0
  52. data/test/test_default_commands/test_gems.rb +14 -0
  53. data/test/test_default_commands/test_input.rb +327 -0
  54. data/test/test_default_commands/test_introspection.rb +155 -0
  55. data/test/test_history_array.rb +65 -0
  56. data/test/test_pry.rb +548 -313
  57. metadata +48 -15
  58. data/lib/pry/hooks.rb +0 -17
  59. data/lib/pry/print.rb +0 -16
  60. data/lib/pry/prompts.rb +0 -31
@@ -0,0 +1,205 @@
1
+ require 'helper'
2
+
3
+ describe "Pry::CommandProcessor" do
4
+ before do
5
+ @pry = Pry.new
6
+ @pry.commands = Pry::CommandSet.new
7
+ @command_processor = Pry::CommandProcessor.new(@pry)
8
+ end
9
+
10
+ after do
11
+ @pry.commands = Pry::CommandSet.new
12
+ end
13
+
14
+ it 'should accurately determine if a command is valid' do
15
+ @pry.commands.command("test-command") {}
16
+ valid = @command_processor.valid_command? "test-command"
17
+ valid.should == true
18
+
19
+ valid = @command_processor.valid_command? "blah"
20
+ valid.should == false
21
+
22
+
23
+ a = "test-command"
24
+
25
+ # not passing in a binding so 'a' shouldn't exist and no command
26
+ # will be matched
27
+ valid = @command_processor.valid_command?('#{a}')
28
+ valid.should == false
29
+
30
+ # passing in the optional binding (against which interpolation is performed)
31
+ valid = @command_processor.valid_command? '#{a}', binding
32
+ valid.should == true
33
+ end
34
+
35
+ it 'should correctly match a simple string command' do
36
+ @pry.commands.command("test-command") {}
37
+ command, captures, pos = @command_processor.command_matched "test-command", binding
38
+
39
+ command.name.should == "test-command"
40
+ captures.should == []
41
+ pos.should == "test-command".length
42
+ end
43
+
44
+ it 'should correctly match a simple string command with parameters' do
45
+ @pry.commands.command("test-command") { |arg|}
46
+ command, captures, pos = @command_processor.command_matched "test-command hello", binding
47
+
48
+ command.name.should == "test-command"
49
+ captures.should == []
50
+ pos.should == "test-command".length
51
+ end
52
+
53
+ it 'should not match when the relevant command does not exist' do
54
+ command, captures, pos = @command_processor.command_matched "test-command", binding
55
+
56
+ command.should == nil
57
+ captures.should == nil
58
+ end
59
+
60
+ it 'should correctly match a regex command' do
61
+ @pry.commands.command(/rue(.?)/) { }
62
+ command, captures, pos = @command_processor.command_matched "rue hello", binding
63
+
64
+ command.name.should == /rue(.?)/
65
+ captures.should == [""]
66
+ pos.should == 3
67
+ end
68
+
69
+ it 'should correctly match a regex command and extract the capture groups' do
70
+ @pry.commands.command(/rue(.?)/) { }
71
+ command, captures, pos = @command_processor.command_matched "rue5 hello", binding
72
+
73
+ command.name.should == /rue(.?)/
74
+ captures.should == ["5"]
75
+ pos.should == 4
76
+ end
77
+
78
+ it 'should correctly match a string command with spaces in its name' do
79
+ @pry.commands.command("test command") {}
80
+ command, captures, pos = @command_processor.command_matched "test command", binding
81
+
82
+ command.name.should == "test command"
83
+ captures.should == []
84
+ pos.should == command.name.length
85
+ end
86
+
87
+ it 'should correctly match a string command with spaces in its name with parameters' do
88
+ @pry.commands.command("test command") {}
89
+ command, captures, pos = @command_processor.command_matched "test command param1 param2", binding
90
+
91
+ command.name.should == "test command"
92
+ captures.should == []
93
+ pos.should == command.name.length
94
+ end
95
+
96
+ it 'should correctly match a regex command with spaces in its name' do
97
+ regex_command_name = /test\s+(.+)\s+command/
98
+ @pry.commands.command(regex_command_name) {}
99
+
100
+ sample_text = "test friendship command"
101
+ command, captures, pos = @command_processor.command_matched sample_text, binding
102
+
103
+ command.name.should == regex_command_name
104
+ captures.should == ["friendship"]
105
+ pos.should == sample_text.size
106
+ end
107
+
108
+ it 'should correctly match a complex regex command' do
109
+ regex_command_name = /\.(.*)/
110
+ @pry.commands.command(regex_command_name) {}
111
+
112
+ sample_text = ".cd ~/pry"
113
+ command, captures, pos = @command_processor.command_matched sample_text, binding
114
+
115
+ command.name.should == regex_command_name
116
+ captures.should == ["cd ~/pry"]
117
+ pos.should == sample_text.size
118
+ end
119
+
120
+ it 'should correctly match a command whose name is interpolated' do
121
+ @pry.commands.command("blah") {}
122
+ a = "bl"
123
+ b = "ah"
124
+ command, captures, pos = @command_processor.command_matched '#{a}#{b}', binding
125
+
126
+ command.name.should == "blah"
127
+ captures.should == []
128
+ pos.should == command.name.length
129
+ end
130
+
131
+ it 'should correctly match a regex command and interpolation should not break the regex' do
132
+ regex_command_name = /blah(\d)/
133
+ @pry.commands.command(regex_command_name) {}
134
+
135
+ sample_text = "blah5"
136
+ a = "5"
137
+ command, captures, pos = @command_processor.command_matched 'blah#{a}', binding
138
+
139
+ command.name.should == regex_command_name
140
+ captures.should == ["5"]
141
+ pos.should == sample_text.size
142
+ end
143
+
144
+ it 'should NOT match a regex command that is interpolated when :interpolate => false' do
145
+ regex_command_name = /blah(\d)/
146
+ @pry.commands.command(regex_command_name, "", :interpolate => false) {}
147
+
148
+ sample_text = "blah5"
149
+ a = "5"
150
+ command, captures, pos = @command_processor.command_matched 'blah#{a}', binding
151
+
152
+ command.should == nil
153
+ end
154
+
155
+ it 'should correctly match a regex command and interpolation should not break the regex where entire regex command is interpolated' do
156
+ regex_command_name = /blah(\d)/
157
+ @pry.commands.command(regex_command_name) {}
158
+
159
+ sample_text = "blah5"
160
+ a = "bl"
161
+ b = "ah"
162
+ c = "5"
163
+
164
+ command, captures, pos = @command_processor.command_matched '#{a}#{b}#{c}', binding
165
+
166
+ command.name.should == regex_command_name
167
+ captures.should == ["5"]
168
+ pos.should == sample_text.size
169
+ end
170
+
171
+ it 'should NOT match a regex command where entire regex command is interpolated and :interpolate => false' do
172
+ regex_command_name = /blah(\d)/
173
+ @pry.commands.command(regex_command_name, "", :interpolate => false) {}
174
+
175
+ sample_text = "blah5"
176
+ a = "bl"
177
+ b = "ah"
178
+ c = "5"
179
+
180
+ command, captures, pos = @command_processor.command_matched '#{a}#{b}#{c}', binding
181
+ command.should == nil
182
+ end
183
+
184
+ it 'should NOT match a command whose name is interpolated when :interpolate => false' do
185
+ @pry.commands.command("boast", "", :interpolate => false) {}
186
+ a = "boa"
187
+ b = "st"
188
+
189
+ # remember to use '' instead of "" when testing interpolation or
190
+ # you'll cause yourself incredible confusion
191
+ command, captures, pos = @command_processor.command_matched '#{a}#{b}', binding
192
+
193
+ command.should == nil
194
+ end
195
+
196
+
197
+ it 'commands that have :interpolate => false should not be interpolated (interpolate_string should *not* be called)' do
198
+ @pry.commands.command("boast", "", :interpolate => false) {}
199
+
200
+ # remember to use '' instead of "" when testing interpolation or
201
+ # you'll cause yourself incredible confusion
202
+ lambda { @command_processor.command_matched('boast #{c}', binding) }.should.not.raise NameError
203
+ end
204
+
205
+ end
@@ -2,11 +2,7 @@ require 'helper'
2
2
 
3
3
  describe Pry::CommandSet do
4
4
  before do
5
- @set = Pry::CommandSet.new(:some_name)
6
- end
7
-
8
- it 'should use the name specified at creation' do
9
- @set.name.should == :some_name
5
+ @set = Pry::CommandSet.new
10
6
  end
11
7
 
12
8
  it 'should call the block used for the command when it is called' do
@@ -35,7 +31,7 @@ describe Pry::CommandSet do
35
31
  @set.run_command true, 'foo'
36
32
  end
37
33
 
38
- it 'should raise an error when calling an undefined comand' do
34
+ it 'should raise an error when calling an undefined command' do
39
35
  @set.command('foo') {}
40
36
  lambda {
41
37
  @set.run_command nil, 'bar'
@@ -54,7 +50,7 @@ describe Pry::CommandSet do
54
50
  it 'should be able to import some commands from other sets' do
55
51
  run = false
56
52
 
57
- other_set = Pry::CommandSet.new :foo do
53
+ other_set = Pry::CommandSet.new do
58
54
  command('foo') { run = true }
59
55
  command('bar') {}
60
56
  end
@@ -72,7 +68,7 @@ describe Pry::CommandSet do
72
68
  it 'should be able to import a whole set' do
73
69
  run = []
74
70
 
75
- other_set = Pry::CommandSet.new :foo do
71
+ other_set = Pry::CommandSet.new do
76
72
  command('foo') { run << true }
77
73
  command('bar') { run << true }
78
74
  end
@@ -88,7 +84,7 @@ describe Pry::CommandSet do
88
84
  run = false
89
85
  @set.command('foo') { run = true }
90
86
 
91
- Pry::CommandSet.new(:other, @set).run_command nil, 'foo'
87
+ Pry::CommandSet.new(@set).run_command nil, 'foo'
92
88
  run.should == true
93
89
  end
94
90
 
@@ -139,7 +135,7 @@ describe Pry::CommandSet do
139
135
  Pry::CommandContext.new.should.not.respond_to :my_helper
140
136
  end
141
137
 
142
- it 'should not recreate a new heler module when helpers is called' do
138
+ it 'should not recreate a new helper module when helpers is called' do
143
139
  @set.command('foo') do
144
140
  should.respond_to :my_helper
145
141
  should.respond_to :my_other_helper
@@ -157,7 +153,7 @@ describe Pry::CommandSet do
157
153
  end
158
154
 
159
155
  it 'should import helpers from imported sets' do
160
- imported_set = Pry::CommandSet.new :test do
156
+ imported_set = Pry::CommandSet.new do
161
157
  helpers do
162
158
  def imported_helper_method; end
163
159
  end
@@ -169,7 +165,7 @@ describe Pry::CommandSet do
169
165
  end
170
166
 
171
167
  it 'should import helpers even if only some commands are imported' do
172
- imported_set = Pry::CommandSet.new :test do
168
+ imported_set = Pry::CommandSet.new do
173
169
  helpers do
174
170
  def imported_helper_method; end
175
171
  end
@@ -181,4 +177,14 @@ describe Pry::CommandSet do
181
177
  @set.command('foo') { should.respond_to :imported_helper_method }
182
178
  @set.run_command(Pry::CommandContext.new, 'foo')
183
179
  end
180
+
181
+ it 'should provide a :listing for a command that defaults to its name' do
182
+ @set.command 'foo', "" do;end
183
+ @set.commands['foo'].options[:listing].should == 'foo'
184
+ end
185
+
186
+ it 'should provide a :listing for a command that differs from its name' do
187
+ @set.command 'foo', "", :listing => 'bar' do;end
188
+ @set.commands['foo'].options[:listing].should == 'bar'
189
+ end
184
190
  end
@@ -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