pry 0.9.8pre3-i386-mswin32 → 0.9.8pre5-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pry/pry_class.rb CHANGED
@@ -123,8 +123,12 @@ class Pry
123
123
  pry_instance
124
124
  )
125
125
 
126
- head, *tail = binding_stack
127
- pry_instance.binding_stack.push(*tail)
126
+ if pry_instance.binding_stack.empty?
127
+ head, *tail = binding_stack
128
+ pry_instance.binding_stack.push(*tail)
129
+ else
130
+ head = pry_instance.binding_stack.pop
131
+ end
128
132
 
129
133
  # Enter the matrix
130
134
  pry_instance.repl(head)
@@ -111,9 +111,9 @@ class Pry
111
111
  inject_local("_in_", @input_array, target)
112
112
  inject_local("_out_", @output_array, target)
113
113
  inject_local("_pry_", self, target)
114
- inject_local("_ex_", nil, target)
115
- inject_local("_file_", nil, target)
116
- inject_local("_dir_", nil, target)
114
+ inject_local("_ex_", last_exception, target)
115
+ inject_local("_file_", last_file, target)
116
+ inject_local("_dir_", last_dir, target)
117
117
 
118
118
  # without this line we get 1 test failure, ask Mon_Ouie
119
119
  set_last_result(nil, target)
@@ -129,13 +129,13 @@ class Pry
129
129
 
130
130
  def special_locals
131
131
  {
132
- :_in_ => @input_array,
133
- :_out_ => @output_array,
134
- :_pry_ => self,
135
- :_ex_ => last_exception,
132
+ :_in_ => @input_array,
133
+ :_out_ => @output_array,
134
+ :_pry_ => self,
135
+ :_ex_ => last_exception,
136
136
  :_file_ => last_file,
137
- :_dir_ => last_dir,
138
- :_ => last_result
137
+ :_dir_ => last_dir,
138
+ :_ => last_result
139
139
  }
140
140
  end
141
141
 
@@ -181,8 +181,9 @@ class Pry
181
181
  end
182
182
  end
183
183
 
184
- repl_epilogue(target)
185
184
  break_data || nil
185
+ ensure
186
+ repl_epilogue(target)
186
187
  end
187
188
 
188
189
  # Perform a read-eval-print.
@@ -225,7 +226,9 @@ class Pry
225
226
 
226
227
  code = r(target)
227
228
 
228
- result = set_last_result(target.eval(code, Pry.eval_path, Pry.current_line), target)
229
+ result = target.eval(code, Pry.eval_path, Pry.current_line)
230
+ set_last_result(result, target, code)
231
+
229
232
  result
230
233
  rescue RescuableException => e
231
234
  result = set_last_exception(e, target)
@@ -257,7 +260,12 @@ class Pry
257
260
  output.puts "Error: #{e.message}"
258
261
  end
259
262
 
260
- break if complete_expression?(eval_string)
263
+ begin
264
+ break if complete_expression?(eval_string)
265
+ rescue SyntaxError => e
266
+ output.puts "SyntaxError: #{e.message.sub(/.*syntax error, */m, '')}"
267
+ eval_string = ""
268
+ end
261
269
  end
262
270
 
263
271
  @suppress_output = true if eval_string =~ /;\Z/ || eval_string.empty?
@@ -398,11 +406,12 @@ class Pry
398
406
  # This method should not need to be invoked directly.
399
407
  # @param [Object] result The result.
400
408
  # @param [Binding] target The binding to set `_` on.
401
- def set_last_result(result, target)
409
+ # @param [String] code The code that was run.
410
+ def set_last_result(result, target, code="")
402
411
  @last_result_is_exception = false
403
412
  @output_array << result
404
413
 
405
- self.last_result = result
414
+ self.last_result = result unless code =~ /\A\s*\z/
406
415
  end
407
416
 
408
417
  # Set the last exception for a session.
@@ -565,8 +574,8 @@ class Pry
565
574
  }
566
575
  end
567
576
 
568
- # Assert that a line which ends with a , or a \ is incomplete.
569
- str !~ /[,\\]$/
577
+ # Assert that a line which ends with a , is incomplete.
578
+ str !~ /[,]\z/
570
579
  rescue SyntaxError => e
