pry 0.9.10pre1-i386-mingw32 → 0.9.11-i386-mingw32
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
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "whereami" do
|
4
|
+
it 'should work with methods that have been undefined' do
|
5
|
+
class Cor
|
6
|
+
def blimey!
|
7
|
+
Cor.send :undef_method, :blimey!
|
8
|
+
Pad.binding = binding
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Cor.new.blimey!
|
13
|
+
|
14
|
+
# using [.] so the regex doesn't match itself
|
15
|
+
pry_eval(Pad.binding, 'whereami').should =~ /self[.]blimey!/
|
16
|
+
|
17
|
+
Object.remove_const(:Cor)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should work in objects with no method methods' do
|
21
|
+
class Cor
|
22
|
+
def blimey!
|
23
|
+
pry_eval(binding, 'whereami').should =~ /Cor[#]blimey!/
|
24
|
+
end
|
25
|
+
|
26
|
+
def method; "moo"; end
|
27
|
+
end
|
28
|
+
Cor.new.blimey!
|
29
|
+
Object.remove_const(:Cor)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should properly set _file_, _line_ and _dir_' do
|
33
|
+
class Cor
|
34
|
+
def blimey!
|
35
|
+
pry_eval(binding, 'whereami', '_file_').
|
36
|
+
should == File.expand_path(__FILE__)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Cor.new.blimey!
|
41
|
+
Object.remove_const(:Cor)
|
42
|
+
end
|
43
|
+
|
44
|
+
if defined?(BasicObject)
|
45
|
+
it 'should work in BasicObjects' do
|
46
|
+
cor = Class.new(BasicObject) do
|
47
|
+
def blimey!
|
48
|
+
::Kernel.binding # omnom
|
49
|
+
end
|
50
|
+
end.new.blimey!
|
51
|
+
|
52
|
+
pry_eval(cor, 'whereami').should =~ /::Kernel.binding [#] omnom/
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should show description and correct code when __LINE__ and __FILE__ are outside @method.source_location' do
|
57
|
+
class Cor
|
58
|
+
def blimey!
|
59
|
+
eval <<-END, binding, "spec/fixtures/example.erb", 1
|
60
|
+
pry_eval(binding, 'whereami')
|
61
|
+
END
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
Cor.instance_method(:blimey!).source.should =~ /pry_eval/
|
66
|
+
|
67
|
+
Cor.new.blimey!.should =~ /Cor#blimey!.*Look at me/m
|
68
|
+
Object.remove_const(:Cor)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should show description and correct code when @method.source_location would raise an error' do
|
72
|
+
class Cor
|
73
|
+
eval <<-END, binding, "spec/fixtures/example.erb", 1
|
74
|
+
def blimey!
|
75
|
+
pry_eval(binding, 'whereami')
|
76
|
+
end
|
77
|
+
END
|
78
|
+
end
|
79
|
+
|
80
|
+
lambda{
|
81
|
+
Cor.instance_method(:blimey!).source
|
82
|
+
}.should.raise(MethodSource::SourceNotFoundError)
|
83
|
+
|
84
|
+
Cor.new.blimey!.should =~ /Cor#blimey!.*Look at me/m
|
85
|
+
Object.remove_const(:Cor)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should display a description and and error if reading the file goes wrong' do
|
89
|
+
class Cor
|
90
|
+
def blimey!
|
91
|
+
eval <<-END, binding, "not.found.file.erb", 7
|
92
|
+
Pad.tester = pry_tester(binding)
|
93
|
+
Pad.tester.eval('whereami')
|
94
|
+
END
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
proc { Cor.new.blimey! }.should.raise(MethodSource::SourceNotFoundError)
|
99
|
+
Pad.tester.last_output.should =~
|
100
|
+
/From: not.found.file.erb @ line 7 Cor#blimey!:/
|
101
|
+
Object.remove_const(:Cor)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should show code window (not just method source) if parameter passed to whereami' do
|
105
|
+
class Cor
|
106
|
+
def blimey!
|
107
|
+
pry_eval(binding, 'whereami 3').should =~ /class Cor/
|
108
|
+
end
|
109
|
+
end
|
110
|
+
Cor.new.blimey!
|
111
|
+
Object.remove_const(:Cor)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should not show line numbers or marker when -n switch is used' do
|
115
|
+
class Cor
|
116
|
+
def blimey!
|
117
|
+
out = pry_eval(binding, 'whereami -n')
|
118
|
+
out.should =~ /^\s*def/
|
119
|
+
out.should.not =~ /\=\>/
|
120
|
+
end
|
121
|
+
end
|
122
|
+
Cor.new.blimey!
|
123
|
+
Object.remove_const(:Cor)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should use Pry.config.default_window_size for window size when outside a method context' do
|
127
|
+
old_size, Pry.config.default_window_size = Pry.config.default_window_size, 1
|
128
|
+
:litella
|
129
|
+
:pig
|
130
|
+
out = pry_eval(binding, 'whereami')
|
131
|
+
:punk
|
132
|
+
:sanders
|
133
|
+
|
134
|
+
out.should.not =~ /:litella/
|
135
|
+
out.should =~ /:pig/
|
136
|
+
out.should =~ /:punk/
|
137
|
+
out.should.not =~ /:sanders/
|
138
|
+
|
139
|
+
Pry.config.default_window_size = old_size
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should work at the top level" do
|
143
|
+
pry_eval(Pry.toplevel_binding, 'whereami').should =~
|
144
|
+
/At the top level/
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should work inside a class" do
|
148
|
+
pry_eval(Pry, 'whereami').should =~ /Inside Pry/
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should work inside an object" do
|
152
|
+
pry_eval(Object.new, 'whereami').should =~ /Inside #<Object/
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,233 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
def new_completer(bind, pry=nil)
|
4
|
+
Pry::InputCompleter.build_completion_proc(Pry.binding_for(bind), pry)
|
5
|
+
end
|
6
|
+
|
7
|
+
def completer_test(bind, pry=nil, assert_flag=true)
|
8
|
+
completer = new_completer(bind, pry)
|
9
|
+
test = proc {|symbol| completer.call(symbol[0..-2]).include?(symbol).should == assert_flag}
|
10
|
+
return proc {|*symbols| symbols.each(&test) }
|
11
|
+
end
|
12
|
+
|
13
|
+
if defined?(Bond) && Readline::VERSION !~ /editline/i
|
14
|
+
describe 'bond-based completion' do
|
15
|
+
it 'should pull in Bond by default' do
|
16
|
+
Pry.config.completer.should == Pry::BondCompleter
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Pry::InputCompleter do
|
22
|
+
|
23
|
+
before do
|
24
|
+
# The AMQP gem has some classes like this:
|
25
|
+
# pry(main)> AMQP::Protocol::Test::ContentOk.name
|
26
|
+
# => :content_ok
|
27
|
+
module SymbolyName
|
28
|
+
def self.name; :symboly_name; end
|
29
|
+
end
|
30
|
+
|
31
|
+
$default_completer = Pry.config.completer
|
32
|
+
Pry.config.completer = Pry::InputCompleter
|
33
|
+
end
|
34
|
+
|
35
|
+
after do
|
36
|
+
Pry.config.completer = $default_completer
|
37
|
+
Object.remove_const :SymbolyName
|
38
|
+
end
|
39
|
+
|
40
|
+
# another jruby hack :((
|
41
|
+
if !Pry::Helpers::BaseHelpers.jruby?
|
42
|
+
it "should not crash if there's a Module that has a symbolic name." do
|
43
|
+
completer = Pry::InputCompleter.build_completion_proc(Pry.binding_for(Object.new))
|
44
|
+
lambda{ completer.call "a.to_s." }.should.not.raise Exception
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should take parenthesis and other characters into account for symbols' do
|
49
|
+
b = Pry.binding_for(Object.new)
|
50
|
+
completer = Pry::InputCompleter.build_completion_proc(b)
|
51
|
+
|
52
|
+
lambda { completer.call(":class)") }.should.not.raise(RegexpError)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should complete instance variables' do
|
56
|
+
object = Class.new.new
|
57
|
+
|
58
|
+
# set variables in appropriate scope
|
59
|
+
object.instance_variable_set(:'@name', 'Pry')
|
60
|
+
object.class.send(:class_variable_set, :'@@number', 10)
|
61
|
+
|
62
|
+
# check to see if variables are in scope
|
63
|
+
object.instance_variables.
|
64
|
+
map { |v| v.to_sym }.
|
65
|
+
include?(:'@name').should == true
|
66
|
+
|
67
|
+
object.class.class_variables.
|
68
|
+
map { |v| v.to_sym }.
|
69
|
+
include?(:'@@number').should == true
|
70
|
+
|
71
|
+
# Complete instance variables.
|
72
|
+
b = Pry.binding_for(object)
|
73
|
+
completer_test(b).call('@name', '@name.downcase')
|
74
|
+
|
75
|
+
# Complete class variables.
|
76
|
+
b = Pry.binding_for(object.class)
|
77
|
+
completer_test(b).call('@@number', '@@number.class')
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
it 'should complete for stdlib symbols' do
|
83
|
+
|
84
|
+
o = Object.new
|
85
|
+
# Regexp
|
86
|
+
completer_test(o).call('/foo/.extend')
|
87
|
+
|
88
|
+
# Array
|
89
|
+
completer_test(o).call('[1].push')
|
90
|
+
|
91
|
+
# Hash
|
92
|
+
completer_test(o).call('{"a" => "b"}.keys')
|
93
|
+
|
94
|
+
# Proc
|
95
|
+
completer_test(o).call('{2}.call')
|
96
|
+
|
97
|
+
# Symbol
|
98
|
+
completer_test(o).call(':symbol.to_s')
|
99
|
+
|
100
|
+
# Absolute Constant
|
101
|
+
completer_test(o).call('::IndexError')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should complete for target symbols' do
|
105
|
+
o = Object.new
|
106
|
+
|
107
|
+
# Constant
|
108
|
+
module Mod
|
109
|
+
Con = 'Constant'
|
110
|
+
module Mod2
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
completer_test(Mod).call('Con')
|
115
|
+
|
116
|
+
# Constants or Class Methods
|
117
|
+
completer_test(o).call('Mod::Con')
|
118
|
+
|
119
|
+
# Symbol
|
120
|
+
foo = :symbol
|
121
|
+
completer_test(o).call(':symbol')
|
122
|
+
|
123
|
+
# Variables
|
124
|
+
class << o
|
125
|
+
attr_accessor :foo
|
126
|
+
end
|
127
|
+
o.foo = 'bar'
|
128
|
+
completer_test(binding).call('o.foo')
|
129
|
+
|
130
|
+
# trailing slash
|
131
|
+
new_completer(Mod).call('Mod2/').include?('Mod2/').should == true
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should complete for arbitrary scopes' do
|
135
|
+
module Bar
|
136
|
+
@barvar = :bar
|
137
|
+
end
|
138
|
+
|
139
|
+
module Baz
|
140
|
+
@bar = Bar
|
141
|
+
@bazvar = :baz
|
142
|
+
Con = :constant
|
143
|
+
end
|
144
|
+
|
145
|
+
pry = Pry.new()
|
146
|
+
stack = pry.binding_stack
|
147
|
+
stack.push(Pry.binding_for(Baz))
|
148
|
+
stack.push(Pry.binding_for(Bar))
|
149
|
+
|
150
|
+
b = Pry.binding_for(Bar)
|
151
|
+
completer_test(b, pry).call("../@bazvar")
|
152
|
+
completer_test(b, pry).call('/Con')
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should complete for stdlib symbols' do
|
156
|
+
|
157
|
+
o = Object.new
|
158
|
+
# Regexp
|
159
|
+
completer_test(o).call('/foo/.extend')
|
160
|
+
|
161
|
+
# Array
|
162
|
+
completer_test(o).call('[1].push')
|
163
|
+
|
164
|
+
# Hash
|
165
|
+
completer_test(o).call('{"a" => "b"}.keys')
|
166
|
+
|
167
|
+
# Proc
|
168
|
+
completer_test(o).call('{2}.call')
|
169
|
+
|
170
|
+
# Symbol
|
171
|
+
completer_test(o).call(':symbol.to_s')
|
172
|
+
|
173
|
+
# Absolute Constant
|
174
|
+
completer_test(o).call('::IndexError')
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'should complete for target symbols' do
|
178
|
+
o = Object.new
|
179
|
+
|
180
|
+
# Constant
|
181
|
+
module Mod
|
182
|
+
Con = 'Constant'
|
183
|
+
module Mod2
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
completer_test(Mod).call('Con')
|
188
|
+
|
189
|
+
# Constants or Class Methods
|
190
|
+
completer_test(o).call('Mod::Con')
|
191
|
+
|
192
|
+
# Symbol
|
193
|
+
foo = :symbol
|
194
|
+
completer_test(o).call(':symbol')
|
195
|
+
|
196
|
+
# Variables
|
197
|
+
class << o
|
198
|
+
attr_accessor :foo
|
199
|
+
end
|
200
|
+
o.foo = 'bar'
|
201
|
+
completer_test(binding).call('o.foo')
|
202
|
+
|
203
|
+
# trailing slash
|
204
|
+
new_completer(Mod).call('Mod2/').include?('Mod2/').should == true
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should complete for arbitrary scopes' do
|
209
|
+
module Bar
|
210
|
+
@barvar = :bar
|
211
|
+
end
|
212
|
+
|
213
|
+
module Baz
|
214
|
+
@bar = Bar
|
215
|
+
@bazvar = :baz
|
216
|
+
Con = :constant
|
217
|
+
end
|
218
|
+
|
219
|
+
pry = Pry.new()
|
220
|
+
stack = pry.binding_stack
|
221
|
+
stack.push(Pry.binding_for(Baz))
|
222
|
+
stack.push(Pry.binding_for(Bar))
|
223
|
+
|
224
|
+
b = Pry.binding_for(Bar)
|
225
|
+
completer_test(b, pry).call("../@bazvar")
|
226
|
+
completer_test(b, pry).call('/Con')
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should not return nil in its output' do
|
230
|
+
pry = Pry.new
|
231
|
+
new_completer(binding, pry).call("pry.").should.not.include nil
|
232
|
+
end
|
233
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Pry::DEFAULT_CONTROL_D_HANDLER do
|
4
|
+
|
5
|
+
describe "control-d press" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
# Simulates a ^D press.
|
9
|
+
@control_d = "Pry::DEFAULT_CONTROL_D_HANDLER.call('', _pry_)"
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "in an expression" do
|
13
|
+
it "should clear out passed string" do
|
14
|
+
str = 'hello world'
|
15
|
+
Pry::DEFAULT_CONTROL_D_HANDLER.call(str, nil)
|
16
|
+
str.should == ''
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe "at top-level session" do
|
22
|
+
it "breaks out of a REPL" do
|
23
|
+
pry_tester(0).simulate_repl do |t|
|
24
|
+
t.eval @control_d
|
25
|
+
end.should == nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "in a nested session" do
|
30
|
+
it "pops last binding from the binding stack" do
|
31
|
+
pry_tester(0).simulate_repl { |t|
|
32
|
+
t.eval 'cd :foo'
|
33
|
+
t.eval('_pry_.binding_stack.size').should == 2
|
34
|
+
t.eval(@control_d)
|
35
|
+
t.eval('_pry_.binding_stack.size').should == 1
|
36
|
+
t.eval 'exit-all'
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
it "breaks out of the parent session" do
|
41
|
+
pry_tester(:outer).simulate_repl do |o|
|
42
|
+
o.context = :inner
|
43
|
+
o.simulate_repl { |i|
|
44
|
+
i.eval('_pry_.current_context.eval("self")').should == :inner
|
45
|
+
i.eval('_pry_.binding_stack.size').should == 2
|
46
|
+
i.eval @control_d
|
47
|
+
i.eval('_pry_.binding_stack.size').should == 1
|
48
|
+
i.eval('_pry_.current_context.eval("self")').should == :outer
|
49
|
+
i.eval 'throw :breakout'
|
50
|
+
}
|
51
|
+
o.eval 'exit-all'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/spec/editor_spec.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
describe Pry::Editor do
|
5
|
+
class << Pry::Editor
|
6
|
+
public :build_editor_invocation_string
|
7
|
+
end
|
8
|
+
|
9
|
+
before do
|
10
|
+
# OS-specific tempdir name. For GNU/Linux it's "tmp", for Windows it's
|
11
|
+
# something "Temp".
|
12
|
+
@tf_dir =
|
13
|
+
if Pry::Helpers::BaseHelpers.mri_19?
|
14
|
+
Pathname.new(Dir::Tmpname.tmpdir)
|
15
|
+
else
|
16
|
+
Pathname.new(Dir.tmpdir)
|
17
|
+
end
|
18
|
+
|
19
|
+
@tf_path = File.join(@tf_dir.to_s, 'hello world.rb')
|
20
|
+
end
|
21
|
+
|
22
|
+
unless Pry::Helpers::BaseHelpers.windows?
|
23
|
+
describe "build_editor_invocation_string" do
|
24
|
+
before do
|
25
|
+
class << Pry::Editor
|
26
|
+
public :build_editor_invocation_string
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should shell-escape files' do
|
31
|
+
invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
|
32
|
+
invocation_str.should =~ /#@tf_dir.+hello\\ world\.rb/
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "build_editor_invocation_string on windows" do
|
38
|
+
before do
|
39
|
+
class << Pry::Editor
|
40
|
+
def windows?; true; end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
after do
|
45
|
+
class << Pry::Editor
|
46
|
+
undef windows?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should replace / by \\" do
|
51
|
+
invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
|
52
|
+
invocation_str.should =~ %r(\\#{@tf_dir.basename}\\)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not shell-escape files" do
|
56
|
+
invocation_str = Pry::Editor.build_editor_invocation_string(@tf_path, 5, true)
|
57
|
+
invocation_str.should =~ /hello world\.rb/
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'invoke_editor with a proc' do
|
62
|
+
before do
|
63
|
+
@old_editor = Pry.config.editor
|
64
|
+
Pry.config.editor = proc{ |file, line, blocking|
|
65
|
+
@file = file
|
66
|
+
nil
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
after do
|
71
|
+
Pry.config.editor = @old_editor
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should not shell-escape files' do
|
75
|
+
Pry::Editor.invoke_editor(@tf_path, 10, true)
|
76
|
+
@file.should == @tf_path
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|