pry 0.10.pre.1-java → 0.10.0.pre2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +41 -35
- data/lib/pry.rb +82 -139
- data/lib/pry/cli.rb +77 -30
- data/lib/pry/code.rb +126 -182
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +71 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +172 -0
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +184 -28
- data/lib/pry/command_set.rb +113 -59
- 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 +62 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +77 -0
- data/lib/pry/commands/cat/file_formatter.rb +67 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +41 -0
- data/lib/pry/commands/change_inspector.rb +27 -0
- data/lib/pry/commands/change_prompt.rb +26 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/disabled_commands.rb +2 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +195 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +36 -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 +23 -0
- data/lib/pry/commands/find_method.rb +193 -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 +32 -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 +101 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +180 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +53 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +114 -0
- data/lib/pry/commands/ls/constants.rb +47 -0
- data/lib/pry/commands/ls/formatter.rb +49 -0
- data/lib/pry/commands/ls/globals.rb +48 -0
- data/lib/pry/commands/ls/grep.rb +21 -0
- data/lib/pry/commands/ls/instance_vars.rb +39 -0
- data/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/lib/pry/commands/ls/local_names.rb +35 -0
- data/lib/pry/commands/ls/local_vars.rb +39 -0
- data/lib/pry/commands/ls/ls_entity.rb +70 -0
- data/lib/pry/commands/ls/methods.rb +57 -0
- data/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/lib/pry/commands/ls/self_methods.rb +32 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +103 -0
- data/lib/pry/commands/pry_backtrace.rb +25 -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 +62 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +60 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +48 -0
- data/lib/pry/commands/shell_mode.rb +25 -0
- data/lib/pry/commands/show_doc.rb +83 -0
- data/lib/pry/commands/show_info.rb +195 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +50 -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 +24 -0
- data/lib/pry/commands/watch_expression.rb +105 -0
- data/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/lib/pry/commands/whereami.rb +190 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/config.rb +20 -229
- data/lib/pry/config/behavior.rb +139 -0
- data/lib/pry/config/convenience.rb +26 -0
- data/lib/pry/config/default.rb +165 -0
- data/lib/pry/core_extensions.rb +59 -38
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +40 -154
- data/lib/pry/helpers/command_helpers.rb +19 -130
- data/lib/pry/helpers/documentation_helpers.rb +21 -11
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +8 -9
- data/lib/pry/history.rb +61 -45
- data/lib/pry/history_array.rb +11 -1
- data/lib/pry/hooks.rb +10 -32
- data/lib/pry/indent.rb +110 -38
- data/lib/pry/input_completer.rb +242 -0
- data/lib/pry/input_lock.rb +132 -0
- data/lib/pry/inspector.rb +27 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method.rb +199 -200
- data/lib/pry/method/disowned.rb +53 -0
- data/lib/pry/method/patcher.rb +125 -0
- data/lib/pry/method/weird_method_locator.rb +186 -0
- data/lib/pry/module_candidate.rb +39 -33
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +234 -0
- data/lib/pry/plugins.rb +4 -3
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +199 -227
- data/lib/pry/pry_instance.rb +344 -403
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +20 -26
- data/lib/pry/rubygem.rb +82 -0
- data/lib/pry/terminal.rb +79 -0
- data/lib/pry/test/helper.rb +170 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +133 -48
- metadata +132 -197
- data/.document +0 -2
- data/.gemtest +0 -0
- data/.gitignore +0 -16
- data/.travis.yml +0 -17
- data/.yardopts +0 -1
- data/CHANGELOG +0 -387
- data/CONTRIBUTORS +0 -36
- data/Gemfile +0 -2
- data/Rakefile +0 -137
- data/TODO +0 -117
- 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/completion.rb +0 -221
- data/lib/pry/custom_completions.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/lib/pry/rbx_method.rb +0 -13
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -46
- data/test/candidate_helper1.rb +0 -11
- data/test/candidate_helper2.rb +0 -8
- data/test/helper.rb +0 -223
- data/test/test_cli.rb +0 -78
- data/test/test_code.rb +0 -201
- data/test/test_command.rb +0 -712
- data/test/test_command_helpers.rb +0 -9
- data/test/test_command_integration.rb +0 -668
- data/test/test_command_set.rb +0 -610
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/example.erb +0 -5
- data/test/test_default_commands/test_cd.rb +0 -318
- data/test/test_default_commands/test_context.rb +0 -280
- data/test/test_default_commands/test_documentation.rb +0 -314
- data/test/test_default_commands/test_find_method.rb +0 -50
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_help.rb +0 -57
- 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_exception_whitelist.rb +0 -21
- data/test/test_history_array.rb +0 -65
- data/test/test_hooks.rb +0 -521
- data/test/test_indent.rb +0 -277
- data/test/test_input_stack.rb +0 -86
- data/test/test_method.rb +0 -401
- data/test/test_pry.rb +0 -463
- data/test/test_pry_defaults.rb +0 -419
- data/test/test_pry_history.rb +0 -84
- data/test/test_pry_output.rb +0 -41
- data/test/test_sticky_locals.rb +0 -155
- data/test/test_syntax_checking.rb +0 -65
- data/test/test_wrapped_module.rb +0 -174
- data/test/testrc +0 -2
- data/test/testrcbad +0 -2
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
data/test/test_history_array.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Pry::HistoryArray do
|
4
|
-
before do
|
5
|
-
@array = Pry::HistoryArray.new 10
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should have a maximum size specifed at creation time' do
|
9
|
-
@array.max_size.should == 10
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should be able to be added objects to' do
|
13
|
-
@array << 1 << 2 << 3
|
14
|
-
@array.size.should == 3
|
15
|
-
@array.to_a.should == [1, 2, 3]
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should be able to access single elements' do
|
19
|
-
@array << 1 << 2 << 3
|
20
|
-
@array[2].should == 3
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should be able to access negative indices' do
|
24
|
-
@array << 1 << 2 << 3
|
25
|
-
@array[-1].should == 3
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should be able to access ranges' do
|
29
|
-
@array << 1 << 2 << 3 << 4
|
30
|
-
@array[1..2].should == [2, 3]
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should be able to access ranges starting from a negative index' do
|
34
|
-
@array << 1 << 2 << 3 << 4
|
35
|
-
@array[-2..3].should == [3, 4]
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should be able to access ranges ending at a negative index' do
|
39
|
-
@array << 1 << 2 << 3 << 4
|
40
|
-
@array[2..-1].should == [3, 4]
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should be able to access ranges using only negative indices' do
|
44
|
-
@array << 1 << 2 << 3 << 4
|
45
|
-
@array[-2..-1].should == [3, 4]
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should be able to use range where end is excluded' do
|
49
|
-
@array << 1 << 2 << 3 << 4
|
50
|
-
@array[-2...-1].should == [3]
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should be able to access slices using a size' do
|
54
|
-
@array << 1 << 2 << 3 << 4
|
55
|
-
@array[-3, 2].should == [2, 3]
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should remove older entries' do
|
59
|
-
11.times { |n| @array << n }
|
60
|
-
|
61
|
-
@array[0].should == nil
|
62
|
-
@array[1].should == 1
|
63
|
-
@array[10].should == 10
|
64
|
-
end
|
65
|
-
end
|
data/test/test_hooks.rb
DELETED
@@ -1,521 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Pry::Hooks do
|
4
|
-
before do
|
5
|
-
@hooks = Pry::Hooks.new
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "adding a new hook" do
|
9
|
-
it 'should not execute hook while adding it' do
|
10
|
-
run = false
|
11
|
-
@hooks.add_hook(:test_hook, :my_name) { run = true }
|
12
|
-
run.should == false
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should not allow adding of a hook with a duplicate name' do
|
16
|
-
@hooks.add_hook(:test_hook, :my_name) {}
|
17
|
-
|
18
|
-
lambda { @hooks.add_hook(:test_hook, :my_name) {} }.should.raise ArgumentError
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should create a new hook with a block' do
|
22
|
-
@hooks.add_hook(:test_hook, :my_name) { }
|
23
|
-
@hooks.hook_count(:test_hook).should == 1
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should create a new hook with a callable' do
|
27
|
-
@hooks.add_hook(:test_hook, :my_name, proc { })
|
28
|
-
@hooks.hook_count(:test_hook).should == 1
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should use block if given both block and callable' do
|
32
|
-
run = false
|
33
|
-
foo = false
|
34
|
-
@hooks.add_hook(:test_hook, :my_name, proc { foo = true }) { run = true }
|
35
|
-
@hooks.hook_count(:test_hook).should == 1
|
36
|
-
@hooks.exec_hook(:test_hook)
|
37
|
-
run.should == true
|
38
|
-
foo.should == false
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should raise if not given a block or any other object' do
|
42
|
-
lambda { @hooks.add_hook(:test_hook, :my_name) }.should.raise ArgumentError
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should create multiple hooks for an event' do
|
46
|
-
@hooks.add_hook(:test_hook, :my_name) {}
|
47
|
-
@hooks.add_hook(:test_hook, :my_name2) {}
|
48
|
-
@hooks.hook_count(:test_hook).should == 2
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should return a count of 0 for an empty hook' do
|
52
|
-
@hooks.hook_count(:test_hook).should == 0
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "Pry::Hooks#merge" do
|
57
|
-
describe "merge!" do
|
58
|
-
it 'should merge in the Pry::Hooks' do
|
59
|
-
h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
|
60
|
-
h2 = Pry::Hooks.new
|
61
|
-
|
62
|
-
h2.merge!(h1)
|
63
|
-
h2.get_hook(:test_hook, :testing).should == h1.get_hook(:test_hook, :testing)
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'should not share merged elements with original' do
|
67
|
-
h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
|
68
|
-
h2 = Pry::Hooks.new
|
69
|
-
|
70
|
-
h2.merge!(h1)
|
71
|
-
h2.add_hook(:test_hook, :testing2) {}
|
72
|
-
h2.get_hook(:test_hook, :testing2).should.not == h1.get_hook(:test_hook, :testing2)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'should NOT overwrite hooks belonging to shared event in receiver' do
|
76
|
-
h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
|
77
|
-
callable = proc {}
|
78
|
-
h2 = Pry::Hooks.new.add_hook(:test_hook, :testing2, callable)
|
79
|
-
|
80
|
-
h2.merge!(h1)
|
81
|
-
h2.get_hook(:test_hook, :testing2).should == callable
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should overwrite identical hook in receiver' do
|
85
|
-
callable1 = proc { :one }
|
86
|
-
h1 = Pry::Hooks.new.add_hook(:test_hook, :testing, callable1)
|
87
|
-
callable2 = proc { :two }
|
88
|
-
h2 = Pry::Hooks.new.add_hook(:test_hook, :testing, callable2)
|
89
|
-
|
90
|
-
h2.merge!(h1)
|
91
|
-
h2.get_hook(:test_hook, :testing).should == callable1
|
92
|
-
h2.hook_count(:test_hook).should == 1
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'should preserve hook order' do
|
96
|
-
name = ""
|
97
|
-
h1 = Pry::Hooks.new
|
98
|
-
h1.add_hook(:test_hook, :testing3) { name << "h" }
|
99
|
-
h1.add_hook(:test_hook, :testing4) { name << "n" }
|
100
|
-
|
101
|
-
h2 = Pry::Hooks.new
|
102
|
-
h2.add_hook(:test_hook, :testing1) { name << "j" }
|
103
|
-
h2.add_hook(:test_hook, :testing2) { name << "o" }
|
104
|
-
|
105
|
-
h2.merge!(h1)
|
106
|
-
h2.exec_hook(:test_hook)
|
107
|
-
|
108
|
-
name.should == "john"
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "merge" do
|
112
|
-
it 'should return a fresh, independent instance' do
|
113
|
-
h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
|
114
|
-
h2 = Pry::Hooks.new
|
115
|
-
|
116
|
-
h3 = h2.merge(h1)
|
117
|
-
h3.should.not == h1
|
118
|
-
h3.should.not == h2
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'should contain hooks from original instance' do
|
122
|
-
h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
|
123
|
-
h2 = Pry::Hooks.new.add_hook(:test_hook2, :testing) {}
|
124
|
-
|
125
|
-
h3 = h2.merge(h1)
|
126
|
-
h3.get_hook(:test_hook, :testing).should == h1.get_hook(:test_hook, :testing)
|
127
|
-
h3.get_hook(:test_hook2, :testing).should == h2.get_hook(:test_hook2, :testing)
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'should not affect original instances when new hooks are added' do
|
131
|
-
h1 = Pry::Hooks.new.add_hook(:test_hook, :testing) {}
|
132
|
-
h2 = Pry::Hooks.new.add_hook(:test_hook2, :testing) {}
|
133
|
-
|
134
|
-
h3 = h2.merge(h1)
|
135
|
-
h3.add_hook(:test_hook3, :testing) {}
|
136
|
-
|
137
|
-
h1.get_hook(:test_hook3, :testing).should == nil
|
138
|
-
h2.get_hook(:test_hook3, :testing).should == nil
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe "dupping a Pry::Hooks instance" do
|
146
|
-
it 'should share hooks with original' do
|
147
|
-
@hooks.add_hook(:test_hook, :testing) do
|
148
|
-
:none_such
|
149
|
-
end
|
150
|
-
|
151
|
-
hooks_dup = @hooks.dup
|
152
|
-
hooks_dup.get_hook(:test_hook, :testing).should == @hooks.get_hook(:test_hook, :testing)
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'adding a new event to dupped instance should not affect original' do
|
156
|
-
@hooks.add_hook(:test_hook, :testing) { :none_such }
|
157
|
-
hooks_dup = @hooks.dup
|
158
|
-
|
159
|
-
hooks_dup.add_hook(:other_test_hook, :testing) { :okay_man }
|
160
|
-
|
161
|
-
hooks_dup.get_hook(:other_test_hook, :testing).should.not == @hooks.get_hook(:other_test_hook, :testing)
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'adding a new hook to dupped instance should not affect original' do
|
165
|
-
@hooks.add_hook(:test_hook, :testing) { :none_such }
|
166
|
-
hooks_dup = @hooks.dup
|
167
|
-
|
168
|
-
hooks_dup.add_hook(:test_hook, :testing2) { :okay_man }
|
169
|
-
|
170
|
-
hooks_dup.get_hook(:test_hook, :testing2).should.not == @hooks.get_hook(:test_hook, :testing2)
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|
174
|
-
|
175
|
-
describe "getting hooks" do
|
176
|
-
describe "get_hook" do
|
177
|
-
it 'should return the correct requested hook' do
|
178
|
-
run = false
|
179
|
-
fun = false
|
180
|
-
@hooks.add_hook(:test_hook, :my_name) { run = true }
|
181
|
-
@hooks.add_hook(:test_hook, :my_name2) { fun = true }
|
182
|
-
@hooks.get_hook(:test_hook, :my_name).call
|
183
|
-
run.should == true
|
184
|
-
fun.should == false
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'should return nil if hook does not exist' do
|
188
|
-
@hooks.get_hook(:test_hook, :my_name).should == nil
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
describe "get_hooks" do
|
193
|
-
it 'should return a hash of hook names/hook functions for an event' do
|
194
|
-
hook1 = proc { 1 }
|
195
|
-
hook2 = proc { 2 }
|
196
|
-
@hooks.add_hook(:test_hook, :my_name1, hook1)
|
197
|
-
@hooks.add_hook(:test_hook, :my_name2, hook2)
|
198
|
-
hash = @hooks.get_hooks(:test_hook)
|
199
|
-
hash.size.should == 2
|
200
|
-
hash[:my_name1].should == hook1
|
201
|
-
hash[:my_name2].should == hook2
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'should return an empty hash if no hooks defined' do
|
205
|
-
@hooks.get_hooks(:test_hook).should == {}
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
describe "clearing all hooks for an event" do
|
211
|
-
it 'should clear all hooks' do
|
212
|
-
@hooks.add_hook(:test_hook, :my_name) { }
|
213
|
-
@hooks.add_hook(:test_hook, :my_name2) { }
|
214
|
-
@hooks.add_hook(:test_hook, :my_name3) { }
|
215
|
-
@hooks.clear(:test_hook)
|
216
|
-
@hooks.hook_count(:test_hook).should == 0
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe "deleting a hook" do
|
221
|
-
it 'should successfully delete a hook' do
|
222
|
-
@hooks.add_hook(:test_hook, :my_name) {}
|
223
|
-
@hooks.delete_hook(:test_hook, :my_name)
|
224
|
-
@hooks.hook_count(:test_hook).should == 0
|
225
|
-
end
|
226
|
-
|
227
|
-
it 'should return the deleted hook' do
|
228
|
-
run = false
|
229
|
-
@hooks.add_hook(:test_hook, :my_name) { run = true }
|
230
|
-
@hooks.delete_hook(:test_hook, :my_name).call
|
231
|
-
run.should == true
|
232
|
-
end
|
233
|
-
|
234
|
-
it 'should return nil if hook does not exist' do
|
235
|
-
@hooks.delete_hook(:test_hook, :my_name).should == nil
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
describe "executing a hook" do
|
240
|
-
it 'should execute block hook' do
|
241
|
-
run = false
|
242
|
-
@hooks.add_hook(:test_hook, :my_name) { run = true }
|
243
|
-
@hooks.exec_hook(:test_hook)
|
244
|
-
run.should == true
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'should execute proc hook' do
|
248
|
-
run = false
|
249
|
-
@hooks.add_hook(:test_hook, :my_name, proc { run = true })
|
250
|
-
@hooks.exec_hook(:test_hook)
|
251
|
-
run.should == true
|
252
|
-
end
|
253
|
-
|
254
|
-
it 'should execute a general callable hook' do
|
255
|
-
callable = Object.new.tap do |obj|
|
256
|
-
obj.instance_variable_set(:@test_var, nil)
|
257
|
-
class << obj
|
258
|
-
attr_accessor :test_var
|
259
|
-
def call() @test_var = true; end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
@hooks.add_hook(:test_hook, :my_name, callable)
|
264
|
-
@hooks.exec_hook(:test_hook)
|
265
|
-
callable.test_var.should == true
|
266
|
-
end
|
267
|
-
|
268
|
-
it 'should execute all hooks for an event if more than one is defined' do
|
269
|
-
x = nil
|
270
|
-
y = nil
|
271
|
-
@hooks.add_hook(:test_hook, :my_name1) { y = true }
|
272
|
-
@hooks.add_hook(:test_hook, :my_name2) { x = true }
|
273
|
-
@hooks.exec_hook(:test_hook)
|
274
|
-
x.should == true
|
275
|
-
y.should == true
|
276
|
-
end
|
277
|
-
|
278
|
-
it 'should execute hooks in order' do
|
279
|
-
array = []
|
280
|
-
@hooks.add_hook(:test_hook, :my_name1) { array << 1 }
|
281
|
-
@hooks.add_hook(:test_hook, :my_name2) { array << 2 }
|
282
|
-
@hooks.add_hook(:test_hook, :my_name3) { array << 3 }
|
283
|
-
@hooks.exec_hook(:test_hook)
|
284
|
-
array.should == [1, 2, 3]
|
285
|
-
end
|
286
|
-
|
287
|
-
it 'return value of exec_hook should be that of last executed hook' do
|
288
|
-
@hooks.add_hook(:test_hook, :my_name1) { 1 }
|
289
|
-
@hooks.add_hook(:test_hook, :my_name2) { 2 }
|
290
|
-
@hooks.add_hook(:test_hook, :my_name3) { 3 }
|
291
|
-
@hooks.exec_hook(:test_hook).should == 3
|
292
|
-
end
|
293
|
-
|
294
|
-
it 'should add exceptions to the errors array' do
|
295
|
-
@hooks.add_hook(:test_hook, :foo1) { raise 'one' }
|
296
|
-
@hooks.add_hook(:test_hook, :foo2) { raise 'two' }
|
297
|
-
@hooks.add_hook(:test_hook, :foo3) { raise 'three' }
|
298
|
-
@hooks.exec_hook(:test_hook)
|
299
|
-
@hooks.errors.map(&:message).should == ['one', 'two', 'three']
|
300
|
-
end
|
301
|
-
|
302
|
-
it 'should return the last exception raised as the return value' do
|
303
|
-
@hooks.add_hook(:test_hook, :foo1) { raise 'one' }
|
304
|
-
@hooks.add_hook(:test_hook, :foo2) { raise 'two' }
|
305
|
-
@hooks.add_hook(:test_hook, :foo3) { raise 'three' }
|
306
|
-
@hooks.exec_hook(:test_hook).should == @hooks.errors.last
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
describe "integration tests" do
|
311
|
-
describe "when_started hook" do
|
312
|
-
it 'should yield options to the hook' do
|
313
|
-
options = nil
|
314
|
-
Pry.config.hooks.add_hook(:when_started, :test_hook) { |target, opt, _| options = opt }
|
315
|
-
|
316
|
-
redirect_pry_io(StringIO.new("exit"), out=StringIO.new) do
|
317
|
-
Pry.start binding, :hello => :baby
|
318
|
-
end
|
319
|
-
options[:hello].should == :baby
|
320
|
-
|
321
|
-
Pry.config.hooks.delete_hook(:when_started, :test_hook)
|
322
|
-
end
|
323
|
-
|
324
|
-
describe "target" do
|
325
|
-
|
326
|
-
it 'should yield the target, as a binding ' do
|
327
|
-
b = nil
|
328
|
-
Pry.config.hooks.add_hook(:when_started, :test_hook) { |target, opt, _| b = target }
|
329
|
-
|
330
|
-
redirect_pry_io(StringIO.new("exit"), out=StringIO.new) do
|
331
|
-
Pry.start 5, :hello => :baby
|
332
|
-
end
|
333
|
-
|
334
|
-
b.is_a?(Binding).should == true
|
335
|
-
Pry.config.hooks.delete_hook(:when_started, :test_hook)
|
336
|
-
end
|
337
|
-
|
338
|
-
it 'should yield the target to the hook' do
|
339
|
-
b = nil
|
340
|
-
Pry.config.hooks.add_hook(:when_started, :test_hook) { |target, opt, _| b = target }
|
341
|
-
|
342
|
-
redirect_pry_io(StringIO.new("exit"), out=StringIO.new) do
|
343
|
-
Pry.start 5, :hello => :baby
|
344
|
-
end
|
345
|
-
|
346
|
-
b.eval('self').should == 5
|
347
|
-
Pry.config.hooks.delete_hook(:when_started, :test_hook)
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
it 'should allow overriding of target (and binding_stack)' do
|
352
|
-
options = nil
|
353
|
-
o = Object.new
|
354
|
-
class << o; attr_accessor :value; end
|
355
|
-
|
356
|
-
Pry.config.hooks.add_hook(:when_started, :test_hook) { |target, opt, _pry_| _pry_.binding_stack = [Pry.binding_for(o)] }
|
357
|
-
|
358
|
-
redirect_pry_io(InputTester.new("@value = true","exit-all")) do
|
359
|
-
Pry.start binding, :hello => :baby
|
360
|
-
end
|
361
|
-
|
362
|
-
o.value.should == true
|
363
|
-
Pry.config.hooks.delete_hook(:when_started, :test_hook)
|
364
|
-
end
|
365
|
-
|
366
|
-
end
|
367
|
-
|
368
|
-
describe "after_session hook" do
|
369
|
-
it 'should always run, even if uncaught exception bubbles out of repl' do
|
370
|
-
o = OpenStruct.new
|
371
|
-
o.great_escape = Class.new(StandardError)
|
372
|
-
|
373
|
-
old_ew = Pry.config.exception_whitelist
|
374
|
-
Pry.config.exception_whitelist << o.great_escape
|
375
|
-
|
376
|
-
array = [1, 2, 3, 4, 5]
|
377
|
-
|
378
|
-
begin
|
379
|
-
redirect_pry_io(StringIO.new("raise great_escape"), out=StringIO.new) do
|
380
|
-
Pry.start o, :hooks => Pry::Hooks.new.add_hook(:after_session, :cleanup) { array = nil }
|
381
|
-
end
|
382
|
-
rescue => ex
|
383
|
-
exception = ex
|
384
|
-
end
|
385
|
-
|
386
|
-
# ensure that an exception really was raised and it broke out
|
387
|
-
# of the repl
|
388
|
-
exception.is_a?(o.great_escape).should == true
|
389
|
-
|
390
|
-
# check that after_session hook ran
|
391
|
-
array.should == nil
|
392
|
-
|
393
|
-
# cleanup after test
|
394
|
-
Pry.config.exception_whitelist = old_ew
|
395
|
-
end
|
396
|
-
|
397
|
-
describe "before_eval hook" do
|
398
|
-
describe "modifying input code" do
|
399
|
-
it 'should replace input code with code determined by hook' do
|
400
|
-
hooks = Pry::Hooks.new.add_hook(:before_eval, :quirk) { |code, pry| code.replace(":little_duck") }
|
401
|
-
redirect_pry_io(InputTester.new(":jemima", "exit-all"), out = StringIO.new) do
|
402
|
-
Pry.start(self, :hooks => hooks)
|
403
|
-
end
|
404
|
-
out.string.should =~ /little_duck/
|
405
|
-
out.string.should.not =~ /jemima/
|
406
|
-
end
|
407
|
-
|
408
|
-
it 'should not interfere with command processing when replacing input code' do
|
409
|
-
commands = Pry::CommandSet.new do
|
410
|
-
import_from Pry::Commands, "exit-all"
|
411
|
-
|
412
|
-
command "how-do-you-like-your-blue-eyed-boy-now-mister-death" do
|
413
|
-
output.puts "in hours of bitterness i imagine balls of sapphire, of metal"
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
hooks = Pry::Hooks.new.add_hook(:before_eval, :quirk) { |code, pry| code.replace(":little_duck") }
|
418
|
-
redirect_pry_io(InputTester.new("how-do-you-like-your-blue-eyed-boy-now-mister-death", "exit-all"), out = StringIO.new) do
|
419
|
-
Pry.start(self, :hooks => hooks, :commands => commands)
|
420
|
-
end
|
421
|
-
out.string.should =~ /in hours of bitterness i imagine balls of sapphire, of metal/
|
422
|
-
out.string.should.not =~ /little_duck/
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
end
|
427
|
-
|
428
|
-
describe "exceptions" do
|
429
|
-
before do
|
430
|
-
Pry.config.hooks.add_hook(:after_eval, :baddums){ raise "Baddums" }
|
431
|
-
Pry.config.hooks.add_hook(:after_eval, :simbads){ raise "Simbads" }
|
432
|
-
end
|
433
|
-
|
434
|
-
after do
|
435
|
-
Pry.config.hooks.delete_hook(:after_eval, :baddums)
|
436
|
-
Pry.config.hooks.delete_hook(:after_eval, :simbads)
|
437
|
-
end
|
438
|
-
it "should not raise exceptions" do
|
439
|
-
lambda{
|
440
|
-
mock_pry("1", "2", "3")
|
441
|
-
}.should.not.raise
|
442
|
-
end
|
443
|
-
|
444
|
-
it "should print out a notice for each exception raised" do
|
445
|
-
mock_pry("1").should =~ /after_eval hook failed: RuntimeError: Baddums\n.*after_eval hook failed: RuntimeError: Simbads/m
|
446
|
-
end
|
447
|
-
end
|
448
|
-
end
|
449
|
-
end
|
450
|
-
|
451
|
-
describe "anonymous hooks" do
|
452
|
-
it 'should allow adding of hook without a name' do
|
453
|
-
@hooks.add_hook(:test_hook, nil) {}
|
454
|
-
@hooks.hook_count(:test_hook).should == 1
|
455
|
-
end
|
456
|
-
|
457
|
-
it 'should only allow one anonymous hook to exist' do
|
458
|
-
@hooks.add_hook(:test_hook, nil) { }
|
459
|
-
@hooks.add_hook(:test_hook, nil) { }
|
460
|
-
@hooks.hook_count(:test_hook).should == 1
|
461
|
-
end
|
462
|
-
|
463
|
-
it 'should execute most recently added anonymous hook' do
|
464
|
-
x = nil
|
465
|
-
y = nil
|
466
|
-
@hooks.add_hook(:test_hook, nil) { y = 1 }
|
467
|
-
@hooks.add_hook(:test_hook, nil) { x = 2 }
|
468
|
-
@hooks.exec_hook(:test_hook)
|
469
|
-
y.should == nil
|
470
|
-
x.should == 2
|
471
|
-
end
|
472
|
-
end
|
473
|
-
|
474
|
-
describe "deprecated hash-based API" do
|
475
|
-
after do
|
476
|
-
Pry.config.hooks.clear_all if Pry.config.hooks
|
477
|
-
end
|
478
|
-
|
479
|
-
describe "Pry.config.hooks" do
|
480
|
-
it 'should allow a hash-assignment' do
|
481
|
-
Pry.config.hooks = { :before_session => proc { :hello } }
|
482
|
-
Pry.config.hooks.get_hook(:before_session, nil).call.should == :hello
|
483
|
-
end
|
484
|
-
|
485
|
-
describe "Pry.config.hooks[]" do
|
486
|
-
it 'should return the only anonymous hook' do
|
487
|
-
Pry.config.hooks = { :before_session => proc { :hello } }
|
488
|
-
Pry.config.hooks[:before_session].call.should == :hello
|
489
|
-
end
|
490
|
-
|
491
|
-
it 'should add an anonymous hook when using Pry.config.hooks[]=' do
|
492
|
-
Pry.config.hooks[:before_session] = proc { :bing }
|
493
|
-
Pry.config.hooks.hook_count(:before_session).should == 1
|
494
|
-
end
|
495
|
-
|
496
|
-
it 'should add overwrite previous anonymous hooks with new one when calling Pry.config.hooks[]= multiple times' do
|
497
|
-
x = nil
|
498
|
-
Pry.config.hooks[:before_session] = proc { x = 1 }
|
499
|
-
Pry.config.hooks[:before_session] = proc { x = 2 }
|
500
|
-
|
501
|
-
Pry.config.hooks.exec_hook(:before_session)
|
502
|
-
Pry.config.hooks.hook_count(:before_session).should == 1
|
503
|
-
x.should == 2
|
504
|
-
end
|
505
|
-
end
|
506
|
-
end
|
507
|
-
|
508
|
-
describe "Pry.start" do
|
509
|
-
it 'should accept a hash for :hooks parameter' do
|
510
|
-
|
511
|
-
redirect_pry_io(InputTester.new("exit-all"), out=StringIO.new) do
|
512
|
-
Pry.start binding, :hooks => { :before_session => proc { |output, _, _| output.puts 'hello friend' } }
|
513
|
-
end
|
514
|
-
|
515
|
-
out.string.should =~ /hello friend/
|
516
|
-
end
|
517
|
-
|
518
|
-
end
|
519
|
-
end
|
520
|
-
|
521
|
-
end
|