571
580
  if incomplete_user_input_exception?(e)
572
581
  false
data/lib/pry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.9.8pre3"
2
+ VERSION = "0.9.8pre5"
3
3
  end
data/pry.gemspec CHANGED
@@ -1,21 +1,21 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = "pry"
5
- s.version = "0.9.8pre3"
4
+ s.name = %q{pry}
5
+ s.version = "0.9.8pre5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["John Mair (banisterfiend)"]
9
- s.date = "2012-01-05"
10
- s.description = "An IRB alternative and runtime developer console"
11
- s.email = "jrmair@gmail.com"
12
- s.executables = ["pry"]
13
- s.files = [".document", ".gemtest", ".gitignore", ".travis.yml", ".yardopts", "CHANGELOG", "CONTRIBUTORS", "Gemfile", "LICENSE", "README.markdown", "Rakefile", "TODO", "bin/pry", "examples/example_basic.rb", "examples/example_command_override.rb", "examples/example_commands.rb", "examples/example_hooks.rb", "examples/example_image_edit.rb", "examples/example_input.rb", "examples/example_input2.rb", "examples/example_output.rb", "examples/example_print.rb", "examples/example_prompt.rb", "examples/helper.rb", "lib/pry.rb", "lib/pry/cli.rb", "lib/pry/command.rb", "lib/pry/command_set.rb", "lib/pry/commands.rb", "lib/pry/completion.rb", "lib/pry/config.rb", "lib/pry/core_extensions.rb", "lib/pry/custom_completions.rb", "lib/pry/default_commands/basic.rb", "lib/pry/default_commands/context.rb", "lib/pry/default_commands/documentation.rb", "lib/pry/default_commands/easter_eggs.rb", "lib/pry/default_commands/gems.rb", "lib/pry/default_commands/input.rb", "lib/pry/default_commands/introspection.rb", "lib/pry/default_commands/ls.rb", "lib/pry/default_commands/shell.rb", "lib/pry/extended_commands/experimental.rb", "lib/pry/extended_commands/user_command_api.rb", "lib/pry/helpers.rb", "lib/pry/helpers/base_helpers.rb", "lib/pry/helpers/command_helpers.rb", "lib/pry/helpers/options_helpers.rb", "lib/pry/helpers/text.rb", "lib/pry/history.rb", "lib/pry/history_array.rb", "lib/pry/hooks.rb", "lib/pry/indent.rb", "lib/pry/method.rb", "lib/pry/plugins.rb", "lib/pry/pry_class.rb", "lib/pry/pry_instance.rb", "lib/pry/rbx_method.rb", "lib/pry/rbx_path.rb", "lib/pry/version.rb", "lib/pry/wrapped_module.rb", "man/pry.1", "man/pry.1.html", "man/pry.1.ronn", "pry.gemspec", "test/helper.rb", "test/test_cli.rb", "test/test_command.rb", "test/test_command_helpers.rb", "test/test_command_set.rb", "test/test_completion.rb", "test/test_default_commands.rb", "test/test_default_commands/test_context.rb", "test/test_default_commands/test_documentation.rb", "test/test_default_commands/test_gems.rb", "test/test_default_commands/test_input.rb", "test/test_default_commands/test_introspection.rb", "test/test_default_commands/test_ls.rb", "test/test_default_commands/test_shell.rb", "test/test_exception_whitelist.rb", "test/test_history_array.rb", "test/test_hooks.rb", "test/test_indent.rb", "test/test_input_stack.rb", "test/test_method.rb", "test/test_pry.rb", "test/test_pry_history.rb", "test/test_pry_output.rb", "test/test_special_locals.rb", "test/test_syntax_checking.rb", "test/test_wrapped_module.rb", "test/testrc", "test/testrcbad", "wiki/Customizing-pry.md", "wiki/Home.md"]
14
- s.homepage = "http://pry.github.com"
15
- s.require_paths = ["lib"]
16
- s.rubygems_version = "1.8.11"
17
- s.summary = "An IRB alternative and runtime developer console"
18
- s.test_files = ["test/helper.rb", "test/test_cli.rb", "test/test_command.rb", "test/test_command_helpers.rb", "test/test_command_set.rb", "test/test_completion.rb", "test/test_default_commands.rb", "test/test_default_commands/test_context.rb", "test/test_default_commands/test_documentation.rb", "test/test_default_commands/test_gems.rb", "test/test_default_commands/test_input.rb", "test/test_default_commands/test_introspection.rb", "test/test_default_commands/test_ls.rb", "test/test_default_commands/test_shell.rb", "test/test_exception_whitelist.rb", "test/test_history_array.rb", "test/test_hooks.rb", "test/test_indent.rb", "test/test_input_stack.rb", "test/test_method.rb", "test/test_pry.rb", "test/test_pry_history.rb", "test/test_pry_output.rb", "test/test_special_locals.rb", "test/test_syntax_checking.rb", "test/test_wrapped_module.rb", "test/testrc", "test/testrcbad"]
8
+ s.authors = [%q{John Mair (banisterfiend)}]
9
+ s.date = %q{2012-01-19}
10
+ s.description = %q{An IRB alternative and runtime developer console}
11
+ s.email = %q{jrmair@gmail.com}
12
+ s.executables = [%q{pry}]
13
+ s.files = [%q{.document}, %q{.gemtest}, %q{.gitignore}, %q{.travis.yml}, %q{.yardopts}, %q{CHANGELOG}, %q{CONTRIBUTORS}, %q{Gemfile}, %q{LICENSE}, %q{README.markdown}, %q{Rakefile}, %q{TODO}, %q{bin/pry}, %q{examples/example_basic.rb}, %q{examples/example_command_override.rb}, %q{examples/example_commands.rb}, %q{examples/example_hooks.rb}, %q{examples/example_image_edit.rb}, %q{examples/example_input.rb}, %q{examples/example_input2.rb}, %q{examples/example_output.rb}, %q{examples/example_print.rb}, %q{examples/example_prompt.rb}, %q{examples/helper.rb}, %q{lib/pry.rb}, %q{lib/pry/cli.rb}, %q{lib/pry/command.rb}, %q{lib/pry/command_set.rb}, %q{lib/pry/commands.rb}, %q{lib/pry/completion.rb}, %q{lib/pry/config.rb}, %q{lib/pry/core_extensions.rb}, %q{lib/pry/custom_completions.rb}, %q{lib/pry/default_commands/basic.rb}, %q{lib/pry/default_commands/context.rb}, %q{lib/pry/default_commands/documentation.rb}, %q{lib/pry/default_commands/easter_eggs.rb}, %q{lib/pry/default_commands/gems.rb}, %q{lib/pry/default_commands/input.rb}, %q{lib/pry/default_commands/introspection.rb}, %q{lib/pry/default_commands/ls.rb}, %q{lib/pry/default_commands/shell.rb}, %q{lib/pry/extended_commands/experimental.rb}, %q{lib/pry/extended_commands/user_command_api.rb}, %q{lib/pry/helpers.rb}, %q{lib/pry/helpers/base_helpers.rb}, %q{lib/pry/helpers/command_helpers.rb}, %q{lib/pry/helpers/options_helpers.rb}, %q{lib/pry/helpers/text.rb}, %q{lib/pry/history.rb}, %q{lib/pry/history_array.rb}, %q{lib/pry/hooks.rb}, %q{lib/pry/indent.rb}, %q{lib/pry/method.rb}, %q{lib/pry/plugins.rb}, %q{lib/pry/pry_class.rb}, %q{lib/pry/pry_instance.rb}, %q{lib/pry/rbx_method.rb}, %q{lib/pry/rbx_path.rb}, %q{lib/pry/version.rb}, %q{lib/pry/wrapped_module.rb}, %q{man/pry.1}, %q{man/pry.1.html}, %q{man/pry.1.ronn}, %q{pry.gemspec}, %q{test/helper.rb}, %q{test/test_cli.rb}, %q{test/test_command.rb}, %q{test/test_command_helpers.rb}, %q{test/test_command_integration.rb}, %q{test/test_command_set.rb}, %q{test/test_completion.rb}, %q{test/test_default_commands.rb}, %q{test/test_default_commands/test_context.rb}, %q{test/test_default_commands/test_documentation.rb}, %q{test/test_default_commands/test_gems.rb}, %q{test/test_default_commands/test_input.rb}, %q{test/test_default_commands/test_introspection.rb}, %q{test/test_default_commands/test_ls.rb}, %q{test/test_default_commands/test_shell.rb}, %q{test/test_exception_whitelist.rb}, %q{test/test_history_array.rb}, %q{test/test_hooks.rb}, %q{test/test_indent.rb}, %q{test/test_input_stack.rb}, %q{test/test_method.rb}, %q{test/test_pry.rb}, %q{test/test_pry_defaults.rb}, %q{test/test_pry_history.rb}, %q{test/test_pry_output.rb}, %q{test/test_special_locals.rb}, %q{test/test_syntax_checking.rb}, %q{test/test_wrapped_module.rb}, %q{test/testrc}, %q{test/testrcbad}, %q{wiki/Customizing-pry.md}, %q{wiki/Home.md}]
14
+ s.homepage = %q{http://pry.github.com}
15
+ s.require_paths = [%q{lib}]
16
+ s.rubygems_version = %q{1.8.6}
17
+ s.summary = %q{An IRB alternative and runtime developer console}
18
+ s.test_files = [%q{test/helper.rb}, %q{test/test_cli.rb}, %q{test/test_command.rb}, %q{test/test_command_helpers.rb}, %q{test/test_command_integration.rb}, %q{test/test_command_set.rb}, %q{test/test_completion.rb}, %q{test/test_default_commands.rb}, %q{test/test_default_commands/test_context.rb}, %q{test/test_default_commands/test_documentation.rb}, %q{test/test_default_commands/test_gems.rb}, %q{test/test_default_commands/test_input.rb}, %q{test/test_default_commands/test_introspection.rb}, %q{test/test_default_commands/test_ls.rb}, %q{test/test_default_commands/test_shell.rb}, %q{test/test_exception_whitelist.rb}, %q{test/test_history_array.rb}, %q{test/test_hooks.rb}, %q{test/test_indent.rb}, %q{test/test_input_stack.rb}, %q{test/test_method.rb}, %q{test/test_pry.rb}, %q{test/test_pry_defaults.rb}, %q{test/test_pry_history.rb}, %q{test/test_pry_output.rb}, %q{test/test_special_locals.rb}, %q{test/test_syntax_checking.rb}, %q{test/test_wrapped_module.rb}, %q{test/testrc}, %q{test/testrcbad}]
19
19
 
20
20
  if s.respond_to? :specification_version then
21
21
  s.specification_version = 3
@@ -0,0 +1,512 @@
1
+ require 'helper'
2
+ describe "commands" do
3
+ it 'should interpolate ruby code into commands' do
4
+ klass = Pry::CommandSet.new do
5
+ command "hello", "", :keep_retval => true do |arg|
6
+ arg
7
+ end
8
+ end
9
+
10
+ $test_interpolation = "bing"
11
+ str_output = StringIO.new
12
+ Pry.new(:input => StringIO.new('hello #{$test_interpolation}'), :output => str_output, :commands => klass).rep
13
+ str_output.string.should =~ /bing/
14
+ $test_interpolation = nil
15
+ end
16
+
17
+ # bug fix for https://github.com/pry/pry/issues/170
18
+ it 'should not choke on complex string interpolation when checking if ruby code is a command' do
19
+ redirect_pry_io(InputTester.new('/#{Regexp.escape(File.expand_path("."))}/'), str_output = StringIO.new) do
20
+ pry
21
+ end
22
+
23
+ str_output.string.should.not =~ /SyntaxError/
24
+ end
25
+
26
+ it 'should NOT interpolate ruby code into commands if :interpolate => false' do
27
+ klass = Pry::CommandSet.new do
28
+ command "hello", "", :keep_retval => true, :interpolate => false do |arg|
29
+ arg
30
+ end
31
+ end
32
+
33
+ $test_interpolation = "bing"
34
+ str_output = StringIO.new
35
+ Pry.new(:input => StringIO.new('hello #{$test_interpolation}'), :output => str_output, :commands => klass).rep
36
+ str_output.string.should =~ /test_interpolation/
37
+ $test_interpolation = nil
38
+ end
39
+
40
+ it 'should NOT try to interpolate pure ruby code (no commands) ' do
41
+ str_output = StringIO.new
42
+ Pry.new(:input => StringIO.new('format \'#{aggy}\''), :output => str_output).rep
43
+ str_output.string.should.not =~ /NameError/
44
+
45
+ Pry.new(:input => StringIO.new('format #{aggy}'), :output => str_output).rep
46
+ str_output.string.should.not =~ /NameError/
47
+
48
+ $test_interpolation = "blah"
49
+ Pry.new(:input => StringIO.new('format \'#{$test_interpolation}\''), :output => str_output).rep
50
+
51
+ str_output.string.should.not =~ /blah/
52
+ $test_interpolation = nil
53
+ end
54
+
55
+ it 'should create a command with a space in its name' do
56
+ set = Pry::CommandSet.new do
57
+ command "hello baby", "" do
58
+ output.puts "hello baby command"
59
+ end
60
+ end
61
+
62
+ str_output = StringIO.new
63
+ redirect_pry_io(InputTester.new("hello baby", "exit-all"), str_output) do
64
+ Pry.new(:commands => set).rep
65
+ end
66
+
67
+ str_output.string.should =~ /hello baby command/
68
+ end
69
+
70
+ it 'should create a command with a space in its name and pass an argument' do
71
+ set = Pry::CommandSet.new do
72
+ command "hello baby", "" do |arg|
73
+ output.puts "hello baby command #{arg}"
74
+ end
75
+ end
76
+
77
+ str_output = StringIO.new
78
+ redirect_pry_io(InputTester.new("hello baby john"), str_output) do
79
+ Pry.new(:commands => set).rep
80
+ end
81
+
82
+ str_output.string.should =~ /hello baby command john/
83
+ end
84
+
85
+ it 'should create a regex command and be able to invoke it' do
86
+ set = Pry::CommandSet.new do
87
+ command /hello(.)/, "" do
88
+ c = captures.first
89
+ output.puts "hello#{c}"
90
+ end
91
+ end
92
+
93
+ str_output = StringIO.new
94
+ redirect_pry_io(InputTester.new("hello1"), str_output) do
95
+ Pry.new(:commands => set).rep
96
+ end
97
+
98
+ str_output.string.should =~ /hello1/
99
+ end
100
+
101
+ it 'should create a regex command and pass captures into the args list before regular arguments' do
102
+ set = Pry::CommandSet.new do
103
+ command /hello(.)/, "" do |c1, a1|
104
+ output.puts "hello #{c1} #{a1}"
105
+ end
106
+ end
107
+
108
+ str_output = StringIO.new
109
+ redirect_pry_io(InputTester.new("hello1 baby"), str_output) do
110
+ Pry.new(:commands => set).rep
111
+ end
112
+
113
+ str_output.string.should =~ /hello 1 baby/
114
+ end
115
+
116
+ it 'should create a regex command and interpolate the captures' do
117
+ set = Pry::CommandSet.new do
118
+ command /hello (.*)/, "" do |c1|
119
+ output.puts "hello #{c1}"
120
+ end
121
+ end
122
+
123
+ str_output = StringIO.new
124
+ $obj = "bing"
125
+ redirect_pry_io(InputTester.new('hello #{$obj}'), str_output) do
126
+ Pry.new(:commands => set).rep
127
+ end
128
+
129
+ str_output.string.should =~ /hello bing/
130
+ $obj = nil
131
+ end
132
+
133
+ it 'should create a regex command and arg_string should be interpolated' do
134
+ set = Pry::CommandSet.new do
135
+ command /hello(\w+)/, "" do |c1, a1, a2, a3|
136
+ output.puts "hello #{c1} #{a1} #{a2} #{a3}"
137
+ end
138
+ end
139
+
140
+ str_output = StringIO.new
141
+ $a1 = "bing"
142
+ $a2 = "bong"
143
+ $a3 = "bang"
144
+ redirect_pry_io(InputTester.new('hellojohn #{$a1} #{$a2} #{$a3}'), str_output) do
145
+ Pry.new(:commands => set).rep
146
+ end
147
+
148
+ str_output.string.should =~ /hello john bing bong bang/
149
+
150
+ $a1 = nil
151
+ $a2 = nil
152
+ $a3 = nil
153
+ end
154
+
155
+
156
+ it 'if a regex capture is missing it should be nil' do
157
+ set = Pry::CommandSet.new do
158
+ command /hello(.)?/, "" do |c1, a1|
159
+ output.puts "hello #{c1.inspect} #{a1}"
160
+ end
161
+ end
162
+
163
+ str_output = StringIO.new
164
+ redirect_pry_io(InputTester.new("hello baby"), str_output) do
165
+ Pry.new(:commands => set).rep
166
+ end
167
+
168
+ str_output.string.should =~ /hello nil baby/
169
+ end
170
+
171
+ it 'should create a command in a nested context and that command should be accessible from the parent' do
172
+ str_output = StringIO.new
173
+ x = "@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"
174
+ redirect_pry_io(StringIO.new("@x=nil\ncd 7\n_pry_.commands.instance_eval {\ncommand('bing') { |arg| run arg }\n}\ncd ..\nbing ls\nexit-all"), str_output) do
175
+ Pry.new.repl(0)
176
+ end
177
+
178
+ str_output.string.should =~ /@x/
179
+ end
180
+
181
+ it 'should define a command that keeps its return value' do
182
+ klass = Pry::CommandSet.new do
183
+ command "hello", "", :keep_retval => true do
184
+ :kept_hello
185
+ end
186
+ end
187
+ str_output = StringIO.new
188
+ Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
189
+ str_output.string.should =~ /:kept_hello/
190
+ str_output.string.should =~ /=>/
191
+ end
192
+
193
+ it 'should define a command that does NOT keep its return value' do
194
+ klass = Pry::CommandSet.new do
195
+ command "hello", "", :keep_retval => false do
196
+ :kept_hello
197
+ end
198
+ end
199
+ str_output = StringIO.new
200
+ Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
201
+ (str_output.string =~ /:kept_hello/).should == nil
202
+ str_output.string !~ /=>/
203
+ end
204
+
205
+ it 'should define a command that keeps its return value even when nil' do
206
+ klass = Pry::CommandSet.new do
207
+ command "hello", "", :keep_retval => true do
208
+ nil
209
+ end
210
+ end
211
+ str_output = StringIO.new
212
+ Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
213
+ str_output.string.should =~ /nil/
214
+ str_output.string.should =~ /=>/
215
+ end
216
+
217
+ it 'should define a command that keeps its return value but does not return when value is void' do
218
+ klass = Pry::CommandSet.new do
219
+ command "hello", "", :keep_retval => true do
220
+ void
221
+ end
222
+ end
223
+ str_output = StringIO.new
224
+ Pry.new(:input => StringIO.new("hello\n"), :output => str_output, :commands => klass).rep
225
+ str_output.string.empty?.should == true
226
+ end
227
+
228
+ it 'a command (with :keep_retval => false) that replaces eval_string with a valid expression should not have the expression value suppressed' do
229
+ klass = Pry::CommandSet.new do
230
+ command "hello", "" do
231
+ eval_string.replace("6")
232
+ end
233
+ end
234
+ str_output = StringIO.new
235
+ Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
236
+ str_output.string.should =~ /6/
237
+ end
238
+
239
+
240
+ it 'a command (with :keep_retval => true) that replaces eval_string with a valid expression should overwrite the eval_string with the return value' do
241
+ klass = Pry::CommandSet.new do
242
+ command "hello", "", :keep_retval => true do
243
+ eval_string.replace("6")
244
+ 7
245
+ end
246
+ end
247
+ str_output = StringIO.new
248
+ Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
249
+ str_output.string.should =~ /7/
250
+ str_output.string.should.not =~ /6/
251
+ end
252
+
253
+ it 'a command that return a value in a multi-line expression should clear the expression and return the value' do
254
+ klass = Pry::CommandSet.new do
255
+ command "hello", "", :keep_retval => true do
256
+ 5
257
+ end
258
+ end
259
+ str_output = StringIO.new
260
+ Pry.new(:input => StringIO.new("def yo\nhello\n"), :output => str_output, :commands => klass).rep
261
+ str_output.string.should =~ /5/
262
+ end
263
+
264
+
265
+ it 'should set the commands default, and the default should be overridable' do
266
+ klass = Pry::CommandSet.new do
267
+ command "hello" do
268
+ output.puts "hello world"
269
+ end
270
+ end
271
+
272
+ Pry.commands = klass
273
+
274
+ str_output = StringIO.new
275
+ Pry.new(:input => InputTester.new("hello"), :output => str_output).rep
276
+ str_output.string.should =~ /hello world/
277
+
278
+ other_klass = Pry::CommandSet.new do
279
+ command "goodbye", "" do
280
+ output.puts "goodbye world"
281
+ end
282
+ end
283
+
284
+ str_output = StringIO.new
285
+
286
+ Pry.new(:input => InputTester.new("goodbye"), :output => str_output, :commands => other_klass).rep
287
+ str_output.string.should =~ /goodbye world/
288
+ end
289
+
290
+ it 'should inherit "help" command from Pry::CommandBase' do
291
+ klass = Pry::CommandSet.new do
292
+ command "h", "h command" do
293
+ end
294
+ end
295
+
296
+ klass.commands.keys.size.should == 3
297
+ klass.commands.keys.include?("help").should == true
298
+ klass.commands.keys.include?("install-command").should == true
299
+ klass.commands.keys.include?("h").should == true
300
+ end
301
+
302
+ it 'should inherit commands from Pry::Commands' do
303
+ klass = Pry::CommandSet.new Pry::Commands do
304
+ command "v" do
305
+ end
306
+ end
307
+
308
+ klass.commands.include?("nesting").should == true
309
+ klass.commands.include?("jump-to").should == true
310
+ klass.commands.include?("cd").should == true
311
+ klass.commands.include?("v").should == true
312
+ end
313
+
314
+ it 'should alias a command with another command' do
315
+ klass = Pry::CommandSet.new do
316
+ alias_command "help2", "help"
317
+ end
318
+ klass.commands["help2"].block.should == klass.commands["help"].block
319
+ end
320
+
321
+ it 'should change description of a command using desc' do
322
+ klass = Pry::CommandSet.new do; end
323
+ orig = klass.commands["help"].description
324
+ klass.instance_eval do
325
+ desc "help", "blah"
326
+ end
327
+ klass.commands["help"].description.should.not == orig
328
+ klass.commands["help"].description.should == "blah"
329
+ end
330
+
331
+ it 'should run a command from within a command' do
332
+ klass = Pry::CommandSet.new do
333
+ command "v" do
334
+ output.puts "v command"
335
+ end
336
+
337
+ command "run_v" do
338
+ run "v"
339
+ end
340
+ end
341
+
342
+ str_output = StringIO.new
343
+ Pry.new(:input => InputTester.new("run_v"), :output => str_output, :commands => klass).rep
344
+ str_output.string.should =~ /v command/
345
+ end
346
+
347
+ it 'should run a regex command from within a command' do
348
+ klass = Pry::CommandSet.new do
349
+ command /v(.*)?/ do |arg|
350
+ output.puts "v #{arg}"
351
+ end
352
+
353
+ command "run_v" do
354
+ run "vbaby"
355
+ end
356
+ end
357
+
358
+ str_output = StringIO.new
359
+ redirect_pry_io(InputTester.new("run_v"), str_output) do
360
+ Pry.new(:commands => klass).rep
361
+ end
362
+
363
+ str_output.string.should =~ /v baby/
364
+ end
365
+
366
+ it 'should run a command from within a command with arguments' do
367
+ klass = Pry::CommandSet.new do
368
+ command /v(\w+)/ do |arg1, arg2|
369
+ output.puts "v #{arg1} #{arg2}"
370
+ end
371
+
372
+ command "run_v_explicit_parameter" do
373
+ run "vbaby", "param"
374
+ end
375
+
376
+ command "run_v_embedded_parameter" do
377
+ run "vbaby param"
378
+ end
379
+ end
380
+
381
+ ["run_v_explicit_parameter", "run_v_embedded_parameter"].each do |cmd|
382
+ str_output = StringIO.new
383
+ redirect_pry_io(InputTester.new(cmd), str_output) do
384
+ Pry.new(:commands => klass).rep
385
+ end
386
+ str_output.string.should =~ /v baby param/
387
+ end
388
+ end
389
+
390
+ it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
391
+ klass = Pry::CommandSet.new do
392
+ command "v" do
393
+ output.puts "#{target.eval('self')}"
394
+ end
395
+ end
396
+
397
+ child_klass = Pry::CommandSet.new klass do
398
+ end
399
+
400
+ str_output = StringIO.new
401
+ Pry.new(:print => proc {}, :input => InputTester.new("v"),
402
+ :output => str_output, :commands => child_klass).rep("john")
403
+
404
+ str_output.string.rstrip.should == "john"
405
+ end
406
+
407
+ it 'should import commands from another command object' do
408
+ klass = Pry::CommandSet.new do
409
+ import_from Pry::Commands, "ls", "jump-to"
410
+ end
411
+
412
+ klass.commands.include?("ls").should == true
413
+ klass.commands.include?("jump-to").should == true
414
+ end
415
+
416
+ it 'should delete some inherited commands when using delete method' do
417
+ klass = Pry::CommandSet.new Pry::Commands do
418
+ command "v" do
419
+ end
420
+
421
+ delete "show-doc", "show-method"
422
+ delete "ls"
423
+ end
424
+
425
+ klass.commands.include?("nesting").should == true
426
+ klass.commands.include?("jump-to").should == true
427
+ klass.commands.include?("cd").should == true
428
+ klass.commands.include?("v").should == true
429
+ klass.commands.include?("show-doc").should == false
430
+ klass.commands.include?("show-method").should == false
431
+ klass.commands.include?("ls").should == false
432
+ end
433
+
434
+ it 'should override some inherited commands' do
435
+ klass = Pry::CommandSet.new Pry::Commands do
436
+ command "jump-to" do
437
+ output.puts "jump-to the music"
438
+ end
439
+
440
+ command "help" do
441
+ output.puts "help to the music"
442
+ end
443
+ end
444
+
445
+ # suppress evaluation output
446
+ Pry.print = proc {}
447
+
448
+ str_output = StringIO.new
449
+ Pry.new(:input => InputTester.new("jump-to"), :output => str_output, :commands => klass).rep
450
+ str_output.string.rstrip.should == "jump-to the music"
451
+
452
+ str_output = StringIO.new
453
+ Pry.new(:input => InputTester.new("help"), :output => str_output, :commands => klass).rep
454
+ str_output.string.rstrip.should == "help to the music"
455
+
456
+
457
+ Pry.reset_defaults
458
+ Pry.color = false
459
+ end
460
+
461
+ it 'should run a command with no parameter' do
462
+ pry_tester = Pry.new
463
+ pry_tester.commands = CommandTester
464
+ pry_tester.input = InputTester.new("command1", "exit-all")
465
+ pry_tester.commands = CommandTester
466
+
467
+ str_output = StringIO.new
468
+ pry_tester.output = str_output
469
+
470
+ pry_tester.rep
471
+
472
+ str_output.string.should =~ /command1/
473
+ end
474
+
475
+ it 'should run a command with one parameter' do
476
+ pry_tester = Pry.new
477
+ pry_tester.commands = CommandTester
478
+ pry_tester.input = InputTester.new("command2 horsey", "exit-all")
479
+ pry_tester.commands = CommandTester
480
+
481
+ str_output = StringIO.new
482
+ pry_tester.output = str_output
483
+
484
+ pry_tester.rep
485
+
486
+ str_output.string.should =~ /horsey/
487
+ end
488
+ end
489
+
490
+ describe "Pry#run_command" do
491
+ it 'should run a command in a specified context' do
492
+ b = Pry.binding_for(7)
493
+ p = Pry.new(:output => StringIO.new)
494
+ p.run_command("ls -m", "", b)
495
+ p.output.string.should =~ /divmod/
496
+ end
497
+
498
+ it 'should run a command that modifies the passed in eval_string' do
499
+ b = Pry.binding_for(7)
500
+ p = Pry.new(:output => StringIO.new)
501
+ eval_string = "def hello\npeter pan\n"
502
+ p.run_command("amend-line !", eval_string, b)
503
+ eval_string.should =~ /def hello/
504
+ eval_string.should.not =~ /peter pan/
505
+ end
506
+
507
+ it 'should run a command in the context of a session' do
508
+ mock_pry("@session_ivar = 10", "_pry_.run_command('ls')").should =~ /@session_ivar/
509
+ end
510
+ end
511
+
512
+