pry 0.9.10 → 0.9.11
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -1
- data/CHANGELOG +60 -1
- 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 +27 -16
- 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 +6 -121
- 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 +236 -112
- 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
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe "Pry::DefaultCommands::Gems" do
|
4
|
-
describe "gem-list" do
|
5
|
-
|
6
|
-
# fixing bug for 1.8 compat
|
7
|
-
it 'should not raise when invoked' do
|
8
|
-
str_output = StringIO.new
|
9
|
-
Pry.start self, :input => InputTester.new("gem-list", "exit-all"), :output => str_output
|
10
|
-
str_output.string.should.not =~ /Error/
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should not raise when invoked with an argument' do
|
14
|
-
mock_pry('gem-list pry').should.not =~ /Error/
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
@@ -1,428 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe "Pry::DefaultCommands::Input" do
|
4
|
-
before do
|
5
|
-
@str_output = StringIO.new
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "amend-line" do
|
9
|
-
it 'should correctly amend the last line of input when no line number specified ' do
|
10
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "amend-line puts :blah", "show-input", "exit-all"), @str_output) do
|
11
|
-
pry
|
12
|
-
end
|
13
|
-
|
14
|
-
@str_output.string.should =~ /\A\d+: def hello\n\d+: puts :blah/
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should correctly amend the specified line of input when line number given ' do
|
18
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 1 def goodbye", "show-input", "exit-all"), @str_output) do
|
19
|
-
pry
|
20
|
-
end
|
21
|
-
|
22
|
-
@str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should correctly amend the specified line of input when line number given, 0 should behave as 1 ' do
|
26
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 0 def goodbye", "show-input", "exit-all"), @str_output) do
|
27
|
-
pry
|
28
|
-
end
|
29
|
-
|
30
|
-
@str_output.string.should =~ /\A\d+: def goodbye\n\d+: puts :bing\n\d+: puts :bang/
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should correctly amend the specified line of input when line number given (negative number)' do
|
34
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line -1 puts :bink", "show-input", "exit-all"), @str_output) do
|
35
|
-
pry
|
36
|
-
end
|
37
|
-
|
38
|
-
@str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing\n\d+: puts :bink/
|
39
|
-
|
40
|
-
@str_output = StringIO.new
|
41
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line -2 puts :bink", "show-input", "exit-all"), @str_output) do
|
42
|
-
pry
|
43
|
-
end
|
44
|
-
|
45
|
-
@str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bink\n\d+: puts :bang/
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should correctly amend the specified range of lines of input when range of negative numbers given (negative number)' do
|
49
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boat", "amend-line -3..-2 puts :bink", "show-input", "exit-all"), @str_output) do
|
50
|
-
pry
|
51
|
-
end
|
52
|
-
|
53
|
-
@str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bink\n\d+: puts :boat/
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should correctly amend the specified line with string interpolated text' do
|
57
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", 'amend-line puts "#{goodbye}"', "show-input", "exit-all"), @str_output) do
|
58
|
-
pry
|
59
|
-
end
|
60
|
-
|
61
|
-
@str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing\n\d+: puts \"\#\{goodbye\}\"/
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should display error if nothing to amend' do
|
65
|
-
redirect_pry_io(InputTester.new("amend-line", "exit-all"), @str_output) do
|
66
|
-
pry
|
67
|
-
end
|
68
|
-
|
69
|
-
@str_output.string.should =~ /No input to amend/
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
it 'should correctly amend the specified range of lines' do
|
74
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :heart", "amend-line 2..3 puts :bong", "show-input", "exit-all"), @str_output) do
|
75
|
-
pry
|
76
|
-
end
|
77
|
-
|
78
|
-
@str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bong\n\d+: puts :heart/
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'should correctly delete a specific line using the ! for content' do
|
82
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line 3 !", "show-input", "exit-all"), @str_output) do
|
83
|
-
pry
|
84
|
-
end
|
85
|
-
|
86
|
-
@str_output.string.should =~ /\d+: def hello\n\d+: puts :bing\n\d+: puts :boast\n\d+: puts :heart/
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should correctly delete a range of lines using the ! for content' do
|
90
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line 2..4 !", "show-input", "exit-all"), @str_output) do
|
91
|
-
pry
|
92
|
-
end
|
93
|
-
|
94
|
-
@str_output.string.should =~ /\d+: def hello\n\d+: puts :heart\n\Z/
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should correctly delete the previous line using the ! for content' do
|
98
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line !", "show-input", "exit-all"), @str_output) do
|
99
|
-
pry
|
100
|
-
end
|
101
|
-
|
102
|
-
@str_output.string.should =~ /\d+: def hello\n\d+: puts :bing\n\d+: puts :bang\n\d+: puts :boast\n\Z/
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'should correctly amend the specified range of lines, using negative numbers in range' do
|
106
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "puts :boast", "puts :heart", "amend-line 2..-2 puts :bong", "show-input", "exit-all"), @str_output) do
|
107
|
-
pry
|
108
|
-
end
|
109
|
-
@str_output.string.should =~ /\d+: def hello\n\d+: puts :bong\n\d+: puts :heart/
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'should correctly insert a new line of input before a specified line using the > syntax' do
|
113
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 2 >puts :inserted", "show-input", "exit-all"), @str_output) do
|
114
|
-
pry
|
115
|
-
end
|
116
|
-
|
117
|
-
@str_output.string.should =~ /\d+: def hello\n\d+: puts :inserted\n\d+: puts :bing\n\d+: puts :bang/
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'should correctly insert a new line of input before a specified line using the > syntax (should ignore second value of range)' do
|
121
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "puts :bang", "amend-line 2..21 >puts :inserted", "show-input", "exit-all"), @str_output) do
|
122
|
-
pry
|
123
|
-
end
|
124
|
-
|
125
|
-
@str_output.string.should =~ /\d+: def hello\n\d+: puts :inserted\n\d+: puts :bing\n\d+: puts :bang/
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "show-input" do
|
130
|
-
it 'should correctly show the current lines in the input buffer' do
|
131
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "show-input", "exit-all"), @str_output) do
|
132
|
-
pry
|
133
|
-
end
|
134
|
-
|
135
|
-
@str_output.string.should =~ /\A\d+: def hello\n\d+: puts :bing/
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe "!" do
|
140
|
-
it 'should correctly clear the input buffer ' do
|
141
|
-
redirect_pry_io(InputTester.new("def hello", "puts :bing", "!", "show-input", "exit-all"), @str_output) do
|
142
|
-
pry
|
143
|
-
end
|
144
|
-
|
145
|
-
stripped_output = @str_output.string.strip!
|
146
|
-
stripped_output.each_line.count.should == 1
|
147
|
-
stripped_output.should =~ /Input buffer cleared!/
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "play" do
|
152
|
-
it 'should play a string variable (with no args)' do
|
153
|
-
b = binding
|
154
|
-
b.eval('x = "\"hello\""')
|
155
|
-
redirect_pry_io(InputTester.new("play x", "exit-all"), @str_output) do
|
156
|
-
Pry.start b, :hooks => Pry::Hooks.new
|
157
|
-
end
|
158
|
-
|
159
|
-
@str_output.string.should =~ /hello/
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'should play a string variable (with no args) using --lines to select what to play' do
|
163
|
-
b = binding
|
164
|
-
b.eval('x = "\"hello\"\n\"goodbye\"\n\"love\""')
|
165
|
-
redirect_pry_io(InputTester.new("play x --lines 1", "exit-all"), @str_output) do
|
166
|
-
Pry.start b, :hooks => Pry::Hooks.new
|
167
|
-
end
|
168
|
-
|
169
|
-
@str_output.string.should =~ /hello/
|
170
|
-
@str_output.string.should.not =~ /love/
|
171
|
-
@str_output.string.should.not =~ /goodbye/
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'should play documentation with the -d switch' do
|
175
|
-
o = Object.new
|
176
|
-
|
177
|
-
# @v = 10
|
178
|
-
# @y = 20
|
179
|
-
def o.test_method
|
180
|
-
:test_method_content
|
181
|
-
end
|
182
|
-
|
183
|
-
redirect_pry_io(InputTester.new('play -d test_method', "exit-all")) do
|
184
|
-
o.pry
|
185
|
-
end
|
186
|
-
|
187
|
-
o.instance_variable_get(:@v).should == 10
|
188
|
-
o.instance_variable_get(:@y).should == 20
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'should play documentation with the -d switch (restricted by --lines)' do
|
192
|
-
o = Object.new
|
193
|
-
|
194
|
-
# @x = 0
|
195
|
-
# @v = 10
|
196
|
-
# @y = 20
|
197
|
-
# @z = 30
|
198
|
-
def o.test_method
|
199
|
-
:test_method_content
|
200
|
-
end
|
201
|
-
|
202
|
-
redirect_pry_io(InputTester.new('play -d test_method --lines 2..3', "exit-all")) do
|
203
|
-
o.pry
|
204
|
-
end
|
205
|
-
|
206
|
-
o.instance_variable_get(:@x).should == nil
|
207
|
-
o.instance_variable_get(:@z).should == nil
|
208
|
-
o.instance_variable_get(:@v).should == 10
|
209
|
-
o.instance_variable_get(:@y).should == 20
|
210
|
-
end
|
211
|
-
|
212
|
-
|
213
|
-
it 'should play a method with the -m switch (a single line)' do
|
214
|
-
o = Object.new
|
215
|
-
def o.test_method
|
216
|
-
:test_method_content
|
217
|
-
end
|
218
|
-
|
219
|
-
redirect_pry_io(InputTester.new('play -m test_method --lines 2', "exit-all"), @str_output) do
|
220
|
-
o.pry
|
221
|
-
end
|
222
|
-
|
223
|
-
@str_output.string.should =~ /:test_method_content/
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'should APPEND to the input buffer when playing a line with play -m, not replace it' do
|
227
|
-
o = Object.new
|
228
|
-
def o.test_method
|
229
|
-
:test_method_content
|
230
|
-
end
|
231
|
-
|
232
|
-
redirect_pry_io(InputTester.new('def another_test_method', 'play -m test_method --lines 2', 'show-input', 'exit-all'), @str_output) do
|
233
|
-
o.pry
|
234
|
-
end
|
235
|
-
|
236
|
-
@str_output.string.should =~ /def another_test_method/
|
237
|
-
@str_output.string.should =~ /:test_method_content/
|
238
|
-
end
|
239
|
-
|
240
|
-
|
241
|
-
it 'should play a method with the -m switch (multiple line)' do
|
242
|
-
o = Object.new
|
243
|
-
|
244
|
-
def o.test_method
|
245
|
-
@var0 = 10
|
246
|
-
@var1 = 20
|
247
|
-
@var2 = 30
|
248
|
-
@var3 = 40
|
249
|
-
end
|
250
|
-
|
251
|
-
redirect_pry_io(InputTester.new('play -m test_method --lines 3..4', "exit-all"), @str_output) do
|
252
|
-
o.pry
|
253
|
-
end
|
254
|
-
|
255
|
-
o.instance_variable_get(:@var0).should == nil
|
256
|
-
o.instance_variable_get(:@var1).should == 20
|
257
|
-
o.instance_variable_get(:@var2).should == 30
|
258
|
-
o.instance_variable_get(:@var3).should == nil
|
259
|
-
@str_output.string.should =~ /30/
|
260
|
-
@str_output.string.should.not =~ /20/
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe "hist" do
|
265
|
-
before do
|
266
|
-
Pry.history.clear
|
267
|
-
@hist = Pry.history
|
268
|
-
end
|
269
|
-
|
270
|
-
it 'should display the correct history' do
|
271
|
-
@hist.push "hello"
|
272
|
-
@hist.push "world"
|
273
|
-
redirect_pry_io(InputTester.new("hist", "exit-all"), @str_output) do
|
274
|
-
pry
|
275
|
-
end
|
276
|
-
|
277
|
-
@str_output.string.should =~ /hello\n.*world/
|
278
|
-
end
|
279
|
-
|
280
|
-
it 'should replay history correctly (single item)' do
|
281
|
-
o = Object.new
|
282
|
-
@hist.push "@x = 10"
|
283
|
-
@hist.push "@y = 20"
|
284
|
-
@hist.push "@z = 30"
|
285
|
-
redirect_pry_io(InputTester.new("hist --replay -1", "exit-all")) do
|
286
|
-
o.pry
|
287
|
-
end
|
288
|
-
o.instance_variable_get(:@x).should == nil
|
289
|
-
o.instance_variable_get(:@y).should == nil
|
290
|
-
o.instance_variable_get(:@z).should == 30
|
291
|
-
end
|
292
|
-
|
293
|
-
it 'should replay a range of history correctly (range of items)' do
|
294
|
-
o = Object.new
|
295
|
-
@hist.push "@x = 10"
|
296
|
-
@hist.push "@y = 20"
|
297
|
-
redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all")) do
|
298
|
-
o.pry
|
299
|
-
end
|
300
|
-
o.instance_variable_get(:@x).should == 10
|
301
|
-
o.instance_variable_get(:@y).should == 20
|
302
|
-
end
|
303
|
-
|
304
|
-
it 'should grep for correct lines in history' do
|
305
|
-
@hist.push "abby"
|
306
|
-
@hist.push "box"
|
307
|
-
@hist.push "button"
|
308
|
-
@hist.push "pepper"
|
309
|
-
@hist.push "orange"
|
310
|
-
@hist.push "grape"
|
311
|
-
@hist.push "def blah 1"
|
312
|
-
@hist.push "def boink 2"
|
313
|
-
@hist.push "place holder"
|
314
|
-
|
315
|
-
redirect_pry_io(InputTester.new("hist --grep o", "exit-all"), @str_output) do
|
316
|
-
pry
|
317
|
-
end
|
318
|
-
@str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/
|
319
|
-
|
320
|
-
# test more than one word in a regex match (def blah)
|
321
|
-
@str_output = StringIO.new
|
322
|
-
redirect_pry_io(InputTester.new("hist --grep def blah", "exit-all"), @str_output) do
|
323
|
-
pry
|
324
|
-
end
|
325
|
-
@str_output.string.should =~ /def blah 1/
|
326
|
-
|
327
|
-
@str_output = StringIO.new
|
328
|
-
# test more than one word with leading white space in a regex match (def boink)
|
329
|
-
redirect_pry_io(InputTester.new("hist --grep def boink", "exit-all"), @str_output) do
|
330
|
-
pry
|
331
|
-
end
|
332
|
-
@str_output.string.should =~ /def boink 2/
|
333
|
-
end
|
334
|
-
|
335
|
-
it 'should return last N lines in history with --tail switch' do
|
336
|
-
("a".."z").each do |v|
|
337
|
-
@hist.push v
|
338
|
-
end
|
339
|
-
|
340
|
-
redirect_pry_io(InputTester.new("hist --tail 3", "exit-all"), @str_output) do
|
341
|
-
pry
|
342
|
-
end
|
343
|
-
|
344
|
-
@str_output.string.each_line.count.should == 3
|
345
|
-
@str_output.string.should =~ /x\n\d+:.*y\n\d+:.*z/
|
346
|
-
end
|
347
|
-
|
348
|
-
it 'should apply --tail after --grep' do
|
349
|
-
@hist.push "print 1"
|
350
|
-
@hist.push "print 2"
|
351
|
-
@hist.push "puts 3"
|
352
|
-
@hist.push "print 4"
|
353
|
-
@hist.push "puts 5"
|
354
|
-
|
355
|
-
str_output = StringIO.new
|
356
|
-
redirect_pry_io(InputTester.new("hist --tail 2 --grep print", "exit-all"), @str_output) do
|
357
|
-
pry
|
358
|
-
end
|
359
|
-
|
360
|
-
@str_output.string.each_line.count.should == 2
|
361
|
-
@str_output.string.should =~ /\d:.*?print 2\n\d:.*?print 4/
|
362
|
-
end
|
363
|
-
|
364
|
-
it 'should apply --head after --grep' do
|
365
|
-
@hist.push "puts 1"
|
366
|
-
@hist.push "print 2"
|
367
|
-
@hist.push "puts 3"
|
368
|
-
@hist.push "print 4"
|
369
|
-
@hist.push "print 5"
|
370
|
-
|
371
|
-
redirect_pry_io(InputTester.new("hist --head 2 --grep print", "exit-all"), @str_output) do
|
372
|
-
pry
|
373
|
-
end
|
374
|
-
|
375
|
-
@str_output.string.each_line.count.should == 2
|
376
|
-
@str_output.string.should =~ /\d:.*?print 2\n\d:.*?print 4/
|
377
|
-
end
|
378
|
-
|
379
|
-
# strangeness in this test is due to bug in Readline::HISTORY not
|
380
|
-
# always registering first line of input
|
381
|
-
it 'should return first N lines in history with --head switch' do
|
382
|
-
("a".."z").each do |v|
|
383
|
-
@hist.push v
|
384
|
-
end
|
385
|
-
|
386
|
-
redirect_pry_io(InputTester.new("hist --head 4", "exit-all"), @str_output) do
|
387
|
-
pry
|
388
|
-
end
|
389
|
-
|
390
|
-
@str_output.string.each_line.count.should == 4
|
391
|
-
@str_output.string.should =~ /a\n\d+:.*b\n\d+:.*c/
|
392
|
-
end
|
393
|
-
|
394
|
-
# strangeness in this test is due to bug in Readline::HISTORY not
|
395
|
-
# always registering first line of input
|
396
|
-
it 'should show lines between lines A and B with the --show switch' do
|
397
|
-
("a".."z").each do |v|
|
398
|
-
@hist.push v
|
399
|
-
end
|
400
|
-
|
401
|
-
redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), @str_output) do
|
402
|
-
pry
|
403
|
-
end
|
404
|
-
|
405
|
-
@str_output.string.each_line.count.should == 4
|
406
|
-
@str_output.string.should =~ /b\n\d+:.*c\n\d+:.*d/
|
407
|
-
end
|
408
|
-
|
409
|
-
it "should not contain duplicated lines" do
|
410
|
-
redirect_pry_io(InputTester.new("3", "_ += 1", "_ += 1", "hist", "exit-all"), @str_output) do
|
411
|
-
pry
|
412
|
-
end
|
413
|
-
|
414
|
-
@str_output.string.each_line.grep(/_ \+= 1/).count.should == 1
|
415
|
-
end
|
416
|
-
|
417
|
-
it "should not contain duplicated lines" do
|
418
|
-
redirect_pry_io(InputTester.new(":place_holder", "2 + 2", "", "", "3 + 3", "hist", "exit-all"), @str_output) do
|
419
|
-
pry
|
420
|
-
end
|
421
|
-
|
422
|
-
a = @str_output.string.each_line.to_a.index{|line| line.include?("2 + 2") }
|
423
|
-
b = @str_output.string.each_line.to_a.index{|line| line.include?("3 + 3") }
|
424
|
-
|
425
|
-
(a + 1).should == b
|
426
|
-
end
|
427
|
-
end
|
428
|
-
end
|
@@ -1,511 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe "Pry::DefaultCommands::Introspection" do
|
4
|
-
describe "edit" do
|
5
|
-
before do
|
6
|
-
@old_editor = Pry.config.editor
|
7
|
-
@file = nil; @line = nil; @contents = nil
|
8
|
-
Pry.config.editor = lambda do |file, line|
|
9
|
-
@file = file; @line = line; @contents = File.read(@file)
|
10
|
-
nil
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
after do
|
15
|
-
Pry.config.editor = @old_editor
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "with FILE" do
|
19
|
-
it "should invoke Pry.config.editor with absolutified filenames" do
|
20
|
-
mock_pry("edit foo.rb")
|
21
|
-
@file.should == File.expand_path("foo.rb")
|
22
|
-
mock_pry("edit /tmp/bar.rb")
|
23
|
-
@file.should == "/tmp/bar.rb"
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should guess the line number from a colon" do
|
27
|
-
mock_pry("edit /tmp/foo.rb:10")
|
28
|
-
@line.should == 10
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should use the line number from -l" do
|
32
|
-
mock_pry("edit -l 10 /tmp/foo.rb")
|
33
|
-
@line.should == 10
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should not delete the file!" do
|
37
|
-
mock_pry("edit Rakefile")
|
38
|
-
File.exist?(@file).should == true
|
39
|
-
end
|
40
|
-
|
41
|
-
describe do
|
42
|
-
before do
|
43
|
-
@rand = rand
|
44
|
-
Pry.config.editor = lambda { |file, line|
|
45
|
-
File.open(file, 'w') { |f| f << "$rand = #{@rand.inspect}" }
|
46
|
-
nil
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should reload the file if it is a ruby file" do
|
51
|
-
tf = Tempfile.new(["pry", ".rb"])
|
52
|
-
path = tf.path
|
53
|
-
|
54
|
-
mock_pry("edit #{path}", "$rand").should =~ /#{@rand}/
|
55
|
-
|
56
|
-
tf.close(true)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should not reload the file if it is not a ruby file" do
|
60
|
-
tf = Tempfile.new(["pry", ".py"])
|
61
|
-
path = tf.path
|
62
|
-
|
63
|
-
mock_pry("edit #{path}", "$rand").should.not =~ /#{@rand}/
|
64
|
-
|
65
|
-
tf.close(true)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should not reload a ruby file if -n is given" do
|
69
|
-
tf = Tempfile.new(["pry", ".rb"])
|
70
|
-
path = tf.path
|
71
|
-
|
72
|
-
mock_pry("edit -n #{path}", "$rand").should.not =~ /#{@rand}/
|
73
|
-
|
74
|
-
tf.close(true)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should reload a non-ruby file if -r is given" do
|
78
|
-
tf = Tempfile.new(["pry", ".pryrc"])
|
79
|
-
path = tf.path
|
80
|
-
|
81
|
-
mock_pry("edit -r #{path}", "$rand").should =~ /#{@rand}/
|
82
|
-
|
83
|
-
tf.close(true)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe do
|
88
|
-
before do
|
89
|
-
@reloading = nil
|
90
|
-
Pry.config.editor = lambda do |file, line, reloading|
|
91
|
-
@file = file; @line = line; @reloading = reloading
|
92
|
-
nil
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should pass the editor a reloading arg" do
|
97
|
-
mock_pry("edit foo.rb")
|
98
|
-
@reloading.should == true
|
99
|
-
mock_pry("edit -n foo.rb")
|
100
|
-
@reloading.should == false
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "with --ex" do
|
106
|
-
before do
|
107
|
-
@tf = Tempfile.new(["pry", ".rb"])
|
108
|
-
@path = @tf.path
|
109
|
-
@tf << "1\n2\nraise RuntimeError"
|
110
|
-
@tf.flush
|
111
|
-
end
|
112
|
-
after do
|
113
|
-
@tf.close(true)
|
114
|
-
File.unlink("#{@path}c") if File.exists?("#{@path}c") #rbx
|
115
|
-
end
|
116
|
-
it "should open the correct file" do
|
117
|
-
mock_pry("require #{@path.inspect}", "edit --ex")
|
118
|
-
|
119
|
-
@file.should == @path
|
120
|
-
@line.should == 3
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should reload the file" do
|
124
|
-
Pry.config.editor = lambda {|file, line|
|
125
|
-
File.open(file, 'w'){|f| f << "FOO = 'BAR'" }
|
126
|
-
nil
|
127
|
-
}
|
128
|
-
|
129
|
-
mock_pry("require #{@path.inspect}", "edit --ex", "FOO").should =~ /BAR/
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should not reload the file if -n is passed" do
|
133
|
-
Pry.config.editor = lambda {|file, line|
|
134
|
-
File.open(file, 'w'){|f| f << "FOO2 = 'BAZ'" }
|
135
|
-
nil
|
136
|
-
}
|
137
|
-
|
138
|
-
mock_pry("require #{@path.inspect}", "edit -n --ex", "FOO2").should.not =~ /BAZ/
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe "with --ex NUM" do
|
143
|
-
before do
|
144
|
-
Pry.config.editor = proc do |file, line|
|
145
|
-
@__ex_file__ = file
|
146
|
-
@__ex_line__ = line
|
147
|
-
nil
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'should start editor on first level of backtrace when --ex used with no argument ' do
|
152
|
-
pry_instance = Pry.new(:input => StringIO.new("edit -n --ex"), :output => StringIO.new)
|
153
|
-
pry_instance.last_exception = mock_exception("a:1", "b:2", "c:3")
|
154
|
-
pry_instance.rep(self)
|
155
|
-
@__ex_file__.should == "a"
|
156
|
-
@__ex_line__.should == 1
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'should start editor on first level of backtrace when --ex 0 used ' do
|
160
|
-
pry_instance = Pry.new(:input => StringIO.new("edit -n --ex 0"), :output => StringIO.new)
|
161
|
-
pry_instance.last_exception = mock_exception("a:1", "b:2", "c:3")
|
162
|
-
pry_instance.rep(self)
|
163
|
-
@__ex_file__.should == "a"
|
164
|
-
@__ex_line__.should == 1
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'should start editor on second level of backtrace when --ex 1 used' do
|
168
|
-
pry_instance = Pry.new(:input => StringIO.new("edit -n --ex 1"), :output => StringIO.new)
|
169
|
-
pry_instance.last_exception = mock_exception("a:1", "b:2", "c:3")
|
170
|
-
pry_instance.rep(self)
|
171
|
-
@__ex_file__.should == "b"
|
172
|
-
@__ex_line__.should == 2
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'should start editor on third level of backtrace when --ex 2 used' do
|
176
|
-
pry_instance = Pry.new(:input => StringIO.new("edit -n --ex 2"), :output => StringIO.new)
|
177
|
-
pry_instance.last_exception = mock_exception("a:1", "b:2", "c:3")
|
178
|
-
pry_instance.rep(self)
|
179
|
-
@__ex_file__.should == "c"
|
180
|
-
@__ex_line__.should == 3
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'should display error message when backtrace level is out of bounds (using --ex 4)' do
|
184
|
-
pry_instance = Pry.new(:input => StringIO.new("edit -n --ex 4"), :output => str_output = StringIO.new)
|
185
|
-
pry_instance.last_exception = mock_exception("a:1", "b:2", "c:3")
|
186
|
-
pry_instance.rep(self)
|
187
|
-
str_output.string.should =~ /Exception has no associated file/
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe "without FILE" do
|
192
|
-
it "should edit the current expression if it's incomplete" do
|
193
|
-
mock_pry("def a", "edit")
|
194
|
-
@contents.should == "def a\n"
|
195
|
-
end
|
196
|
-
|
197
|
-
it "should edit the previous expression if the current is empty" do
|
198
|
-
mock_pry("def a; 2; end", "edit")
|
199
|
-
@contents.should == "def a; 2; end\n"
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should use a blank file if -t is specified" do
|
203
|
-
mock_pry("def a; 5; end", "edit -t")
|
204
|
-
@contents.should == "\n"
|
205
|
-
end
|
206
|
-
|
207
|
-
it "should use a blank file if -t is specified even half-way through an expression" do
|
208
|
-
mock_pry("def a;", "edit -t")
|
209
|
-
@contents.should == "\n"
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should position the cursor at the end of the expression" do
|
213
|
-
mock_pry("def a; 2;"," end", "edit")
|
214
|
-
@line.should == 2
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should evaluate the expression" do
|
218
|
-
Pry.config.editor = lambda {|file, line|
|
219
|
-
File.open(file, 'w'){|f| f << "'FOO'\n" }
|
220
|
-
nil
|
221
|
-
}
|
222
|
-
mock_pry("edit").should =~ /FOO/
|
223
|
-
end
|
224
|
-
it "should not evaluate the expression with -n" do
|
225
|
-
Pry.config.editor = lambda {|file, line|
|
226
|
-
File.open(file, 'w'){|f| f << "'FOO'\n" }
|
227
|
-
nil
|
228
|
-
}
|
229
|
-
mock_pry("edit -n").should.not =~ /FOO/
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
describe "with --in" do
|
234
|
-
it "should edit the nth line of _in_" do
|
235
|
-
mock_pry("10", "11", "edit --in -2")
|
236
|
-
@contents.should == "10\n"
|
237
|
-
end
|
238
|
-
|
239
|
-
it "should edit the last line if no argument is given" do
|
240
|
-
mock_pry("10", "11", "edit --in")
|
241
|
-
@contents.should == "11\n"
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should edit a range of lines if a range is given" do
|
245
|
-
mock_pry("10", "11", "edit -i 1,2")
|
246
|
-
@contents.should == "10\n11\n"
|
247
|
-
end
|
248
|
-
|
249
|
-
it "should edit a multi-line expression as it occupies one line of _in_" do
|
250
|
-
mock_pry("class Fixnum", " def invert; -self; end", "end", "edit -i 1")
|
251
|
-
@contents.should == "class Fixnum\n def invert; -self; end\nend\n"
|
252
|
-
end
|
253
|
-
|
254
|
-
it "should not work with a filename" do
|
255
|
-
mock_pry("edit ruby.rb -i").should =~ /Only one of --ex, --temp, --in and FILE may be specified/
|
256
|
-
end
|
257
|
-
|
258
|
-
it "should not work with nonsense" do
|
259
|
-
mock_pry("edit --in three").should =~ /Not a valid range: three/
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe "edit-method" do
|
265
|
-
describe "on a method defined in a file" do
|
266
|
-
before do
|
267
|
-
@tempfile = Tempfile.new(['pry', '*.rb'])
|
268
|
-
@tempfile.puts <<-EOS
|
269
|
-
module A
|
270
|
-
def a
|
271
|
-
:yup
|
272
|
-
end
|
273
|
-
|
274
|
-
def b
|
275
|
-
:kinda
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
class X
|
280
|
-
include A
|
281
|
-
|
282
|
-
def self.x
|
283
|
-
:double_yup
|
284
|
-
end
|
285
|
-
|
286
|
-
def x
|
287
|
-
:nope
|
288
|
-
end
|
289
|
-
|
290
|
-
def b
|
291
|
-
super
|
292
|
-
end
|
293
|
-
alias c b
|
294
|
-
|
295
|
-
def y?
|
296
|
-
:because
|
297
|
-
end
|
298
|
-
end
|
299
|
-
EOS
|
300
|
-
@tempfile.flush
|
301
|
-
load @tempfile.path
|
302
|
-
end
|
303
|
-
|
304
|
-
after do
|
305
|
-
@tempfile.close(true)
|
306
|
-
end
|
307
|
-
|
308
|
-
describe 'without -p' do
|
309
|
-
before do
|
310
|
-
@old_editor = Pry.config.editor
|
311
|
-
@file, @line, @contents = nil, nil, nil
|
312
|
-
Pry.config.editor = lambda do |file, line|
|
313
|
-
@file = file; @line = line
|
314
|
-
nil
|
315
|
-
end
|
316
|
-
end
|
317
|
-
after do
|
318
|
-
Pry.config.editor = @old_editor
|
319
|
-
end
|
320
|
-
|
321
|
-
it "should correctly find a class method" do
|
322
|
-
mock_pry("edit-method X.x")
|
323
|
-
@file.should == @tempfile.path
|
324
|
-
@line.should == 14
|
325
|
-
end
|
326
|
-
|
327
|
-
it "should correctly find an instance method" do
|
328
|
-
mock_pry("edit-method X#x")
|
329
|
-
@file.should == @tempfile.path
|
330
|
-
@line.should == 18
|
331
|
-
end
|
332
|
-
|
333
|
-
it "should correctly find a method on an instance" do
|
334
|
-
mock_pry("x = X.new", "edit-method x.x")
|
335
|
-
@file.should == @tempfile.path
|
336
|
-
@line.should == 18
|
337
|
-
end
|
338
|
-
|
339
|
-
it "should correctly find a method from a module" do
|
340
|
-
mock_pry("edit-method X#a")
|
341
|
-
@file.should == @tempfile.path
|
342
|
-
@line.should == 2
|
343
|
-
end
|
344
|
-
|
345
|
-
it "should correctly find an aliased method" do
|
346
|
-
mock_pry("edit-method X#c")
|
347
|
-
@file.should == @tempfile.path
|
348
|
-
@line.should == 22
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
describe 'with -p' do
|
353
|
-
before do
|
354
|
-
@old_editor = Pry.config.editor
|
355
|
-
Pry.config.editor = lambda do |file, line|
|
356
|
-
lines = File.read(file).lines.to_a
|
357
|
-
lines[1] = ":maybe\n"
|
358
|
-
File.open(file, 'w') do |f|
|
359
|
-
f.write(lines.join)
|
360
|
-
end
|
361
|
-
nil
|
362
|
-
end
|
363
|
-
end
|
364
|
-
after do
|
365
|
-
Pry.config.editor = @old_editor
|
366
|
-
end
|
367
|
-
|
368
|
-
it "should successfully replace a class method" do
|
369
|
-
mock_pry("edit-method -p X.x")
|
370
|
-
|
371
|
-
class << X
|
372
|
-
X.method(:x).owner.should == self
|
373
|
-
end
|
374
|
-
X.method(:x).receiver.should == X
|
375
|
-
X.x.should == :maybe
|
376
|
-
end
|
377
|
-
|
378
|
-
it "should successfully replace an instance method" do
|
379
|
-
mock_pry("edit-method -p X#x")
|
380
|
-
|
381
|
-
X.instance_method(:x).owner.should == X
|
382
|
-
X.new.x.should == :maybe
|
383
|
-
end
|
384
|
-
|
385
|
-
it "should successfully replace a method on an instance" do
|
386
|
-
mock_pry("instance = X.new", "edit-method -p instance.x")
|
387
|
-
|
388
|
-
instance = X.new
|
389
|
-
instance.method(:x).owner.should == X
|
390
|
-
instance.x.should == :maybe
|
391
|
-
end
|
392
|
-
|
393
|
-
it "should successfully replace a method from a module" do
|
394
|
-
mock_pry("edit-method -p X#a")
|
395
|
-
|
396
|
-
X.instance_method(:a).owner.should == A
|
397
|
-
X.new.a.should == :maybe
|
398
|
-
end
|
399
|
-
|
400
|
-
it "should successfully replace a method with a question mark" do
|
401
|
-
mock_pry("edit-method -p X#y?")
|
402
|
-
|
403
|
-
X.instance_method(:y?).owner.should == X
|
404
|
-
X.new.y?.should == :maybe
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
describe 'on an aliased method' do
|
409
|
-
before do
|
410
|
-
@old_editor = Pry.config.editor
|
411
|
-
Pry.config.editor = lambda do |file, line|
|
412
|
-
lines = File.read(file).lines.to_a
|
413
|
-
lines[1] = '"#{super}aa".to_sym' + "\n"
|
414
|
-
File.open(file, 'w') do |f|
|
415
|
-
f.write(lines.join)
|
416
|
-
end
|
417
|
-
nil
|
418
|
-
end
|
419
|
-
end
|
420
|
-
after do
|
421
|
-
Pry.config.editor = @old_editor
|
422
|
-
end
|
423
|
-
|
424
|
-
it "should change the alias, but not the original, without breaking super" do
|
425
|
-
mock_pry("edit-method -p X#c")
|
426
|
-
|
427
|
-
Pry::Method.from_str("X#c").alias?.should == true
|
428
|
-
|
429
|
-
X.new.b.should == :kinda
|
430
|
-
X.new.c.should == :kindaaa
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
describe 'with three-arg editor' do
|
435
|
-
before do
|
436
|
-
@old_editor = Pry.config.editor
|
437
|
-
@file, @line, @reloading = nil, nil, nil
|
438
|
-
Pry.config.editor = lambda do |file, line, reloading|
|
439
|
-
@file = file; @line = line; @reloading = reloading
|
440
|
-
nil
|
441
|
-
end
|
442
|
-
end
|
443
|
-
after do
|
444
|
-
Pry.config.editor = @old_editor
|
445
|
-
end
|
446
|
-
|
447
|
-
it "should pass the editor a reloading arg" do
|
448
|
-
mock_pry('edit-method X.x')
|
449
|
-
@reloading.should == true
|
450
|
-
mock_pry('edit-method -n X.x')
|
451
|
-
@reloading.should == false
|
452
|
-
end
|
453
|
-
end
|
454
|
-
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
# show-command only works in implementations that support Proc#source_location
|
459
|
-
if Proc.method_defined?(:source_location)
|
460
|
-
describe "show-command" do
|
461
|
-
before do
|
462
|
-
@str_output = StringIO.new
|
463
|
-
end
|
464
|
-
|
465
|
-
it 'should show source for an ordinary command' do
|
466
|
-
set = Pry::CommandSet.new do
|
467
|
-
import_from Pry::Commands, "show-command"
|
468
|
-
command "foo" do
|
469
|
-
:body_of_foo
|
470
|
-
end
|
471
|
-
end
|
472
|
-
|
473
|
-
redirect_pry_io(InputTester.new("show-command foo"), @str_output) do
|
474
|
-
Pry.new(:commands => set).rep
|
475
|
-
end
|
476
|
-
|
477
|
-
@str_output.string.should =~ /:body_of_foo/
|
478
|
-
end
|
479
|
-
|
480
|
-
it 'should show source for a command with spaces in its name' do
|
481
|
-
set = Pry::CommandSet.new do
|
482
|
-
import_from Pry::Commands, "show-command"
|
483
|
-
command "foo bar" do
|
484
|
-
:body_of_foo_bar
|
485
|
-
end
|
486
|
-
end
|
487
|
-
|
488
|
-
redirect_pry_io(InputTester.new("show-command \"foo bar\""), @str_output) do
|
489
|
-
Pry.new(:commands => set).rep
|
490
|
-
end
|
491
|
-
|
492
|
-
@str_output.string.should =~ /:body_of_foo_bar/
|
493
|
-
end
|
494
|
-
|
495
|
-
it 'should show source for a command by listing name' do
|
496
|
-
set = Pry::CommandSet.new do
|
497
|
-
import_from Pry::Commands, "show-command"
|
498
|
-
command /foo(.*)/, "", :listing => "bar" do
|
499
|
-
:body_of_foo_regex
|
500
|
-
end
|
501
|
-
end
|
502
|
-
|
503
|
-
redirect_pry_io(InputTester.new("show-command bar"), @str_output) do
|
504
|
-
Pry.new(:commands => set).rep
|
505
|
-
end
|
506
|
-
|
507
|
-
@str_output.string.should =~ /:body_of_foo_regex/
|
508
|
-
end
|
509
|
-
end
|
510
|
-
end
|
511
|
-
end
|