pry 0.9.0pre3-java → 0.9.4pre2-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.
- data/.gitignore +1 -0
- data/CHANGELOG +84 -6
- data/CONTRIBUTORS +13 -0
- data/README.markdown +23 -183
- data/Rakefile +22 -19
- data/TODO +36 -6
- data/bin/pry +12 -1
- data/lib/pry.rb +60 -12
- data/lib/pry/command_context.rb +21 -0
- data/lib/pry/command_processor.rb +62 -16
- data/lib/pry/command_set.rb +25 -11
- data/lib/pry/commands.rb +0 -3
- data/lib/pry/completion.rb +6 -6
- data/lib/pry/config.rb +25 -5
- data/lib/pry/default_commands/basic.rb +27 -6
- data/lib/pry/default_commands/context.rb +84 -35
- data/lib/pry/default_commands/documentation.rb +69 -31
- data/lib/pry/default_commands/easter_eggs.rb +5 -0
- data/lib/pry/default_commands/input.rb +193 -56
- data/lib/pry/default_commands/introspection.rb +98 -50
- data/lib/pry/default_commands/ls.rb +51 -21
- data/lib/pry/default_commands/shell.rb +57 -13
- data/lib/pry/extended_commands/experimental.rb +0 -32
- data/lib/pry/extended_commands/user_command_api.rb +33 -2
- data/lib/pry/helpers/base_helpers.rb +30 -10
- data/lib/pry/helpers/command_helpers.rb +75 -16
- data/lib/pry/helpers/text.rb +12 -11
- data/lib/pry/history.rb +61 -0
- data/lib/pry/plugins.rb +23 -12
- data/lib/pry/pry_class.rb +51 -50
- data/lib/pry/pry_instance.rb +129 -119
- data/lib/pry/version.rb +1 -1
- data/pry.gemspec +46 -0
- data/test/helper.rb +37 -3
- data/test/test_command_processor.rb +62 -19
- data/test/test_command_set.rb +40 -2
- data/test/test_completion.rb +27 -0
- data/test/test_default_commands/test_context.rb +185 -1
- data/test/test_default_commands/test_documentation.rb +10 -0
- data/test/test_default_commands/test_input.rb +207 -11
- data/test/test_default_commands/test_introspection.rb +20 -1
- data/test/test_default_commands/test_shell.rb +18 -0
- data/test/test_pry.rb +261 -45
- data/test/test_pry_history.rb +82 -0
- data/test/test_pry_output.rb +44 -0
- data/test/test_special_locals.rb +35 -0
- metadata +185 -159
data/lib/pry/version.rb
CHANGED
data/pry.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{pry}
|
5
|
+
s.version = "0.9.4pre1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = [%q{John Mair (banisterfiend)}]
|
9
|
+
s.date = %q{2011-09-07}
|
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{.yardopts}, %q{CHANGELOG}, %q{CONTRIBUTORS}, %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/command_context.rb}, %q{lib/pry/command_processor.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/text.rb}, %q{lib/pry/history.rb}, %q{lib/pry/history_array.rb}, %q{lib/pry/plugins.rb}, %q{lib/pry/pry_class.rb}, %q{lib/pry/pry_instance.rb}, %q{lib/pry/version.rb}, %q{pry.gemspec}, %q{test/helper.rb}, %q{test/test_command_helpers.rb}, %q{test/test_command_processor.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_shell.rb}, %q{test/test_history_array.rb}, %q{test/test_pry.rb}, %q{test/test_pry_history.rb}, %q{test/test_pry_output.rb}, %q{test/test_special_locals.rb}, %q{test/testrc}, %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_command_helpers.rb}, %q{test/test_command_processor.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_shell.rb}, %q{test/test_history_array.rb}, %q{test/test_pry.rb}, %q{test/test_pry_history.rb}, %q{test/test_pry_output.rb}, %q{test/test_special_locals.rb}, %q{test/testrc}]
|
19
|
+
|
20
|
+
if s.respond_to? :specification_version then
|
21
|
+
s.specification_version = 3
|
22
|
+
|
23
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
24
|
+
s.add_runtime_dependency(%q<ruby_parser>, [">= 2.0.5"])
|
25
|
+
s.add_runtime_dependency(%q<coderay>, [">= 0.9.8"])
|
26
|
+
s.add_runtime_dependency(%q<slop>, ["~> 2.1.0"])
|
27
|
+
s.add_runtime_dependency(%q<method_source>, [">= 0.6.0"])
|
28
|
+
s.add_development_dependency(%q<bacon>, [">= 1.1.0"])
|
29
|
+
s.add_development_dependency(%q<open4>, ["~> 1.0.1"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<ruby_parser>, [">= 2.0.5"])
|
32
|
+
s.add_dependency(%q<coderay>, [">= 0.9.8"])
|
33
|
+
s.add_dependency(%q<slop>, ["~> 2.1.0"])
|
34
|
+
s.add_dependency(%q<method_source>, [">= 0.6.0"])
|
35
|
+
s.add_dependency(%q<bacon>, [">= 1.1.0"])
|
36
|
+
s.add_dependency(%q<open4>, ["~> 1.0.1"])
|
37
|
+
end
|
38
|
+
else
|
39
|
+
s.add_dependency(%q<ruby_parser>, [">= 2.0.5"])
|
40
|
+
s.add_dependency(%q<coderay>, [">= 0.9.8"])
|
41
|
+
s.add_dependency(%q<slop>, ["~> 2.1.0"])
|
42
|
+
s.add_dependency(%q<method_source>, [">= 0.6.0"])
|
43
|
+
s.add_dependency(%q<bacon>, [">= 1.1.0"])
|
44
|
+
s.add_dependency(%q<open4>, ["~> 1.0.1"])
|
45
|
+
end
|
46
|
+
end
|
data/test/helper.rb
CHANGED
@@ -20,18 +20,38 @@ class << Pry
|
|
20
20
|
Pry.pager = false
|
21
21
|
Pry.config.should_load_rc = false
|
22
22
|
Pry.config.plugins.enabled = false
|
23
|
-
Pry.config.history.
|
24
|
-
Pry.config.history.
|
23
|
+
Pry.config.history.should_load = false
|
24
|
+
Pry.config.history.should_save = false
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
# are we on Jruby platform?
|
29
|
+
def jruby?
|
30
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
|
31
|
+
end
|
32
|
+
|
33
|
+
# are we on rbx platform?
|
34
|
+
def rbx?
|
35
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
|
36
|
+
end
|
37
|
+
|
28
38
|
Pry.reset_defaults
|
29
39
|
|
40
|
+
# this is to test exception code (cat --ex)
|
41
|
+
def broken_method
|
42
|
+
this method is broken
|
43
|
+
end
|
44
|
+
|
30
45
|
# sample doc
|
31
46
|
def sample_method
|
32
47
|
:sample
|
33
48
|
end
|
34
49
|
|
50
|
+
# another sample doc
|
51
|
+
def another_sample_method
|
52
|
+
:another_sample
|
53
|
+
end
|
54
|
+
|
35
55
|
def redirect_pry_io(new_in, new_out)
|
36
56
|
old_in = Pry.input
|
37
57
|
old_out = Pry.output
|
@@ -46,6 +66,17 @@ def redirect_pry_io(new_in, new_out)
|
|
46
66
|
end
|
47
67
|
end
|
48
68
|
|
69
|
+
def mock_pry(*args)
|
70
|
+
input = InputTester.new(*args)
|
71
|
+
output = StringIO.new
|
72
|
+
|
73
|
+
redirect_pry_io(input, output) do
|
74
|
+
Pry.start
|
75
|
+
end
|
76
|
+
|
77
|
+
output.string
|
78
|
+
end
|
79
|
+
|
49
80
|
def redirect_global_pry_input(new_io)
|
50
81
|
old_io = Pry.input
|
51
82
|
Pry.input = new_io
|
@@ -74,12 +105,15 @@ end
|
|
74
105
|
|
75
106
|
class InputTester
|
76
107
|
def initialize(*actions)
|
108
|
+
if actions.last.is_a?(Hash) && actions.last.keys == [:history]
|
109
|
+
@hist = actions.pop[:history]
|
110
|
+
end
|
77
111
|
@orig_actions = actions.dup
|
78
112
|
@actions = actions
|
79
113
|
end
|
80
114
|
|
81
115
|
def readline(*)
|
82
|
-
@actions.shift
|
116
|
+
@actions.shift.tap{ |line| @hist << line if @hist }
|
83
117
|
end
|
84
118
|
|
85
119
|
def rewind
|
@@ -18,9 +18,6 @@ describe "Pry::CommandProcessor" do
|
|
18
18
|
|
19
19
|
valid = @command_processor.valid_command? "blah"
|
20
20
|
valid.should == false
|
21
|
-
|
22
|
-
a = "test-command"
|
23
|
-
lambda { @command_processor.valid_command? '#{a}' }.should.raise NameError
|
24
21
|
end
|
25
22
|
|
26
23
|
it 'should correctly match a simple string command' do
|
@@ -84,6 +81,57 @@ describe "Pry::CommandProcessor" do
|
|
84
81
|
pos.should == command.name.length
|
85
82
|
end
|
86
83
|
|
84
|
+
it 'should correctly match a command preceded by the command_prefix if one is defined' do
|
85
|
+
Pry.config.command_prefix = "%"
|
86
|
+
|
87
|
+
@pry.commands.command("test-command") {}
|
88
|
+
command, captures, pos = @command_processor.command_matched "%test-command hello", binding
|
89
|
+
|
90
|
+
command.name.should == "test-command"
|
91
|
+
captures.should == []
|
92
|
+
pos.should == "test-command".length + "%".length
|
93
|
+
|
94
|
+
Pry.config.command_prefix = ''
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should not match a command not preceded by the command_prefix if one is defined' do
|
98
|
+
Pry.config.command_prefix = "%"
|
99
|
+
|
100
|
+
@pry.commands.command("test-command") {}
|
101
|
+
command, captures, pos = @command_processor.command_matched "test-command hello", binding
|
102
|
+
|
103
|
+
command.should == nil
|
104
|
+
captures.should == nil
|
105
|
+
|
106
|
+
Pry.config.command_prefix = ''
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should match a command preceded by the command_prefix when :use_prefix => false' do
|
110
|
+
Pry.config.command_prefix = "%"
|
111
|
+
|
112
|
+
@pry.commands.command("test-command", "", :use_prefix => false) {}
|
113
|
+
command, captures, pos = @command_processor.command_matched "%test-command hello", binding
|
114
|
+
|
115
|
+
command.name.should == "test-command"
|
116
|
+
captures.should == []
|
117
|
+
pos.should == "test-command".length + "%".length
|
118
|
+
|
119
|
+
Pry.config.command_prefix = ''
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should match a command not preceded by the command_prefix when :use_prefix => false' do
|
123
|
+
Pry.config.command_prefix = "%"
|
124
|
+
|
125
|
+
@pry.commands.command("test-command", "", :use_prefix => false) {}
|
126
|
+
command, captures, pos = @command_processor.command_matched "test-command hello", binding
|
127
|
+
|
128
|
+
command.name.should == "test-command"
|
129
|
+
captures.should == []
|
130
|
+
pos.should == "test-command".length
|
131
|
+
|
132
|
+
Pry.config.command_prefix = ''
|
133
|
+
end
|
134
|
+
|
87
135
|
it 'should correctly match a regex command with spaces in its name' do
|
88
136
|
regex_command_name = /test\s+(.+)\s+command/
|
89
137
|
@pry.commands.command(regex_command_name) {}
|
@@ -108,26 +156,21 @@ describe "Pry::CommandProcessor" do
|
|
108
156
|
pos.should == sample_text.size
|
109
157
|
end
|
110
158
|
|
111
|
-
it 'should
|
112
|
-
@pry.commands.command("blah") {}
|
113
|
-
a = "bl"
|
114
|
-
b = "ah"
|
115
|
-
command, captures, pos = @command_processor.command_matched '#{a}#{b}', binding
|
116
|
-
|
117
|
-
command.name.should == "blah"
|
118
|
-
captures.should == []
|
119
|
-
pos.should == command.name.length
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'should NOT match a command whose name is interpolated when :interpolate => false' do
|
159
|
+
it 'should not interpolate commands that have :interpolate => false (interpolate_string should *not* be called)' do
|
123
160
|
@pry.commands.command("boast", "", :interpolate => false) {}
|
124
|
-
a = "boa"
|
125
|
-
b = "st"
|
126
161
|
|
127
162
|
# remember to use '' instead of "" when testing interpolation or
|
128
163
|
# you'll cause yourself incredible confusion
|
129
|
-
|
164
|
+
lambda { @command_processor.command_matched('boast #{c}', binding) }.should.not.raise NameError
|
165
|
+
end
|
130
166
|
|
131
|
-
|
167
|
+
it 'should only execute the contents of an interpolation once' do
|
168
|
+
$obj = 'a'
|
169
|
+
|
170
|
+
redirect_pry_io(InputTester.new('cat #{$obj.succ!}'), StringIO.new) do
|
171
|
+
Pry.new.rep
|
172
|
+
end
|
173
|
+
|
174
|
+
$obj.should == 'b'
|
132
175
|
end
|
133
176
|
end
|
data/test/test_command_set.rb
CHANGED
@@ -112,9 +112,9 @@ describe Pry::CommandSet do
|
|
112
112
|
@set.commands['foo'].description.should == 'baz'
|
113
113
|
end
|
114
114
|
|
115
|
-
it 'should return
|
115
|
+
it 'should return Pry::CommandContext::VOID_VALUE for commands by default' do
|
116
116
|
@set.command('foo') { 3 }
|
117
|
-
@set.run_command(nil, 'foo').should ==
|
117
|
+
@set.run_command(nil, 'foo').should == Pry::CommandContext::VOID_VALUE
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'should be able to keep return values' do
|
@@ -122,6 +122,11 @@ describe Pry::CommandSet do
|
|
122
122
|
@set.run_command(nil, 'foo').should == 3
|
123
123
|
end
|
124
124
|
|
125
|
+
it 'should be able to keep return values, even if return value is nil' do
|
126
|
+
@set.command('foo', '', :keep_retval => true) { nil }
|
127
|
+
@set.run_command(nil, 'foo').should == nil
|
128
|
+
end
|
129
|
+
|
125
130
|
it 'should be able to have its own helpers' do
|
126
131
|
@set.command('foo') do
|
127
132
|
should.respond_to :my_helper
|
@@ -187,4 +192,37 @@ describe Pry::CommandSet do
|
|
187
192
|
@set.command 'foo', "", :listing => 'bar' do;end
|
188
193
|
@set.commands['foo'].options[:listing].should == 'bar'
|
189
194
|
end
|
195
|
+
|
196
|
+
it "should provide a 'help' command" do
|
197
|
+
context = Pry::CommandContext.new
|
198
|
+
context.command_set = @set
|
199
|
+
context.output = StringIO.new
|
200
|
+
|
201
|
+
lambda {
|
202
|
+
@set.run_command(context, 'help')
|
203
|
+
}.should.not.raise
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should sort the output of the 'help' command" do
|
207
|
+
@set.command 'foo', "Fooerizes" do; end
|
208
|
+
@set.command 'goo', "Gooerizes" do; end
|
209
|
+
@set.command 'moo', "Mooerizes" do; end
|
210
|
+
@set.command 'boo', "Booerizes" do; end
|
211
|
+
|
212
|
+
context = Pry::CommandContext.new
|
213
|
+
context.command_set = @set
|
214
|
+
context.output = StringIO.new
|
215
|
+
|
216
|
+
@set.run_command(context, 'help')
|
217
|
+
|
218
|
+
doc = context.output.string
|
219
|
+
|
220
|
+
order = [doc.index("boo"),
|
221
|
+
doc.index("foo"),
|
222
|
+
doc.index("goo"),
|
223
|
+
doc.index("help"),
|
224
|
+
doc.index("moo")]
|
225
|
+
|
226
|
+
order.should == order.sort
|
227
|
+
end
|
190
228
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Pry::InputCompleter do
|
4
|
+
|
5
|
+
before do
|
6
|
+
# The AMQP gem has some classes like this:
|
7
|
+
# pry(main)> AMQP::Protocol::Test::ContentOk.name
|
8
|
+
# => :content_ok
|
9
|
+
module SymbolyName
|
10
|
+
def self.name; :symboly_name; end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
Object.remove_const :SymbolyName
|
16
|
+
end
|
17
|
+
|
18
|
+
# another jruby hack :((
|
19
|
+
if !jruby?
|
20
|
+
it "should not crash if there's a Module that has a symbolic name." do
|
21
|
+
completer = Pry::InputCompleter.build_completion_proc(Pry.binding_for(Object.new))
|
22
|
+
binding.pry
|
23
|
+
lambda{ completer.call "a.to_s." }.should.not.raise Exception
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -1,6 +1,104 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe "Pry::DefaultCommands::Context" do
|
4
|
+
describe "exit-all" do
|
5
|
+
it 'should break out of the repl loop of Pry instance (returning target of session)' do
|
6
|
+
redirect_pry_io(InputTester.new("exit-all"), StringIO.new) do
|
7
|
+
Pry.new.repl(0).should == 0
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should break out of the repl loop of Pry instance wth a user specified value' do
|
12
|
+
redirect_pry_io(InputTester.new("exit-all 'message'"), StringIO.new) do
|
13
|
+
Pry.new.repl(0).should == 'message'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should break of the repl loop even if multiple bindings still on stack' do
|
18
|
+
ins = nil
|
19
|
+
redirect_pry_io(InputTester.new("cd 1", "cd 2", "exit-all 'message'"), StringIO.new) do
|
20
|
+
ins = Pry.new.tap { |v| v.repl(0).should == 'message' }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'binding_stack should be empty after breaking out of the repl loop' do
|
25
|
+
ins = nil
|
26
|
+
redirect_pry_io(InputTester.new("cd 1", "cd 2", "exit-all"), StringIO.new) do
|
27
|
+
ins = Pry.new.tap { |v| v.repl(0) }
|
28
|
+
end
|
29
|
+
|
30
|
+
ins.binding_stack.empty?.should == true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "exit" do
|
35
|
+
it 'should pop a binding with exit' do
|
36
|
+
b = Pry.binding_for(:outer)
|
37
|
+
b.eval("x = :inner")
|
38
|
+
|
39
|
+
redirect_pry_io(InputTester.new("cd x", "$inner = self;", "exit", "$outer = self", "exit-all"), StringIO.new) do
|
40
|
+
b.pry
|
41
|
+
end
|
42
|
+
$inner.should == :inner
|
43
|
+
$outer.should == :outer
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with exit' do
|
47
|
+
Pry.start(0, :input => StringIO.new("exit")).should == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with exit, and return user-given value' do
|
51
|
+
Pry.start(0, :input => StringIO.new("exit :john")).should == :john
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "jump-to" do
|
56
|
+
it 'should jump to the proper binding index in the stack' do
|
57
|
+
outp = StringIO.new
|
58
|
+
redirect_pry_io(InputTester.new("cd 1", "cd 2", "jump-to 1", "$blah = self", "exit-all"), outp) do
|
59
|
+
Pry.start(0)
|
60
|
+
end
|
61
|
+
|
62
|
+
$blah.should == 1
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should print error when trying to jump to a non-existent binding index' do
|
66
|
+
outp = StringIO.new
|
67
|
+
redirect_pry_io(InputTester.new("cd 1", "cd 2", "jump-to 100", "exit-all"), outp) do
|
68
|
+
Pry.start(0)
|
69
|
+
end
|
70
|
+
|
71
|
+
outp.string.should =~ /Invalid nest level/
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should print error when trying to jump to the same binding index' do
|
75
|
+
outp = StringIO.new
|
76
|
+
redirect_pry_io(InputTester.new("cd 1", "cd 2", "jump-to 2", "exit-all"), outp) do
|
77
|
+
Pry.new.repl(0)
|
78
|
+
end
|
79
|
+
|
80
|
+
outp.string.should =~ /Already/
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "exit-program" do
|
85
|
+
it 'should raise SystemExit' do
|
86
|
+
redirect_pry_io(InputTester.new("exit-program"), StringIO.new) do
|
87
|
+
lambda { Pry.new.repl(0).should == 0 }.should.raise SystemExit
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should exit the program with the provided value' do
|
92
|
+
redirect_pry_io(InputTester.new("exit-program 66"), StringIO.new) do
|
93
|
+
begin
|
94
|
+
Pry.new.repl(0)
|
95
|
+
rescue SystemExit => e
|
96
|
+
e.status.should == 66
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
4
102
|
describe "cd" do
|
5
103
|
after do
|
6
104
|
$obj = nil
|
@@ -28,6 +126,10 @@ describe "Pry::DefaultCommands::Context" do
|
|
28
126
|
$outer.should == :outer
|
29
127
|
end
|
30
128
|
|
129
|
+
it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with cd ..' do
|
130
|
+
Pry.start(0, :input => StringIO.new("cd ..")).should == 0
|
131
|
+
end
|
132
|
+
|
31
133
|
it 'should break out to outer-most session with cd /' do
|
32
134
|
b = Pry.binding_for(:outer)
|
33
135
|
b.eval("x = :inner")
|
@@ -40,9 +142,91 @@ describe "Pry::DefaultCommands::Context" do
|
|
40
142
|
$outer.should == :outer
|
41
143
|
end
|
42
144
|
|
43
|
-
it 'should
|
145
|
+
it 'should break out to outer-most session with just cd (no args)' do
|
44
146
|
b = Pry.binding_for(:outer)
|
147
|
+
b.eval("x = :inner")
|
148
|
+
|
149
|
+
redirect_pry_io(InputTester.new("cd x", "$inner = self;", "cd 5", "$five = self", "cd", "$outer = self", "exit-all"), StringIO.new) do
|
150
|
+
b.pry
|
151
|
+
end
|
152
|
+
$inner.should == :inner
|
153
|
+
$five.should == 5
|
154
|
+
$outer.should == :outer
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should cd into an object and its ivar using cd obj/@ivar syntax' do
|
158
|
+
$obj = Object.new
|
159
|
+
$obj.instance_variable_set(:@x, 66)
|
160
|
+
|
161
|
+
redirect_pry_io(InputTester.new("cd $obj/@x", "$result = _pry_.binding_stack.dup", "exit-all"), StringIO.new) do
|
162
|
+
Pry.start
|
163
|
+
end
|
164
|
+
$result.size.should == 3
|
165
|
+
$result[1].eval('self').should == $obj
|
166
|
+
$result[2].eval('self').should == 66
|
167
|
+
end
|
45
168
|
|
169
|
+
it 'should cd into an object and its ivar using cd obj/@ivar/ syntax (note following /)' do
|
170
|
+
$obj = Object.new
|
171
|
+
$obj.instance_variable_set(:@x, 66)
|
172
|
+
|
173
|
+
redirect_pry_io(InputTester.new("cd $obj/@x/", "$result = _pry_.binding_stack.dup", "exit-all"), StringIO.new) do
|
174
|
+
Pry.start
|
175
|
+
end
|
176
|
+
$result.size.should == 3
|
177
|
+
$result[1].eval('self').should == $obj
|
178
|
+
$result[2].eval('self').should == 66
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should cd into previous object and its local using cd ../local syntax' do
|
182
|
+
$obj = Object.new
|
183
|
+
$obj.instance_variable_set(:@x, 66)
|
184
|
+
|
185
|
+
redirect_pry_io(InputTester.new("cd $obj", "local = :local", "cd @x", "cd ../local", "$result = _pry_.binding_stack.dup", "exit-all"), StringIO.new) do
|
186
|
+
Pry.start
|
187
|
+
end
|
188
|
+
$result.size.should == 3
|
189
|
+
$result[1].eval('self').should == $obj
|
190
|
+
$result[2].eval('self').should == :local
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'should cd into an object and its ivar and back again using cd obj/@ivar/.. syntax' do
|
194
|
+
$obj = Object.new
|
195
|
+
$obj.instance_variable_set(:@x, 66)
|
196
|
+
|
197
|
+
redirect_pry_io(InputTester.new("cd $obj/@x/..", "$result = _pry_.binding_stack.dup", "exit-all"), StringIO.new) do
|
198
|
+
Pry.start
|
199
|
+
end
|
200
|
+
$result.size.should == 2
|
201
|
+
$result[1].eval('self').should == $obj
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'should cd into an object and its ivar and back and then into another ivar using cd obj/@ivar/../@y syntax' do
|
205
|
+
$obj = Object.new
|
206
|
+
$obj.instance_variable_set(:@x, 66)
|
207
|
+
$obj.instance_variable_set(:@y, 79)
|
208
|
+
|
209
|
+
redirect_pry_io(InputTester.new("cd $obj/@x/../@y", "$result = _pry_.binding_stack.dup", "exit-all"), StringIO.new) do
|
210
|
+
Pry.start
|
211
|
+
end
|
212
|
+
$result.size.should == 3
|
213
|
+
$result[1].eval('self').should == $obj
|
214
|
+
$result[2].eval('self').should == 79
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'should cd back to top-level and then into another ivar using cd /@ivar/ syntax' do
|
218
|
+
$obj = Object.new
|
219
|
+
$obj.instance_variable_set(:@x, 66)
|
220
|
+
TOPLEVEL_BINDING.eval('@z = 20')
|
221
|
+
|
222
|
+
redirect_pry_io(InputTester.new("cd $obj/@x/", "cd /@z", "$result = _pry_.binding_stack.dup", "exit-all"), StringIO.new) do
|
223
|
+
Pry.start
|
224
|
+
end
|
225
|
+
$result.size.should == 2
|
226
|
+
$result[1].eval('self').should == 20
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should start a session on TOPLEVEL_BINDING with cd ::' do
|
46
230
|
redirect_pry_io(InputTester.new("cd ::", "$obj = self", "exit-all"), StringIO.new) do
|
47
231
|
5.pry
|
48
232
|
end
|