pry 0.9.10pre1-java → 0.9.11-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -1
- data/CHANGELOG +63 -2
- data/CONTRIBUTORS +43 -25
- data/Gemfile +7 -0
- data/Guardfile +62 -0
- data/README.markdown +4 -4
- data/Rakefile +34 -35
- data/lib/pry.rb +107 -54
- data/lib/pry/cli.rb +34 -11
- data/lib/pry/code.rb +165 -182
- data/lib/pry/code/code_range.rb +70 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +153 -0
- data/lib/pry/command.rb +160 -22
- data/lib/pry/command_set.rb +37 -26
- 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 +53 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +78 -0
- data/lib/pry/commands/cat/file_formatter.rb +84 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +30 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/deprecated_commands.rb +2 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +206 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +38 -0
- data/lib/pry/commands/edit/method_patcher.rb +122 -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 +24 -0
- data/lib/pry/commands/find_method.rb +199 -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 +29 -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 +95 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +161 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +51 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/ls.rb +339 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +69 -0
- data/lib/pry/commands/pry_backtrace.rb +26 -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 +39 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +56 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +43 -0
- data/lib/pry/commands/shell_mode.rb +27 -0
- data/lib/pry/commands/show_doc.rb +78 -0
- data/lib/pry/commands/show_info.rb +139 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +37 -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 +20 -0
- data/lib/pry/commands/whereami.rb +114 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/completion.rb +120 -46
- data/lib/pry/config.rb +11 -0
- data/lib/pry/core_extensions.rb +30 -19
- data/lib/pry/editor.rb +129 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +89 -119
- data/lib/pry/helpers/command_helpers.rb +7 -122
- data/lib/pry/helpers/table.rb +100 -0
- data/lib/pry/helpers/text.rb +4 -4
- data/lib/pry/history_array.rb +5 -0
- data/lib/pry/hooks.rb +1 -3
- data/lib/pry/indent.rb +104 -30
- data/lib/pry/method.rb +66 -22
- data/lib/pry/module_candidate.rb +26 -15
- data/lib/pry/pager.rb +70 -0
- data/lib/pry/plugins.rb +1 -2
- data/lib/pry/pry_class.rb +63 -22
- data/lib/pry/pry_instance.rb +58 -37
- data/lib/pry/rubygem.rb +74 -0
- data/lib/pry/terminal_info.rb +43 -0
- data/lib/pry/test/helper.rb +185 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +58 -24
- data/pry.gemspec +21 -37
- data/{test/test_cli.rb → spec/cli_spec.rb} +0 -0
- data/spec/code_object_spec.rb +277 -0
- data/{test/test_code.rb → spec/code_spec.rb} +19 -1
- data/{test/test_command_helpers.rb → spec/command_helpers_spec.rb} +0 -0
- data/{test/test_command_integration.rb → spec/command_integration_spec.rb} +38 -46
- data/{test/test_command_set.rb → spec/command_set_spec.rb} +18 -1
- data/{test/test_command.rb → spec/command_spec.rb} +250 -149
- data/spec/commands/amend_line_spec.rb +247 -0
- data/spec/commands/bang_spec.rb +19 -0
- data/spec/commands/cat_spec.rb +164 -0
- data/spec/commands/cd_spec.rb +250 -0
- data/spec/commands/disable_pry_spec.rb +25 -0
- data/spec/commands/edit_spec.rb +727 -0
- data/spec/commands/exit_all_spec.rb +34 -0
- data/spec/commands/exit_program_spec.rb +19 -0
- data/spec/commands/exit_spec.rb +34 -0
- data/{test/test_default_commands/test_find_method.rb → spec/commands/find_method_spec.rb} +27 -7
- data/spec/commands/gem_list_spec.rb +26 -0
- data/spec/commands/gist_spec.rb +75 -0
- data/{test/test_default_commands/test_help.rb → spec/commands/help_spec.rb} +8 -9
- data/spec/commands/hist_spec.rb +181 -0
- data/spec/commands/jump_to_spec.rb +15 -0
- data/spec/commands/ls_spec.rb +177 -0
- data/spec/commands/play_spec.rb +140 -0
- data/spec/commands/raise_up_spec.rb +56 -0
- data/spec/commands/save_file_spec.rb +177 -0
- data/spec/commands/show_doc_spec.rb +378 -0
- data/spec/commands/show_input_spec.rb +17 -0
- data/spec/commands/show_source_spec.rb +597 -0
- data/spec/commands/whereami_spec.rb +154 -0
- data/spec/completion_spec.rb +233 -0
- data/spec/control_d_handler_spec.rb +58 -0
- data/spec/editor_spec.rb +79 -0
- data/{test/test_exception_whitelist.rb → spec/exception_whitelist_spec.rb} +0 -0
- data/{test → spec/fixtures}/candidate_helper1.rb +0 -0
- data/{test → spec/fixtures}/candidate_helper2.rb +0 -0
- data/{test/test_default_commands → spec/fixtures}/example.erb +0 -0
- data/spec/fixtures/example_nesting.rb +33 -0
- data/spec/fixtures/show_source_doc_examples.rb +15 -0
- data/{test → spec/fixtures}/testrc +0 -0
- data/{test → spec/fixtures}/testrcbad +0 -0
- data/spec/helper.rb +34 -0
- data/spec/helpers/bacon.rb +86 -0
- data/spec/helpers/mock_pry.rb +43 -0
- data/spec/helpers/table_spec.rb +83 -0
- data/{test/test_history_array.rb → spec/history_array_spec.rb} +21 -19
- data/{test/test_hooks.rb → spec/hooks_spec.rb} +0 -0
- data/{test/test_indent.rb → spec/indent_spec.rb} +24 -0
- data/{test/test_input_stack.rb → spec/input_stack_spec.rb} +4 -0
- data/{test/test_method.rb → spec/method_spec.rb} +65 -1
- data/{test/test_prompt.rb → spec/prompt_spec.rb} +0 -0
- data/{test/test_pry_defaults.rb → spec/pry_defaults_spec.rb} +14 -14
- data/{test/test_pry_history.rb → spec/pry_history_spec.rb} +15 -0
- data/spec/pry_output_spec.rb +95 -0
- data/{test/test_pry.rb → spec/pry_spec.rb} +74 -32
- data/{test/test_sticky_locals.rb → spec/sticky_locals_spec.rb} +27 -25
- data/{test/test_syntax_checking.rb → spec/syntax_checking_spec.rb} +17 -1
- data/{test/test_wrapped_module.rb → spec/wrapped_module_spec.rb} +92 -5
- metadata +239 -115
- 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/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/test/helper.rb +0 -223
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/test_cd.rb +0 -321
- data/test/test_default_commands/test_context.rb +0 -288
- data/test/test_default_commands/test_documentation.rb +0 -315
- data/test/test_default_commands/test_gems.rb +0 -18
- 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_pry_output.rb +0 -41
data/test/helper.rb
DELETED
@@ -1,223 +0,0 @@
|
|
1
|
-
unless Object.const_defined? 'Pry'
|
2
|
-
$:.unshift File.expand_path '../../lib', __FILE__
|
3
|
-
require 'pry'
|
4
|
-
end
|
5
|
-
|
6
|
-
puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Slop v#{Slop::VERSION}"
|
7
|
-
|
8
|
-
require 'bacon'
|
9
|
-
require 'open4'
|
10
|
-
|
11
|
-
# A global space for storing temporary state during tests.
|
12
|
-
Pad = OpenStruct.new
|
13
|
-
def Pad.clear
|
14
|
-
@table = {}
|
15
|
-
end
|
16
|
-
|
17
|
-
# turn warnings off (esp for Pry::Hooks which will generate warnings
|
18
|
-
# in tests)
|
19
|
-
$VERBOSE = nil
|
20
|
-
|
21
|
-
# Ensure we do not execute any rc files
|
22
|
-
Pry::RC_FILES.clear
|
23
|
-
|
24
|
-
# inject a variable into a binding
|
25
|
-
def inject_var(name, value, b)
|
26
|
-
Thread.current[:__pry_local__] = value
|
27
|
-
b.eval("#{name} = Thread.current[:__pry_local__]")
|
28
|
-
ensure
|
29
|
-
Thread.current[:__pry_local__] = nil
|
30
|
-
end
|
31
|
-
|
32
|
-
def constant_scope(*names)
|
33
|
-
names.each do |name|
|
34
|
-
Object.remove_const name if Object.const_defined?(name)
|
35
|
-
end
|
36
|
-
|
37
|
-
yield
|
38
|
-
ensure
|
39
|
-
names.each do |name|
|
40
|
-
Object.remove_const name if Object.const_defined?(name)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def mri18_and_no_real_source_location?
|
45
|
-
Pry::Helpers::BaseHelpers.mri_18? && !(Method.instance_method(:source_location).owner == Method)
|
46
|
-
end
|
47
|
-
|
48
|
-
# used by test_show_source.rb and test_documentation.rb
|
49
|
-
class TestClassForShowSource
|
50
|
-
def alpha
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class TestClassForShowSourceClassEval
|
55
|
-
def alpha
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class TestClassForShowSourceInstanceEval
|
60
|
-
def alpha
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# in case the tests call reset_defaults, ensure we reset them to
|
65
|
-
# amended (test friendly) values
|
66
|
-
class << Pry
|
67
|
-
alias_method :orig_reset_defaults, :reset_defaults
|
68
|
-
def reset_defaults
|
69
|
-
orig_reset_defaults
|
70
|
-
|
71
|
-
Pry.color = false
|
72
|
-
Pry.pager = false
|
73
|
-
Pry.config.should_load_rc = false
|
74
|
-
Pry.config.should_load_local_rc= false
|
75
|
-
Pry.config.should_load_plugins = false
|
76
|
-
Pry.config.history.should_load = false
|
77
|
-
Pry.config.history.should_save = false
|
78
|
-
Pry.config.auto_indent = false
|
79
|
-
Pry.config.hooks = Pry::Hooks.new
|
80
|
-
Pry.config.collision_warning = false
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def mock_exception(*mock_backtrace)
|
85
|
-
e = StandardError.new("mock exception")
|
86
|
-
(class << e; self; end).class_eval do
|
87
|
-
define_method(:backtrace) { mock_backtrace }
|
88
|
-
end
|
89
|
-
e
|
90
|
-
end
|
91
|
-
|
92
|
-
Pry.reset_defaults
|
93
|
-
|
94
|
-
# this is to test exception code (cat --ex)
|
95
|
-
def broken_method
|
96
|
-
this method is broken
|
97
|
-
end
|
98
|
-
|
99
|
-
# sample doc
|
100
|
-
def sample_method
|
101
|
-
:sample
|
102
|
-
end
|
103
|
-
|
104
|
-
# another sample doc
|
105
|
-
def another_sample_method
|
106
|
-
:another_sample
|
107
|
-
end
|
108
|
-
|
109
|
-
# Set I/O streams.
|
110
|
-
#
|
111
|
-
# Out defaults to an anonymous StringIO.
|
112
|
-
#
|
113
|
-
def redirect_pry_io(new_in, new_out = StringIO.new)
|
114
|
-
old_in = Pry.input
|
115
|
-
old_out = Pry.output
|
116
|
-
|
117
|
-
Pry.input = new_in
|
118
|
-
Pry.output = new_out
|
119
|
-
begin
|
120
|
-
yield
|
121
|
-
ensure
|
122
|
-
Pry.input = old_in
|
123
|
-
Pry.output = old_out
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def mock_pry(*args)
|
128
|
-
|
129
|
-
binding = args.first.is_a?(Binding) ? args.shift : binding()
|
130
|
-
|
131
|
-
input = InputTester.new(*args)
|
132
|
-
output = StringIO.new
|
133
|
-
|
134
|
-
redirect_pry_io(input, output) do
|
135
|
-
binding.pry
|
136
|
-
end
|
137
|
-
|
138
|
-
output.string
|
139
|
-
end
|
140
|
-
|
141
|
-
def mock_command(cmd, args=[], opts={})
|
142
|
-
output = StringIO.new
|
143
|
-
ret = cmd.new(opts.merge(:output => output)).call_safely(*args)
|
144
|
-
Struct.new(:output, :return).new(output.string, ret)
|
145
|
-
end
|
146
|
-
|
147
|
-
def redirect_global_pry_input(new_io)
|
148
|
-
old_io = Pry.input
|
149
|
-
Pry.input = new_io
|
150
|
-
begin
|
151
|
-
yield
|
152
|
-
ensure
|
153
|
-
Pry.input = old_io
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def redirect_global_pry_output(new_io)
|
158
|
-
old_io = Pry.output
|
159
|
-
Pry.output = new_io
|
160
|
-
begin
|
161
|
-
yield
|
162
|
-
ensure
|
163
|
-
Pry.output = old_io
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
class Module
|
168
|
-
public :remove_const
|
169
|
-
public :remove_method
|
170
|
-
end
|
171
|
-
|
172
|
-
|
173
|
-
class InputTester
|
174
|
-
def initialize(*actions)
|
175
|
-
@orig_actions = actions.dup
|
176
|
-
@actions = actions
|
177
|
-
end
|
178
|
-
|
179
|
-
def readline(*)
|
180
|
-
@actions.shift
|
181
|
-
end
|
182
|
-
|
183
|
-
def rewind
|
184
|
-
@actions = @orig_actions.dup
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
class Pry
|
189
|
-
|
190
|
-
# null output class - doesn't write anywwhere.
|
191
|
-
class NullOutput
|
192
|
-
def self.puts(*) end
|
193
|
-
def self.string(*) end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
# Open a temp file and yield it to the block, closing it after
|
198
|
-
# @return [String] The path of the temp file
|
199
|
-
def temp_file(ext='.rb')
|
200
|
-
file = Tempfile.new(['pry', ext])
|
201
|
-
yield file
|
202
|
-
ensure
|
203
|
-
file.close(true) if file
|
204
|
-
end
|
205
|
-
|
206
|
-
|
207
|
-
CommandTester = Pry::CommandSet.new do
|
208
|
-
command "command1", "command 1 test" do
|
209
|
-
output.puts "command1"
|
210
|
-
end
|
211
|
-
|
212
|
-
command "command2", "command 2 test" do |arg|
|
213
|
-
output.puts arg
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
# to help with tracking down bugs that cause an infinite loop in the test suite
|
218
|
-
if ENV["SET_TRACE_FUNC"]
|
219
|
-
require 'set_trace' if Pry::Helpers::BaseHelpers.rbx?
|
220
|
-
set_trace_func proc { |event, file, line, id, binding, classname|
|
221
|
-
STDERR.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
|
222
|
-
}
|
223
|
-
end
|
data/test/test_completion.rb
DELETED
@@ -1,62 +0,0 @@
|
|
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 !Pry::Helpers::BaseHelpers.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
|
-
lambda{ completer.call "a.to_s." }.should.not.raise Exception
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should take parenthesis and other characters into account for symbols' do
|
27
|
-
b = Pry.binding_for(Object.new)
|
28
|
-
completer = Pry::InputCompleter.build_completion_proc(b)
|
29
|
-
|
30
|
-
lambda { completer.call(":class)") }.should.not.raise(RegexpError)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should complete instance variables' do
|
34
|
-
object = Object.new
|
35
|
-
|
36
|
-
object.instance_variable_set(:'@name', 'Pry')
|
37
|
-
object.class.send(:class_variable_set, :'@@number', 10)
|
38
|
-
|
39
|
-
object.instance_variables.map { |v| v.to_sym } \
|
40
|
-
.include?(:'@name').should == true
|
41
|
-
|
42
|
-
object.class.class_variables.map { |v| v.to_sym } \
|
43
|
-
.include?(:'@@number').should == true
|
44
|
-
|
45
|
-
completer = Pry::InputCompleter.build_completion_proc(
|
46
|
-
Pry.binding_for(object)
|
47
|
-
)
|
48
|
-
|
49
|
-
# Complete instance variables.
|
50
|
-
completer.call('@na').include?('@name').should == true
|
51
|
-
completer.call('@name.down').include?('@name.downcase').should == true
|
52
|
-
|
53
|
-
# Complete class variables.
|
54
|
-
completer = Pry::InputCompleter.build_completion_proc(
|
55
|
-
Pry.binding_for(object.class)
|
56
|
-
)
|
57
|
-
|
58
|
-
completer.call('@@nu').include?('@@number').should == true
|
59
|
-
completer.call('@@number.cl').include?('@@number.class').should == true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Pry::DEFAULT_CONTROL_D_HANDLER do
|
4
|
-
describe 'control-d press' do
|
5
|
-
before do
|
6
|
-
@control_d = "Pry::DEFAULT_CONTROL_D_HANDLER.call('', _pry_)"
|
7
|
-
@binding_stack = "self.binding_stack = _pry_.binding_stack.dup"
|
8
|
-
end
|
9
|
-
|
10
|
-
describe 'in an expression' do
|
11
|
-
it 'should clear out passed string' do
|
12
|
-
str = "hello world"
|
13
|
-
Pry::DEFAULT_CONTROL_D_HANDLER.call(str, nil)
|
14
|
-
str.should == ""
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 'at top-level session' do
|
19
|
-
it 'should break out of a REPL loop' do
|
20
|
-
instance = nil
|
21
|
-
redirect_pry_io(InputTester.new(@control_d)) do
|
22
|
-
instance = Pry.new
|
23
|
-
instance.repl
|
24
|
-
end
|
25
|
-
|
26
|
-
instance.binding_stack.should.be.empty
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe 'in a nested session' do
|
31
|
-
it 'should pop last binding from the binding stack' do
|
32
|
-
base = OpenStruct.new
|
33
|
-
base.obj = OpenStruct.new
|
34
|
-
|
35
|
-
redirect_pry_io(InputTester.new("cd obj", "self.stack_size = _pry_.binding_stack.size",
|
36
|
-
@control_d, "self.stack_size = _pry_.binding_stack.size", "exit-all")) do
|
37
|
-
Pry.start(base)
|
38
|
-
end
|
39
|
-
|
40
|
-
base.obj.stack_size.should == 2
|
41
|
-
base.stack_size.should == 1
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,321 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'Pry::DefaultCommands::Cd' do
|
4
|
-
before do
|
5
|
-
@o, @obj = Object.new, Object.new
|
6
|
-
@obj.instance_variable_set(:@x, 66)
|
7
|
-
@obj.instance_variable_set(:@y, 79)
|
8
|
-
@o.instance_variable_set(:@obj, @obj)
|
9
|
-
|
10
|
-
# Shortcuts. They save a lot of typing.
|
11
|
-
@bs1 = "Pad.bs1 = _pry_.binding_stack.dup"
|
12
|
-
@bs2 = "Pad.bs2 = _pry_.binding_stack.dup"
|
13
|
-
@bs3 = "Pad.bs3 = _pry_.binding_stack.dup"
|
14
|
-
|
15
|
-
@os1 = "Pad.os1 = _pry_.command_state['cd'].old_stack.dup"
|
16
|
-
@os2 = "Pad.os2 = _pry_.command_state['cd'].old_stack.dup"
|
17
|
-
|
18
|
-
@self = "Pad.self = self"
|
19
|
-
@inner = "Pad.inner = self"
|
20
|
-
@outer = "Pad.outer = self"
|
21
|
-
end
|
22
|
-
|
23
|
-
after do
|
24
|
-
Pad.clear
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'state' do
|
28
|
-
it 'should not to be set up in fresh instance' do
|
29
|
-
redirect_pry_io(InputTester.new(@os1, "exit-all")) do
|
30
|
-
Pry.start(@o)
|
31
|
-
end
|
32
|
-
|
33
|
-
Pad.os1.should == nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe 'old stack toggling with `cd -`' do
|
38
|
-
describe 'in fresh pry instance' do
|
39
|
-
it 'should not toggle when there is no old stack' do
|
40
|
-
redirect_pry_io(InputTester.new("cd -", @bs1, "cd -",
|
41
|
-
@bs2, "exit-all")) do
|
42
|
-
Pry.start(@o)
|
43
|
-
end
|
44
|
-
|
45
|
-
Pad.bs1.map { |v| v.eval("self") }.should == [@o]
|
46
|
-
Pad.bs2.map { |v| v.eval("self") }.should == [@o]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe 'when an error was raised' do
|
51
|
-
it 'should ensure cd @ raises SyntaxError' do
|
52
|
-
mock_pry("cd @").should =~ /SyntaxError/
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should not toggle and should keep correct old stack' do
|
56
|
-
redirect_pry_io(InputTester.new("cd @", @os1, "cd -", @os2, "exit-all")) do
|
57
|
-
Pry.start(@o)
|
58
|
-
end
|
59
|
-
|
60
|
-
Pad.os1.should == []
|
61
|
-
Pad.os2.should == []
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should not toggle and should keep correct current binding stack' do
|
65
|
-
redirect_pry_io(InputTester.new("cd @", @bs1, "cd -", @bs2, "exit-all")) do
|
66
|
-
Pry.start(@o)
|
67
|
-
end
|
68
|
-
|
69
|
-
Pad.bs1.map { |v| v.eval("self") }.should == [@o]
|
70
|
-
Pad.bs2.map { |v| v.eval("self") }.should == [@o]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'when using simple cd syntax' do
|
75
|
-
it 'should toggle' do
|
76
|
-
redirect_pry_io(InputTester.new("cd :mon_dogg", "cd -", @bs1,
|
77
|
-
"cd -", @bs2, "exit-all")) do
|
78
|
-
Pry.start(@o)
|
79
|
-
end
|
80
|
-
|
81
|
-
Pad.bs1.map { |v| v.eval("self") }.should == [@o]
|
82
|
-
Pad.bs2.map { |v| v.eval("self") }.should == [@o, :mon_dogg]
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "when using complex cd syntax" do
|
87
|
-
it 'should toggle with a complex path (simple case)' do
|
88
|
-
redirect_pry_io(InputTester.new("cd 1/2/3", "cd -", @bs1,
|
89
|
-
"cd -", @bs2, "exit-all")) do
|
90
|
-
Pry.start(@o)
|
91
|
-
end
|
92
|
-
|
93
|
-
Pad.bs1.map { |v| v.eval('self') }.should == [@o]
|
94
|
-
Pad.bs2.map { |v| v.eval('self') }.should == [@o, 1, 2, 3]
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should toggle with a complex path (more complex case)' do
|
98
|
-
redirect_pry_io(InputTester.new("cd 1/2/3", "cd ../4", "cd -",
|
99
|
-
@bs1, "cd -", @bs2, "exit-all")) do
|
100
|
-
Pry.start(@o)
|
101
|
-
end
|
102
|
-
|
103
|
-
Pad.bs1.map { |v| v.eval('self') }.should == [@o, 1, 2, 3]
|
104
|
-
Pad.bs2.map { |v| v.eval('self') }.should == [@o, 1, 2, 4]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe 'series of cd calls' do
|
109
|
-
it 'should toggle with fuzzy `cd -` calls' do
|
110
|
-
redirect_pry_io(InputTester.new("cd :mon_dogg", "cd -", "cd 42", "cd -",
|
111
|
-
@bs1, "cd -", @bs2, "exit-all")) do
|
112
|
-
Pry.start(@o)
|
113
|
-
end
|
114
|
-
|
115
|
-
Pad.bs1.map { |v| v.eval('self') }.should == [@o]
|
116
|
-
Pad.bs2.map { |v| v.eval('self') }.should == [@o, 42]
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe 'when using cd ..' do
|
121
|
-
it 'should toggle with a simple path' do
|
122
|
-
redirect_pry_io(InputTester.new("cd :john_dogg", "cd ..", @bs1,
|
123
|
-
"cd -", @bs2, "exit-all")) do
|
124
|
-
Pry.start(@o)
|
125
|
-
end
|
126
|
-
|
127
|
-
Pad.bs1.map { |v| v.eval('self') }.should == [@o]
|
128
|
-
Pad.bs2.map { |v| v.eval('self') }.should == [@o, :john_dogg]
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'should toggle with a complex path' do
|
132
|
-
redirect_pry_io(InputTester.new("cd 1/2/3/../4", "cd -", @bs1,
|
133
|
-
"cd -", @bs2, "exit-all")) do
|
134
|
-
Pry.start(@o)
|
135
|
-
end
|
136
|
-
|
137
|
-
Pad.bs1.map { |v| v.eval('self') }.should == [@o]
|
138
|
-
Pad.bs2.map { |v| v.eval('self') }.should == [@o, 1, 2, 4]
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe 'when using cd ::' do
|
143
|
-
it 'should toggle' do
|
144
|
-
redirect_pry_io(InputTester.new("cd ::", "cd -", @bs1,
|
145
|
-
"cd -", @bs2, "exit-all")) do
|
146
|
-
Pry.start(@o)
|
147
|
-
end
|
148
|
-
|
149
|
-
Pad.bs1.map { |v| v.eval('self') }.should == [@o]
|
150
|
-
Pad.bs2.map { |v| v.eval('self') }.should == [@o, TOPLEVEL_BINDING.eval("self")]
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe 'when using cd /' do
|
155
|
-
it 'should toggle' do
|
156
|
-
redirect_pry_io(InputTester.new("cd /", "cd -", @bs1, "cd :john_dogg",
|
157
|
-
"cd /", "cd -", @bs2, "exit-all")) do
|
158
|
-
Pry.start(@o)
|
159
|
-
end
|
160
|
-
|
161
|
-
Pad.bs1.map { |v| v.eval('self') }.should == [@o]
|
162
|
-
Pad.bs2.map { |v| v.eval('self') }.should == [@o, :john_dogg]
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe 'when using ^D (Control-D) key press' do
|
167
|
-
before do
|
168
|
-
@control_d = "Pry::DEFAULT_CONTROL_D_HANDLER.call('', _pry_)"
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'should keep correct old binding' do
|
172
|
-
redirect_pry_io(InputTester.new("cd :john_dogg", "cd :mon_dogg",
|
173
|
-
"cd :kyr_dogg", @control_d, @bs1,
|
174
|
-
"cd -", @bs2, "cd -", @bs3, "exit-all")) do
|
175
|
-
Pry.start(@o)
|
176
|
-
end
|
177
|
-
|
178
|
-
Pad.bs1.map { |v| v.eval('self') }.should == [@o, :john_dogg, :mon_dogg]
|
179
|
-
Pad.bs2.map { |v| v.eval('self') }.should == [@o, :john_dogg, :mon_dogg, :kyr_dogg]
|
180
|
-
Pad.bs3.map { |v| v.eval('self') }.should == [@o, :john_dogg, :mon_dogg]
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'should cd into simple input' do
|
186
|
-
redirect_pry_io(InputTester.new("cd :mon_ouie", @inner, "exit-all")) do
|
187
|
-
Pry.start(@o)
|
188
|
-
end
|
189
|
-
|
190
|
-
Pad.inner.should == :mon_ouie
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'should break out of session with cd ..' do
|
194
|
-
redirect_pry_io(InputTester.new("cd :inner", @inner, "cd ..", @outer, "exit-all")) do
|
195
|
-
Pry.start(:outer)
|
196
|
-
end
|
197
|
-
|
198
|
-
Pad.inner.should == :inner
|
199
|
-
Pad.outer.should == :outer
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should not leave the REPL session when given 'cd ..'" do
|
203
|
-
redirect_pry_io(InputTester.new("cd ..", @self, "exit-all")) do
|
204
|
-
Pry.start(@o)
|
205
|
-
end
|
206
|
-
|
207
|
-
Pad.self.should == @o
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'should break out to outer-most session with cd /' do
|
211
|
-
redirect_pry_io(InputTester.new("cd :inner", @inner, "cd 5", "Pad.five = self",
|
212
|
-
"cd /", @outer, "exit-all")) do
|
213
|
-
Pry.start(:outer)
|
214
|
-
end
|
215
|
-
|
216
|
-
Pad.inner.should == :inner
|
217
|
-
Pad.five.should == 5
|
218
|
-
Pad.outer.should == :outer
|
219
|
-
end
|
220
|
-
|
221
|
-
it 'should break out to outer-most session with just cd (no args)' do
|
222
|
-
redirect_pry_io(InputTester.new("cd :inner", @inner, "cd 5", "Pad.five = self",
|
223
|
-
"cd", @outer, "exit-all")) do
|
224
|
-
Pry.start(:outer)
|
225
|
-
end
|
226
|
-
|
227
|
-
Pad.inner.should == :inner
|
228
|
-
Pad.five.should == 5
|
229
|
-
Pad.outer.should == :outer
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'should cd into an object and its ivar using cd obj/@ivar syntax' do
|
233
|
-
redirect_pry_io(InputTester.new("cd @obj/@x", @bs1, "exit-all")) do
|
234
|
-
Pry.start(@o)
|
235
|
-
end
|
236
|
-
|
237
|
-
Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj, 66]
|
238
|
-
end
|
239
|
-
|
240
|
-
it 'should cd into an object and its ivar using cd obj/@ivar/ syntax (note following /)' do
|
241
|
-
redirect_pry_io(InputTester.new("cd @obj/@x/", @bs1, "exit-all")) do
|
242
|
-
Pry.start(@o)
|
243
|
-
end
|
244
|
-
|
245
|
-
Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj, 66]
|
246
|
-
end
|
247
|
-
|
248
|
-
it 'should cd into previous object and its local using cd ../local syntax' do
|
249
|
-
redirect_pry_io(InputTester.new("cd @obj", "local = :local", "cd @x",
|
250
|
-
"cd ../local", @bs1, "exit-all")) do
|
251
|
-
Pry.start(@o)
|
252
|
-
end
|
253
|
-
|
254
|
-
Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj, :local]
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'should cd into an object and its ivar and back again using cd obj/@ivar/.. syntax' do
|
258
|
-
redirect_pry_io(InputTester.new("cd @obj/@x/..", @bs1, "exit-all")) do
|
259
|
-
Pry.start(@o)
|
260
|
-
end
|
261
|
-
|
262
|
-
Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj]
|
263
|
-
end
|
264
|
-
|
265
|
-
it 'should cd into an object and its ivar and back and then into another ivar using cd obj/@ivar/../@y syntax' do
|
266
|
-
redirect_pry_io(InputTester.new("cd @obj/@x/../@y", @bs1, "exit-all")) do
|
267
|
-
Pry.start(@o)
|
268
|
-
end
|
269
|
-
|
270
|
-
Pad.bs1.map { |v| v.eval("self") }.should == [@o, @obj, 79]
|
271
|
-
end
|
272
|
-
|
273
|
-
it 'should cd back to top-level and then into another ivar using cd /@ivar/ syntax' do
|
274
|
-
redirect_pry_io(InputTester.new("@z = 20", "cd @obj/@x/", "cd /@z",
|
275
|
-
@bs1, "exit-all")) do
|
276
|
-
Pry.start(@o)
|
277
|
-
end
|
278
|
-
|
279
|
-
Pad.bs1.map { |v| v.eval("self") }.should == [@o, 20]
|
280
|
-
end
|
281
|
-
|
282
|
-
it 'should start a session on TOPLEVEL_BINDING with cd ::' do
|
283
|
-
redirect_pry_io(InputTester.new("cd ::", @self, "exit-all")) do
|
284
|
-
Pry.start(@o)
|
285
|
-
end
|
286
|
-
|
287
|
-
Pad.self.should == TOPLEVEL_BINDING.eval("self")
|
288
|
-
end
|
289
|
-
|
290
|
-
it 'should cd into complex input (with spaces)' do
|
291
|
-
def @o.hello(x, y, z)
|
292
|
-
:mon_ouie
|
293
|
-
end
|
294
|
-
|
295
|
-
redirect_pry_io(InputTester.new("cd hello 1, 2, 3", @self, "exit-all")) do
|
296
|
-
Pry.start(@o)
|
297
|
-
end
|
298
|
-
|
299
|
-
Pad.self.should == :mon_ouie
|
300
|
-
end
|
301
|
-
|
302
|
-
it 'should not cd into complex input when it encounters an exception' do
|
303
|
-
redirect_pry_io(InputTester.new("cd 1/2/swoop_a_doop/3",
|
304
|
-
@bs1, "exit-all")) do
|
305
|
-
Pry.start(@o)
|
306
|
-
end
|
307
|
-
|
308
|
-
Pad.bs1.map { |v| v.eval("self") }.should == [@o]
|
309
|
-
end
|
310
|
-
|
311
|
-
# Regression test for ticket #516.
|
312
|
-
#it 'should be able to cd into the Object BasicObject.' do
|
313
|
-
# mock_pry('cd BasicObject.new').should.not =~ /\Aundefined method `__binding__'/
|
314
|
-
#end
|
315
|
-
|
316
|
-
# Regression test for ticket #516
|
317
|
-
# Possibly move higher up.
|
318
|
-
it 'should not fail with undefined BasicObject#is_a?' do
|
319
|
-
mock_pry('cd BasicObject.new').should.not =~ /undefined method `is_a\?'/
|
320
|
-
end
|
321
|
-
end
|