pry 0.10.pre.1-java → 0.10.0.pre2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +41 -35
- data/lib/pry.rb +82 -139
- data/lib/pry/cli.rb +77 -30
- data/lib/pry/code.rb +126 -182
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +71 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +172 -0
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +184 -28
- data/lib/pry/command_set.rb +113 -59
- data/lib/pry/commands.rb +4 -27
- data/lib/pry/commands/amend_line.rb +99 -0
- data/lib/pry/commands/bang.rb +20 -0
- data/lib/pry/commands/bang_pry.rb +17 -0
- data/lib/pry/commands/cat.rb +62 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +77 -0
- data/lib/pry/commands/cat/file_formatter.rb +67 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +41 -0
- data/lib/pry/commands/change_inspector.rb +27 -0
- data/lib/pry/commands/change_prompt.rb +26 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/disabled_commands.rb +2 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +195 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
- data/lib/pry/commands/exit.rb +42 -0
- data/lib/pry/commands/exit_all.rb +29 -0
- data/lib/pry/commands/exit_program.rb +23 -0
- data/lib/pry/commands/find_method.rb +193 -0
- data/lib/pry/commands/fix_indent.rb +19 -0
- data/lib/pry/commands/gem_cd.rb +26 -0
- data/lib/pry/commands/gem_install.rb +32 -0
- data/lib/pry/commands/gem_list.rb +33 -0
- data/lib/pry/commands/gem_open.rb +29 -0
- data/lib/pry/commands/gist.rb +101 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +180 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +53 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +114 -0
- data/lib/pry/commands/ls/constants.rb +47 -0
- data/lib/pry/commands/ls/formatter.rb +49 -0
- data/lib/pry/commands/ls/globals.rb +48 -0
- data/lib/pry/commands/ls/grep.rb +21 -0
- data/lib/pry/commands/ls/instance_vars.rb +39 -0
- data/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/lib/pry/commands/ls/local_names.rb +35 -0
- data/lib/pry/commands/ls/local_vars.rb +39 -0
- data/lib/pry/commands/ls/ls_entity.rb +70 -0
- data/lib/pry/commands/ls/methods.rb +57 -0
- data/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/lib/pry/commands/ls/self_methods.rb +32 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +103 -0
- data/lib/pry/commands/pry_backtrace.rb +25 -0
- data/lib/pry/commands/pry_version.rb +17 -0
- data/lib/pry/commands/raise_up.rb +32 -0
- data/lib/pry/commands/reload_code.rb +62 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +60 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +48 -0
- data/lib/pry/commands/shell_mode.rb +25 -0
- data/lib/pry/commands/show_doc.rb +83 -0
- data/lib/pry/commands/show_info.rb +195 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +50 -0
- data/lib/pry/commands/simple_prompt.rb +22 -0
- data/lib/pry/commands/stat.rb +40 -0
- data/lib/pry/commands/switch_to.rb +23 -0
- data/lib/pry/commands/toggle_color.rb +24 -0
- data/lib/pry/commands/watch_expression.rb +105 -0
- data/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/lib/pry/commands/whereami.rb +190 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/config.rb +20 -229
- data/lib/pry/config/behavior.rb +139 -0
- data/lib/pry/config/convenience.rb +26 -0
- data/lib/pry/config/default.rb +165 -0
- data/lib/pry/core_extensions.rb +59 -38
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +40 -154
- data/lib/pry/helpers/command_helpers.rb +19 -130
- data/lib/pry/helpers/documentation_helpers.rb +21 -11
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +8 -9
- data/lib/pry/history.rb +61 -45
- data/lib/pry/history_array.rb +11 -1
- data/lib/pry/hooks.rb +10 -32
- data/lib/pry/indent.rb +110 -38
- data/lib/pry/input_completer.rb +242 -0
- data/lib/pry/input_lock.rb +132 -0
- data/lib/pry/inspector.rb +27 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method.rb +199 -200
- data/lib/pry/method/disowned.rb +53 -0
- data/lib/pry/method/patcher.rb +125 -0
- data/lib/pry/method/weird_method_locator.rb +186 -0
- data/lib/pry/module_candidate.rb +39 -33
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +234 -0
- data/lib/pry/plugins.rb +4 -3
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +199 -227
- data/lib/pry/pry_instance.rb +344 -403
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +20 -26
- data/lib/pry/rubygem.rb +82 -0
- data/lib/pry/terminal.rb +79 -0
- data/lib/pry/test/helper.rb +170 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +133 -48
- metadata +132 -197
- data/.document +0 -2
- data/.gemtest +0 -0
- data/.gitignore +0 -16
- data/.travis.yml +0 -17
- data/.yardopts +0 -1
- data/CHANGELOG +0 -387
- data/CONTRIBUTORS +0 -36
- data/Gemfile +0 -2
- data/Rakefile +0 -137
- data/TODO +0 -117
- data/examples/example_basic.rb +0 -15
- data/examples/example_command_override.rb +0 -32
- data/examples/example_commands.rb +0 -36
- data/examples/example_hooks.rb +0 -9
- data/examples/example_image_edit.rb +0 -67
- data/examples/example_input.rb +0 -7
- data/examples/example_input2.rb +0 -29
- data/examples/example_output.rb +0 -11
- data/examples/example_print.rb +0 -6
- data/examples/example_prompt.rb +0 -9
- data/examples/helper.rb +0 -6
- data/lib/pry/completion.rb +0 -221
- data/lib/pry/custom_completions.rb +0 -6
- data/lib/pry/default_commands/cd.rb +0 -81
- data/lib/pry/default_commands/commands.rb +0 -62
- data/lib/pry/default_commands/context.rb +0 -98
- data/lib/pry/default_commands/easter_eggs.rb +0 -95
- data/lib/pry/default_commands/editing.rb +0 -420
- data/lib/pry/default_commands/find_method.rb +0 -169
- data/lib/pry/default_commands/gems.rb +0 -84
- data/lib/pry/default_commands/gist.rb +0 -187
- data/lib/pry/default_commands/help.rb +0 -127
- data/lib/pry/default_commands/hist.rb +0 -120
- data/lib/pry/default_commands/input_and_output.rb +0 -306
- data/lib/pry/default_commands/introspection.rb +0 -410
- data/lib/pry/default_commands/ls.rb +0 -272
- data/lib/pry/default_commands/misc.rb +0 -38
- data/lib/pry/default_commands/navigating_pry.rb +0 -110
- data/lib/pry/default_commands/whereami.rb +0 -92
- data/lib/pry/extended_commands/experimental.rb +0 -7
- data/lib/pry/rbx_method.rb +0 -13
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -46
- data/test/candidate_helper1.rb +0 -11
- data/test/candidate_helper2.rb +0 -8
- data/test/helper.rb +0 -223
- data/test/test_cli.rb +0 -78
- data/test/test_code.rb +0 -201
- data/test/test_command.rb +0 -712
- data/test/test_command_helpers.rb +0 -9
- data/test/test_command_integration.rb +0 -668
- data/test/test_command_set.rb +0 -610
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/example.erb +0 -5
- data/test/test_default_commands/test_cd.rb +0 -318
- data/test/test_default_commands/test_context.rb +0 -280
- data/test/test_default_commands/test_documentation.rb +0 -314
- data/test/test_default_commands/test_find_method.rb +0 -50
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_help.rb +0 -57
- data/test/test_default_commands/test_input.rb +0 -428
- data/test/test_default_commands/test_introspection.rb +0 -511
- data/test/test_default_commands/test_ls.rb +0 -151
- data/test/test_default_commands/test_shell.rb +0 -343
- data/test/test_default_commands/test_show_source.rb +0 -432
- data/test/test_exception_whitelist.rb +0 -21
- data/test/test_history_array.rb +0 -65
- data/test/test_hooks.rb +0 -521
- data/test/test_indent.rb +0 -277
- data/test/test_input_stack.rb +0 -86
- data/test/test_method.rb +0 -401
- data/test/test_pry.rb +0 -463
- data/test/test_pry_defaults.rb +0 -419
- data/test/test_pry_history.rb +0 -84
- data/test/test_pry_output.rb +0 -41
- data/test/test_sticky_locals.rb +0 -155
- data/test/test_syntax_checking.rb +0 -65
- data/test/test_wrapped_module.rb +0 -174
- data/test/testrc +0 -2
- data/test/testrcbad +0 -2
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
data/test/test_command_set.rb
DELETED
@@ -1,610 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Pry::CommandSet do
|
4
|
-
before do
|
5
|
-
@set = Pry::CommandSet.new{ import Pry::DefaultCommands::Help }
|
6
|
-
@ctx = {
|
7
|
-
:target => binding,
|
8
|
-
:command_set => @set
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should call the block used for the command when it is called' do
|
13
|
-
run = false
|
14
|
-
@set.command 'foo' do
|
15
|
-
run = true
|
16
|
-
end
|
17
|
-
|
18
|
-
@set.run_command @ctx, 'foo'
|
19
|
-
run.should == true
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should pass arguments of the command to the block' do
|
23
|
-
@set.command 'foo' do |*args|
|
24
|
-
args.should == [1, 2, 3]
|
25
|
-
end
|
26
|
-
|
27
|
-
@set.run_command @ctx, 'foo', 1, 2, 3
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should use the first argument as context' do
|
31
|
-
ctx = @ctx
|
32
|
-
|
33
|
-
@set.command 'foo' do
|
34
|
-
self.context.should == ctx
|
35
|
-
end
|
36
|
-
|
37
|
-
@set.run_command @ctx, 'foo'
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should raise an error when calling an undefined command' do
|
41
|
-
@set.command('foo') {}
|
42
|
-
lambda {
|
43
|
-
@set.run_command @ctx, 'bar'
|
44
|
-
}.should.raise(Pry::NoCommandError)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should be able to remove its own commands' do
|
48
|
-
@set.command('foo') {}
|
49
|
-
@set.delete 'foo'
|
50
|
-
|
51
|
-
lambda {
|
52
|
-
@set.run_command @ctx, 'foo'
|
53
|
-
}.should.raise(Pry::NoCommandError)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should be able to remove its own commands, by listing name' do
|
57
|
-
@set.command(/^foo1/, 'desc', :listing => 'foo') {}
|
58
|
-
@set.delete 'foo'
|
59
|
-
|
60
|
-
lambda {
|
61
|
-
@set.run_command @ctx, /^foo1/
|
62
|
-
}.should.raise(Pry::NoCommandError)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should be able to import some commands from other sets' do
|
66
|
-
run = false
|
67
|
-
|
68
|
-
other_set = Pry::CommandSet.new do
|
69
|
-
command('foo') { run = true }
|
70
|
-
command('bar') {}
|
71
|
-
end
|
72
|
-
|
73
|
-
@set.import_from(other_set, 'foo')
|
74
|
-
|
75
|
-
@set.run_command @ctx, 'foo'
|
76
|
-
run.should == true
|
77
|
-
|
78
|
-
lambda {
|
79
|
-
@set.run_command @ctx, 'bar'
|
80
|
-
}.should.raise(Pry::NoCommandError)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should return command set after import' do
|
84
|
-
run = false
|
85
|
-
|
86
|
-
other_set = Pry::CommandSet.new do
|
87
|
-
command('foo') { run = true }
|
88
|
-
command('bar') {}
|
89
|
-
end
|
90
|
-
|
91
|
-
@set.import(other_set).should == @set
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should return command set after import_from' do
|
95
|
-
run = false
|
96
|
-
|
97
|
-
other_set = Pry::CommandSet.new do
|
98
|
-
command('foo') { run = true }
|
99
|
-
command('bar') {}
|
100
|
-
end
|
101
|
-
|
102
|
-
@set.import_from(other_set, 'foo').should == @set
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'should be able to import some commands from other sets using listing name' do
|
106
|
-
run = false
|
107
|
-
|
108
|
-
other_set = Pry::CommandSet.new do
|
109
|
-
command(/^foo1/, 'desc', :listing => 'foo') { run = true }
|
110
|
-
end
|
111
|
-
|
112
|
-
@set.import_from(other_set, 'foo')
|
113
|
-
|
114
|
-
@set.run_command @ctx, /^foo1/
|
115
|
-
run.should == true
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'should be able to import a whole set' do
|
119
|
-
run = []
|
120
|
-
|
121
|
-
other_set = Pry::CommandSet.new do
|
122
|
-
command('foo') { run << true }
|
123
|
-
command('bar') { run << true }
|
124
|
-
end
|
125
|
-
|
126
|
-
@set.import other_set
|
127
|
-
|
128
|
-
@set.run_command @ctx, 'foo'
|
129
|
-
@set.run_command @ctx, 'bar'
|
130
|
-
run.should == [true, true]
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'should be able to import sets at creation' do
|
134
|
-
run = false
|
135
|
-
@set.command('foo') { run = true }
|
136
|
-
|
137
|
-
Pry::CommandSet.new(@set).run_command @ctx, 'foo'
|
138
|
-
run.should == true
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'should set the descriptions of commands' do
|
142
|
-
@set.command('foo', 'some stuff') {}
|
143
|
-
@set.commands['foo'].description.should == 'some stuff'
|
144
|
-
end
|
145
|
-
|
146
|
-
describe "aliases" do
|
147
|
-
it 'should be able to alias command' do
|
148
|
-
run = false
|
149
|
-
@set.command('foo', 'stuff') { run = true }
|
150
|
-
|
151
|
-
@set.alias_command 'bar', 'foo'
|
152
|
-
@set.commands['bar'].match.should == 'bar'
|
153
|
-
@set.commands['bar'].description.should == 'Alias for `foo`'
|
154
|
-
|
155
|
-
@set.run_command @ctx, 'bar'
|
156
|
-
run.should == true
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'should inherit options from original command' do
|
160
|
-
run = false
|
161
|
-
@set.command('foo', 'stuff', :shellwords => true, :interpolate => false) { run = true }
|
162
|
-
|
163
|
-
@set.alias_command 'bar', 'foo'
|
164
|
-
@set.commands['bar'].options[:shellwords].should == @set.commands['foo'].options[:shellwords]
|
165
|
-
@set.commands['bar'].options[:interpolate].should == @set.commands['foo'].options[:interpolate]
|
166
|
-
|
167
|
-
# however some options should not be inherited
|
168
|
-
@set.commands['bar'].options[:listing].should.not == @set.commands['foo'].options[:listing]
|
169
|
-
@set.commands['bar'].options[:listing].should == "bar"
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'should be able to specify alias\'s description when aliasing' do
|
173
|
-
run = false
|
174
|
-
@set.command('foo', 'stuff') { run = true }
|
175
|
-
|
176
|
-
@set.alias_command 'bar', 'foo', :desc => "tobina"
|
177
|
-
@set.commands['bar'].match.should == 'bar'
|
178
|
-
@set.commands['bar'].description.should == "tobina"
|
179
|
-
|
180
|
-
@set.run_command @ctx, 'bar'
|
181
|
-
run.should == true
|
182
|
-
end
|
183
|
-
|
184
|
-
it "should be able to alias a command by its invocation line" do
|
185
|
-
run = false
|
186
|
-
@set.command(/^foo1/, 'stuff', :listing => 'foo') { run = true }
|
187
|
-
|
188
|
-
@set.alias_command 'bar', 'foo1'
|
189
|
-
@set.commands['bar'].match.should == 'bar'
|
190
|
-
@set.commands['bar'].description.should == 'Alias for `foo1`'
|
191
|
-
|
192
|
-
@set.run_command @ctx, 'bar'
|
193
|
-
run.should == true
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should be able to specify options when creating alias" do
|
197
|
-
run = false
|
198
|
-
@set.command(/^foo1/, 'stuff', :listing => 'foo') { run = true }
|
199
|
-
|
200
|
-
@set.alias_command /^b.r/, 'foo1', :listing => "bar"
|
201
|
-
@set.commands[/^b.r/].options[:listing].should == "bar"
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should set description to default if description parameter is nil" do
|
205
|
-
run = false
|
206
|
-
@set.command(/^foo1/, 'stuff', :listing => 'foo') { run = true }
|
207
|
-
|
208
|
-
@set.alias_command "bar", 'foo1'
|
209
|
-
@set.commands["bar"].description.should == "Alias for `foo1`"
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'should be able to change the descriptions of commands' do
|
214
|
-
@set.command('foo', 'bar') {}
|
215
|
-
@set.desc 'foo', 'baz'
|
216
|
-
|
217
|
-
@set.commands['foo'].description.should == 'baz'
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'should get the descriptions of commands' do
|
221
|
-
@set.command('foo', 'bar') {}
|
222
|
-
@set.desc('foo').should == 'bar'
|
223
|
-
end
|
224
|
-
|
225
|
-
it 'should get the descriptions of commands, by listing' do
|
226
|
-
@set.command(/^foo1/, 'bar', :listing => 'foo') {}
|
227
|
-
@set.desc('foo').should == 'bar'
|
228
|
-
end
|
229
|
-
|
230
|
-
it 'should return Pry::Command::VOID_VALUE for commands by default' do
|
231
|
-
@set.command('foo') { 3 }
|
232
|
-
@set.run_command(@ctx, 'foo').should == Pry::Command::VOID_VALUE
|
233
|
-
end
|
234
|
-
|
235
|
-
it 'should be able to keep return values' do
|
236
|
-
@set.command('foo', '', :keep_retval => true) { 3 }
|
237
|
-
@set.run_command(@ctx, 'foo').should == 3
|
238
|
-
end
|
239
|
-
|
240
|
-
it 'should be able to keep return values, even if return value is nil' do
|
241
|
-
@set.command('foo', '', :keep_retval => true) { nil }
|
242
|
-
@set.run_command(@ctx, 'foo').should == nil
|
243
|
-
end
|
244
|
-
|
245
|
-
it 'should be able to have its own helpers' do
|
246
|
-
@set.command('foo') do
|
247
|
-
should.respond_to :my_helper
|
248
|
-
end
|
249
|
-
|
250
|
-
@set.helpers do
|
251
|
-
def my_helper; end
|
252
|
-
end
|
253
|
-
|
254
|
-
@set.run_command(@ctx, 'foo')
|
255
|
-
Pry::Command.subclass('foo', '', {}, Module.new).new({:target => binding}).should.not.respond_to :my_helper
|
256
|
-
end
|
257
|
-
|
258
|
-
it 'should not recreate a new helper module when helpers is called' do
|
259
|
-
@set.command('foo') do
|
260
|
-
should.respond_to :my_helper
|
261
|
-
should.respond_to :my_other_helper
|
262
|
-
end
|
263
|
-
|
264
|
-
@set.helpers do
|
265
|
-
def my_helper; end
|
266
|
-
end
|
267
|
-
|
268
|
-
@set.helpers do
|
269
|
-
def my_other_helper; end
|
270
|
-
end
|
271
|
-
|
272
|
-
@set.run_command(@ctx, 'foo')
|
273
|
-
end
|
274
|
-
|
275
|
-
it 'should import helpers from imported sets' do
|
276
|
-
imported_set = Pry::CommandSet.new do
|
277
|
-
helpers do
|
278
|
-
def imported_helper_method; end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
@set.import imported_set
|
283
|
-
@set.command('foo') { should.respond_to :imported_helper_method }
|
284
|
-
@set.run_command(@ctx, 'foo')
|
285
|
-
end
|
286
|
-
|
287
|
-
it 'should import helpers even if only some commands are imported' do
|
288
|
-
imported_set = Pry::CommandSet.new do
|
289
|
-
helpers do
|
290
|
-
def imported_helper_method; end
|
291
|
-
end
|
292
|
-
|
293
|
-
command('bar') {}
|
294
|
-
end
|
295
|
-
|
296
|
-
@set.import_from imported_set, 'bar'
|
297
|
-
@set.command('foo') { should.respond_to :imported_helper_method }
|
298
|
-
@set.run_command(@ctx, 'foo')
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'should provide a :listing for a command that defaults to its name' do
|
302
|
-
@set.command 'foo', "" do;end
|
303
|
-
@set.commands['foo'].options[:listing].should == 'foo'
|
304
|
-
end
|
305
|
-
|
306
|
-
it 'should provide a :listing for a command that differs from its name' do
|
307
|
-
@set.command 'foo', "", :listing => 'bar' do;end
|
308
|
-
@set.commands['foo'].options[:listing].should == 'bar'
|
309
|
-
end
|
310
|
-
|
311
|
-
it "should provide a 'help' command" do
|
312
|
-
@ctx[:command_set] = @set
|
313
|
-
@ctx[:output] = StringIO.new
|
314
|
-
|
315
|
-
lambda {
|
316
|
-
@set.run_command(@ctx, 'help')
|
317
|
-
}.should.not.raise
|
318
|
-
end
|
319
|
-
|
320
|
-
|
321
|
-
describe "renaming a command" do
|
322
|
-
it 'should be able to rename and run a command' do
|
323
|
-
run = false
|
324
|
-
@set.command('foo') { run = true }
|
325
|
-
@set.rename_command('bar', 'foo')
|
326
|
-
@set.run_command(@ctx, 'bar')
|
327
|
-
run.should == true
|
328
|
-
end
|
329
|
-
|
330
|
-
it 'should accept listing name when renaming a command' do
|
331
|
-
run = false
|
332
|
-
@set.command('foo', "", :listing => 'love') { run = true }
|
333
|
-
@set.rename_command('bar', 'love')
|
334
|
-
@set.run_command(@ctx, 'bar')
|
335
|
-
run.should == true
|
336
|
-
end
|
337
|
-
|
338
|
-
it 'should raise exception trying to rename non-existent command' do
|
339
|
-
lambda { @set.rename_command('bar', 'foo') }.should.raise ArgumentError
|
340
|
-
end
|
341
|
-
|
342
|
-
it 'should make old command name inaccessible' do
|
343
|
-
@set.command('foo') { }
|
344
|
-
@set.rename_command('bar', 'foo')
|
345
|
-
lambda { @set.run_command(@ctx, 'foo') }.should.raise Pry::NoCommandError
|
346
|
-
end
|
347
|
-
|
348
|
-
it 'should be able to pass in options when renaming command' do
|
349
|
-
desc = "hello"
|
350
|
-
listing = "bing"
|
351
|
-
@set.command('foo') { }
|
352
|
-
@set.rename_command('bar', 'foo', :description => desc, :listing => listing, :keep_retval => true)
|
353
|
-
@set.commands['bar'].description.should == desc
|
354
|
-
@set.commands['bar'].options[:listing].should == listing
|
355
|
-
@set.commands['bar'].options[:keep_retval].should == true
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
|
-
describe "command decorators - before_command and after_command" do
|
360
|
-
describe "before_command" do
|
361
|
-
it 'should be called before the original command' do
|
362
|
-
foo = []
|
363
|
-
@set.command('foo') { foo << 1 }
|
364
|
-
@set.before_command('foo') { foo << 2 }
|
365
|
-
@set.run_command(@ctx, 'foo')
|
366
|
-
|
367
|
-
foo.should == [2, 1]
|
368
|
-
end
|
369
|
-
|
370
|
-
it 'should be called before the original command, using listing name' do
|
371
|
-
foo = []
|
372
|
-
@set.command(/^foo1/, '', :listing => 'foo') { foo << 1 }
|
373
|
-
@set.before_command('foo') { foo << 2 }
|
374
|
-
@set.run_command(@ctx, /^foo1/)
|
375
|
-
|
376
|
-
foo.should == [2, 1]
|
377
|
-
end
|
378
|
-
|
379
|
-
it 'should share the context with the original command' do
|
380
|
-
@ctx[:target] = "test target string".__binding__
|
381
|
-
before_val = nil
|
382
|
-
orig_val = nil
|
383
|
-
@set.command('foo') { orig_val = target }
|
384
|
-
@set.before_command('foo') { before_val = target }
|
385
|
-
@set.run_command(@ctx, 'foo')
|
386
|
-
|
387
|
-
before_val.should == @ctx[:target]
|
388
|
-
orig_val.should == @ctx[:target]
|
389
|
-
end
|
390
|
-
|
391
|
-
it 'should work when applied multiple times' do
|
392
|
-
foo = []
|
393
|
-
@set.command('foo') { foo << 1 }
|
394
|
-
@set.before_command('foo') { foo << 2 }
|
395
|
-
@set.before_command('foo') { foo << 3 }
|
396
|
-
@set.before_command('foo') { foo << 4 }
|
397
|
-
@set.run_command(@ctx, 'foo')
|
398
|
-
|
399
|
-
foo.should == [4, 3, 2, 1]
|
400
|
-
end
|
401
|
-
|
402
|
-
end
|
403
|
-
|
404
|
-
describe "after_command" do
|
405
|
-
it 'should be called after the original command' do
|
406
|
-
foo = []
|
407
|
-
@set.command('foo') { foo << 1 }
|
408
|
-
@set.after_command('foo') { foo << 2 }
|
409
|
-
@set.run_command(@ctx, 'foo')
|
410
|
-
|
411
|
-
foo.should == [1, 2]
|
412
|
-
end
|
413
|
-
|
414
|
-
it 'should be called after the original command, using listing name' do
|
415
|
-
foo = []
|
416
|
-
@set.command(/^foo1/, '', :listing => 'foo') { foo << 1 }
|
417
|
-
@set.after_command('foo') { foo << 2 }
|
418
|
-
@set.run_command(@ctx, /^foo1/)
|
419
|
-
|
420
|
-
foo.should == [1, 2]
|
421
|
-
end
|
422
|
-
|
423
|
-
it 'should share the context with the original command' do
|
424
|
-
@ctx[:target] = "test target string".__binding__
|
425
|
-
after_val = nil
|
426
|
-
orig_val = nil
|
427
|
-
@set.command('foo') { orig_val = target }
|
428
|
-
@set.after_command('foo') { after_val = target }
|
429
|
-
@set.run_command(@ctx, 'foo')
|
430
|
-
|
431
|
-
after_val.should == @ctx[:target]
|
432
|
-
orig_val.should == @ctx[:target]
|
433
|
-
end
|
434
|
-
|
435
|
-
it 'should determine the return value for the command' do
|
436
|
-
@set.command('foo', 'bar', :keep_retval => true) { 1 }
|
437
|
-
@set.after_command('foo') { 2 }
|
438
|
-
@set.run_command(@ctx, 'foo').should == 2
|
439
|
-
end
|
440
|
-
|
441
|
-
it 'should work when applied multiple times' do
|
442
|
-
foo = []
|
443
|
-
@set.command('foo') { foo << 1 }
|
444
|
-
@set.after_command('foo') { foo << 2 }
|
445
|
-
@set.after_command('foo') { foo << 3 }
|
446
|
-
@set.after_command('foo') { foo << 4 }
|
447
|
-
@set.run_command(@ctx, 'foo')
|
448
|
-
|
449
|
-
foo.should == [1, 2, 3, 4]
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
describe "before_command and after_command" do
|
454
|
-
it 'should work when combining both before_command and after_command' do
|
455
|
-
foo = []
|
456
|
-
@set.command('foo') { foo << 1 }
|
457
|
-
@set.after_command('foo') { foo << 2 }
|
458
|
-
@set.before_command('foo') { foo << 3 }
|
459
|
-
@set.run_command(@ctx, 'foo')
|
460
|
-
|
461
|
-
foo.should == [3, 1, 2]
|
462
|
-
end
|
463
|
-
|
464
|
-
end
|
465
|
-
|
466
|
-
end
|
467
|
-
|
468
|
-
describe 'find_command' do
|
469
|
-
it 'should find commands with the right string' do
|
470
|
-
cmd = @set.command('rincewind'){ }
|
471
|
-
@set.find_command('rincewind').should == cmd
|
472
|
-
end
|
473
|
-
|
474
|
-
it 'should not find commands with spaces before' do
|
475
|
-
cmd = @set.command('luggage'){ }
|
476
|
-
@set.find_command(' luggage').should == nil
|
477
|
-
end
|
478
|
-
|
479
|
-
it 'should find commands with arguments after' do
|
480
|
-
cmd = @set.command('vetinari'){ }
|
481
|
-
@set.find_command('vetinari --knock 3').should == cmd
|
482
|
-
end
|
483
|
-
|
484
|
-
it 'should find commands with names containing spaces' do
|
485
|
-
cmd = @set.command('nobby nobbs'){ }
|
486
|
-
@set.find_command('nobby nobbs --steal petty-cash').should == cmd
|
487
|
-
end
|
488
|
-
|
489
|
-
it 'should find command defined by regex' do
|
490
|
-
cmd = @set.command(/(capt|captain) vimes/i){ }
|
491
|
-
@set.find_command('Capt Vimes').should == cmd
|
492
|
-
end
|
493
|
-
|
494
|
-
it 'should find commands defined by regex with arguments' do
|
495
|
-
cmd = @set.command(/(cpl|corporal) Carrot/i){ }
|
496
|
-
@set.find_command('cpl carrot --write-home').should == cmd
|
497
|
-
end
|
498
|
-
|
499
|
-
it 'should not find commands by listing' do
|
500
|
-
cmd = @set.command(/werewol(f|ve)s?/, 'only once a month', :listing => "angua"){ }
|
501
|
-
@set.find_command('angua').should == nil
|
502
|
-
end
|
503
|
-
|
504
|
-
it 'should not find commands without command_prefix' do
|
505
|
-
Pry.config.command_prefix = '%'
|
506
|
-
cmd = @set.command('detritus'){ }
|
507
|
-
@set.find_command('detritus').should == nil
|
508
|
-
Pry.config.command_prefix = ''
|
509
|
-
end
|
510
|
-
|
511
|
-
it "should find commands that don't use the prefix" do
|
512
|
-
Pry.config.command_prefix = '%'
|
513
|
-
cmd = @set.command('colon', 'Sergeant Fred', :use_prefix => false){ }
|
514
|
-
@set.find_command('colon').should == cmd
|
515
|
-
Pry.config.command_prefix = ''
|
516
|
-
end
|
517
|
-
|
518
|
-
it "should find the command that has the longest match" do
|
519
|
-
cmd = @set.command(/\.(.*)/){ }
|
520
|
-
cmd2 = @set.command(/\.\|\|(.*)/){ }
|
521
|
-
@set.find_command('.||').should == cmd2
|
522
|
-
end
|
523
|
-
|
524
|
-
it "should find the command that has the longest name" do
|
525
|
-
cmd = @set.command(/\.(.*)/){ }
|
526
|
-
cmd2 = @set.command('.||'){ }
|
527
|
-
@set.find_command('.||').should == cmd2
|
528
|
-
end
|
529
|
-
end
|
530
|
-
|
531
|
-
describe '.valid_command?' do
|
532
|
-
it 'should be true for commands that can be found' do
|
533
|
-
cmd = @set.command('archchancellor')
|
534
|
-
@set.valid_command?('archchancellor of_the?(:University)').should == true
|
535
|
-
end
|
536
|
-
|
537
|
-
it 'should be false for commands that can\'' do
|
538
|
-
@set.valid_command?('def monkey(ape)').should == false
|
539
|
-
end
|
540
|
-
|
541
|
-
it 'should not cause argument interpolation' do
|
542
|
-
cmd = @set.command('hello')
|
543
|
-
lambda {
|
544
|
-
@set.valid_command?('hello #{raise "futz"}')
|
545
|
-
}.should.not.raise
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
describe '.process_line' do
|
550
|
-
|
551
|
-
it 'should return Result.new(false) if there is no matching command' do
|
552
|
-
result = @set.process_line('1 + 42')
|
553
|
-
result.command?.should == false
|
554
|
-
result.void_command?.should == false
|
555
|
-
result.retval.should == nil
|
556
|
-
end
|
557
|
-
|
558
|
-
it 'should return Result.new(true, VOID) if the command is not keep_retval' do
|
559
|
-
@set.create_command('mrs-cake') do
|
560
|
-
def process; 42; end
|
561
|
-
end
|
562
|
-
|
563
|
-
result = @set.process_line('mrs-cake')
|
564
|
-
result.command?.should == true
|
565
|
-
result.void_command?.should == true
|
566
|
-
result.retval.should == Pry::Command::VOID_VALUE
|
567
|
-
end
|
568
|
-
|
569
|
-
it 'should return Result.new(true, retval) if the command is keep_retval' do
|
570
|
-
@set.create_command('magrat', 'the maiden', :keep_retval => true) do
|
571
|
-
def process; 42; end
|
572
|
-
end
|
573
|
-
|
574
|
-
result = @set.process_line('magrat')
|
575
|
-
result.command?.should == true
|
576
|
-
result.void_command?.should == false
|
577
|
-
result.retval.should == 42
|
578
|
-
end
|
579
|
-
|
580
|
-
it 'should pass through context' do
|
581
|
-
ctx = {
|
582
|
-
:eval_string => "bloomers",
|
583
|
-
:pry_instance => Object.new,
|
584
|
-
:output => StringIO.new,
|
585
|
-
:target => binding
|
586
|
-
}
|
587
|
-
@set.create_command('agnes') do
|
588
|
-
define_method(:process) do
|
589
|
-
eval_string.should == ctx[:eval_string]
|
590
|
-
output.should == ctx[:output]
|
591
|
-
target.should == ctx[:target]
|
592
|
-
_pry_.should == ctx[:pry_instance]
|
593
|
-
end
|
594
|
-
end
|
595
|
-
|
596
|
-
@set.process_line('agnes', ctx)
|
597
|
-
end
|
598
|
-
|
599
|
-
it 'should add command_set to context' do
|
600
|
-
set = @set
|
601
|
-
@set.create_command(/nann+y ogg+/) do
|
602
|
-
define_method(:process) do
|
603
|
-
command_set.should == set
|
604
|
-
end
|
605
|
-
end
|
606
|
-
|
607
|
-
@set.process_line('nannnnnny oggggg')
|
608
|
-
end
|
609
|
-
end
|
610
|
-
end
|