pry 0.9.12.6 → 0.10.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +37 -31
- data/lib/pry.rb +38 -151
- data/lib/pry/cli.rb +35 -17
- data/lib/pry/code.rb +24 -63
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +2 -1
- data/lib/pry/code/loc.rb +2 -2
- data/lib/pry/code_object.rb +40 -21
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +12 -9
- data/lib/pry/command_set.rb +81 -38
- data/lib/pry/commands.rb +1 -1
- data/lib/pry/commands/amend_line.rb +2 -2
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat.rb +11 -2
- data/lib/pry/commands/cat/exception_formatter.rb +5 -6
- data/lib/pry/commands/cat/file_formatter.rb +15 -32
- data/lib/pry/commands/cd.rb +14 -3
- 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 +4 -4
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +10 -22
- data/lib/pry/commands/edit/exception_patcher.rb +2 -2
- data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
- data/lib/pry/commands/exit_program.rb +0 -1
- data/lib/pry/commands/find_method.rb +16 -22
- data/lib/pry/commands/gem_install.rb +5 -2
- data/lib/pry/commands/gem_open.rb +1 -1
- data/lib/pry/commands/gist.rb +10 -11
- data/lib/pry/commands/help.rb +14 -14
- data/lib/pry/commands/hist.rb +27 -8
- data/lib/pry/commands/install_command.rb +14 -12
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +72 -296
- 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/play.rb +44 -10
- data/lib/pry/commands/pry_backtrace.rb +1 -2
- data/lib/pry/commands/raise_up.rb +2 -2
- data/lib/pry/commands/reload_code.rb +16 -19
- data/lib/pry/commands/ri.rb +7 -3
- data/lib/pry/commands/shell_command.rb +18 -13
- data/lib/pry/commands/shell_mode.rb +2 -4
- data/lib/pry/commands/show_doc.rb +5 -0
- data/lib/pry/commands/show_info.rb +8 -13
- data/lib/pry/commands/show_source.rb +15 -3
- data/lib/pry/commands/simple_prompt.rb +1 -1
- data/lib/pry/commands/toggle_color.rb +8 -4
- 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 +18 -10
- data/lib/pry/commands/wtf.rb +3 -3
- data/lib/pry/config.rb +20 -254
- 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 +31 -21
- data/lib/pry/editor.rb +107 -103
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers/base_helpers.rb +22 -109
- data/lib/pry/helpers/command_helpers.rb +10 -8
- data/lib/pry/helpers/documentation_helpers.rb +1 -2
- data/lib/pry/helpers/text.rb +4 -5
- data/lib/pry/history.rb +46 -45
- data/lib/pry/history_array.rb +6 -1
- data/lib/pry/hooks.rb +9 -29
- data/lib/pry/indent.rb +6 -6
- 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 +82 -87
- data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
- data/lib/pry/module_candidate.rb +4 -14
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +191 -47
- data/lib/pry/plugins.rb +1 -1
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +149 -230
- data/lib/pry/pry_instance.rb +302 -413
- 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 +13 -5
- data/lib/pry/terminal.rb +2 -1
- data/lib/pry/test/helper.rb +26 -41
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +45 -59
- metadata +61 -224
- data/.document +0 -2
- data/.gitignore +0 -16
- data/.travis.yml +0 -25
- data/.yardopts +0 -1
- data/CHANGELOG +0 -534
- data/CONTRIBUTORS +0 -55
- data/Gemfile +0 -12
- data/Rakefile +0 -140
- data/TODO +0 -117
- data/lib/pry/completion.rb +0 -321
- data/lib/pry/custom_completions.rb +0 -6
- 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 -29
- data/spec/Procfile +0 -3
- data/spec/cli_spec.rb +0 -78
- data/spec/code_object_spec.rb +0 -277
- data/spec/code_spec.rb +0 -219
- data/spec/command_helpers_spec.rb +0 -29
- data/spec/command_integration_spec.rb +0 -644
- data/spec/command_set_spec.rb +0 -627
- data/spec/command_spec.rb +0 -821
- data/spec/commands/amend_line_spec.rb +0 -247
- data/spec/commands/bang_spec.rb +0 -19
- data/spec/commands/cat_spec.rb +0 -164
- data/spec/commands/cd_spec.rb +0 -250
- data/spec/commands/disable_pry_spec.rb +0 -25
- data/spec/commands/edit_spec.rb +0 -727
- data/spec/commands/exit_all_spec.rb +0 -34
- data/spec/commands/exit_program_spec.rb +0 -19
- data/spec/commands/exit_spec.rb +0 -34
- data/spec/commands/find_method_spec.rb +0 -70
- data/spec/commands/gem_list_spec.rb +0 -26
- data/spec/commands/gist_spec.rb +0 -79
- data/spec/commands/help_spec.rb +0 -56
- data/spec/commands/hist_spec.rb +0 -181
- data/spec/commands/jump_to_spec.rb +0 -15
- data/spec/commands/ls_spec.rb +0 -181
- data/spec/commands/play_spec.rb +0 -140
- data/spec/commands/raise_up_spec.rb +0 -56
- data/spec/commands/save_file_spec.rb +0 -177
- data/spec/commands/show_doc_spec.rb +0 -510
- data/spec/commands/show_input_spec.rb +0 -17
- data/spec/commands/show_source_spec.rb +0 -782
- data/spec/commands/whereami_spec.rb +0 -203
- data/spec/completion_spec.rb +0 -241
- data/spec/control_d_handler_spec.rb +0 -58
- data/spec/documentation_helper_spec.rb +0 -73
- data/spec/editor_spec.rb +0 -79
- data/spec/exception_whitelist_spec.rb +0 -21
- data/spec/fixtures/candidate_helper1.rb +0 -11
- data/spec/fixtures/candidate_helper2.rb +0 -8
- data/spec/fixtures/example.erb +0 -5
- data/spec/fixtures/example_nesting.rb +0 -33
- data/spec/fixtures/show_source_doc_examples.rb +0 -15
- data/spec/fixtures/testrc +0 -2
- data/spec/fixtures/testrcbad +0 -2
- data/spec/fixtures/whereami_helper.rb +0 -6
- data/spec/helper.rb +0 -34
- data/spec/helpers/bacon.rb +0 -86
- data/spec/helpers/mock_pry.rb +0 -43
- data/spec/helpers/table_spec.rb +0 -105
- data/spec/history_array_spec.rb +0 -67
- data/spec/hooks_spec.rb +0 -522
- data/spec/indent_spec.rb +0 -301
- data/spec/input_stack_spec.rb +0 -90
- data/spec/method_spec.rb +0 -482
- data/spec/prompt_spec.rb +0 -60
- data/spec/pry_defaults_spec.rb +0 -419
- data/spec/pry_history_spec.rb +0 -99
- data/spec/pry_output_spec.rb +0 -95
- data/spec/pry_spec.rb +0 -515
- data/spec/run_command_spec.rb +0 -25
- data/spec/sticky_locals_spec.rb +0 -157
- data/spec/syntax_checking_spec.rb +0 -81
- data/spec/wrapped_module_spec.rb +0 -261
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
data/spec/run_command_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe "Pry.run_command" do
|
4
|
-
before do
|
5
|
-
o = Object.new
|
6
|
-
def o.drum
|
7
|
-
"roken is dodelijk"
|
8
|
-
end
|
9
|
-
@context = Pry.binding_for(o)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'performs a simple ls' do
|
13
|
-
@context.eval("hokey_pokey = 10")
|
14
|
-
Pry.run_command "ls", :context => @context, :output => out = StringIO.new
|
15
|
-
out.string.should =~ /hokey_pokey/
|
16
|
-
end
|
17
|
-
|
18
|
-
if !PryTestHelpers.mri18_and_no_real_source_location?
|
19
|
-
# This is a regression test as 0.9.11 broke this behaviour
|
20
|
-
it 'can perform a show-source' do
|
21
|
-
Pry.run_command "show-source drum", :context => @context, :output => out = StringIO.new
|
22
|
-
out.string.should =~ /roken is dodelijk/
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/spec/sticky_locals_spec.rb
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe "Sticky locals (_file_ and friends)" do
|
4
|
-
it 'locals should all exist upon initialization' do
|
5
|
-
proc {
|
6
|
-
pry_eval '_file_', '_dir_', '_ex_', '_pry_', '_'
|
7
|
-
}.should.not.raise(NameError)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'locals should still exist after cd-ing into a new context' do
|
11
|
-
proc {
|
12
|
-
pry_eval 'cd 0', '_file_', '_dir_', '_ex_', '_pry_', '_'
|
13
|
-
}.should.not.raise(NameError)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'locals should keep value after cd-ing (_pry_)' do
|
17
|
-
pry_tester.tap do |t|
|
18
|
-
pry = t.eval '_pry_'
|
19
|
-
t.eval 'cd 0'
|
20
|
-
t.eval('_pry_').should == pry
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# Using mock_pry here until we figure out exception handling
|
25
|
-
it 'locals should keep value after cd-ing (_ex_)' do
|
26
|
-
mock_pry("error blah;", "$x = _ex_;", "cd 0", "_ex_ == $x").should =~ /true/
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'locals should keep value after cd-ing (_file_ and _dir_)' do
|
30
|
-
Pry.commands.command "file-and-dir-test" do
|
31
|
-
set_file_and_dir_locals("/blah/ostrich.rb")
|
32
|
-
end
|
33
|
-
|
34
|
-
pry_eval('file-and-dir-test', 'cd 0', '_file_').
|
35
|
-
should =~ /\/blah\/ostrich\.rb/
|
36
|
-
|
37
|
-
pry_eval('file-and-dir-test', 'cd 0', '_dir_').
|
38
|
-
should =~ /\/blah/
|
39
|
-
|
40
|
-
Pry.commands.delete "file-and-dir-test"
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "User defined sticky locals" do
|
44
|
-
describe "setting as Pry.config option" do
|
45
|
-
it 'should define a new sticky local for the session (normal value)' do
|
46
|
-
Pry.config.extra_sticky_locals[:test_local] = :john
|
47
|
-
|
48
|
-
o = Object.new
|
49
|
-
redirect_pry_io(InputTester.new("@value = test_local",
|
50
|
-
"exit-all")) do
|
51
|
-
Pry.start(o)
|
52
|
-
end
|
53
|
-
|
54
|
-
o.instance_variable_get(:@value).should == :john
|
55
|
-
Pry.config.extra_sticky_locals = {}
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should define a new sticky local for the session (proc)' do
|
59
|
-
Pry.config.extra_sticky_locals[:test_local] = proc { :john }
|
60
|
-
|
61
|
-
o = Object.new
|
62
|
-
redirect_pry_io(InputTester.new("@value = test_local",
|
63
|
-
"exit-all")) do
|
64
|
-
Pry.start(o)
|
65
|
-
end
|
66
|
-
|
67
|
-
o.instance_variable_get(:@value).should == :john
|
68
|
-
Pry.config.extra_sticky_locals = {}
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "passing in as hash option when creating pry instance" do
|
74
|
-
it 'should define a new sticky local for the session (normal value)' do
|
75
|
-
o = Object.new
|
76
|
-
redirect_pry_io(InputTester.new("@value = test_local",
|
77
|
-
"exit-all")) do
|
78
|
-
Pry.start(o, :extra_sticky_locals => { :test_local => :john } )
|
79
|
-
end
|
80
|
-
|
81
|
-
o.instance_variable_get(:@value).should == :john
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should define multiple sticky locals' do
|
85
|
-
o = Object.new
|
86
|
-
redirect_pry_io(InputTester.new("@value1 = test_local1",
|
87
|
-
"@value2 = test_local2",
|
88
|
-
"exit-all")) do
|
89
|
-
Pry.start(o, :extra_sticky_locals => { :test_local1 => :john ,
|
90
|
-
:test_local2 => :carl} )
|
91
|
-
end
|
92
|
-
|
93
|
-
o.instance_variable_get(:@value1).should == :john
|
94
|
-
o.instance_variable_get(:@value2).should == :carl
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
it 'should define a new sticky local for the session (as Proc)' do
|
99
|
-
o = Object.new
|
100
|
-
redirect_pry_io(InputTester.new("@value = test_local",
|
101
|
-
"exit-all")) do
|
102
|
-
Pry.start(o, :extra_sticky_locals => { :test_local => proc { :john }} )
|
103
|
-
end
|
104
|
-
|
105
|
-
o.instance_variable_get(:@value).should == :john
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "hash option value should override config value" do
|
110
|
-
it 'should define a new sticky local for the session (normal value)' do
|
111
|
-
Pry.config.extra_sticky_locals[:test_local] = :john
|
112
|
-
|
113
|
-
o = Object.new
|
114
|
-
redirect_pry_io(InputTester.new("@value = test_local",
|
115
|
-
"exit-all")) do
|
116
|
-
Pry.start(o, :extra_sticky_locals => { :test_local => :carl })
|
117
|
-
end
|
118
|
-
|
119
|
-
o.instance_variable_get(:@value).should == :carl
|
120
|
-
Pry.config.extra_sticky_locals = {}
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should create a new sticky local' do
|
125
|
-
o = Object.new
|
126
|
-
pi = Pry.new
|
127
|
-
pi.add_sticky_local(:test_local) { :test_value }
|
128
|
-
pi.input, pi.output = InputTester.new("@value = test_local", "exit-all"), StringIO.new
|
129
|
-
pi.repl(o)
|
130
|
-
|
131
|
-
o.instance_variable_get(:@value).should == :test_value
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'should still exist after cd-ing into new binding' do
|
135
|
-
o = Object.new
|
136
|
-
o2 = Object.new
|
137
|
-
o.instance_variable_set(:@o2, o2)
|
138
|
-
pi = Pry.new
|
139
|
-
pi.add_sticky_local(:test_local) { :test_value }
|
140
|
-
pi.input = InputTester.new("cd @o2\n",
|
141
|
-
"@value = test_local", "exit-all")
|
142
|
-
pi.output = StringIO.new
|
143
|
-
pi.repl(o)
|
144
|
-
|
145
|
-
o2.instance_variable_get(:@value).should == :test_value
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'should provide different values for successive block invocations' do
|
149
|
-
pry = Pry.new
|
150
|
-
pry.add_sticky_local(:test_local) { rand }
|
151
|
-
value1 = pry.evaluate_ruby 'test_local'
|
152
|
-
value2 = pry.evaluate_ruby 'test_local'
|
153
|
-
value1.should.not == value2
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Pry do
|
4
|
-
before do
|
5
|
-
@str_output = StringIO.new
|
6
|
-
end
|
7
|
-
|
8
|
-
[
|
9
|
-
["p = '", "'"],
|
10
|
-
["def", "a", "(); end"],
|
11
|
-
["p = <<FOO", "lots", "and", "lots of", "foo", "FOO"],
|
12
|
-
["[", ":lets,", "'list',", "[/nested/", "], things ]"],
|
13
|
-
["abc =~ /hello", "/"],
|
14
|
-
["issue = %W/", "343/"],
|
15
|
-
["pouts(<<HI, 'foo", "bar", "HI", "baz')"],
|
16
|
-
].each do |foo|
|
17
|
-
it "should not raise an error on broken lines: #{foo.join("\\n")}" do
|
18
|
-
redirect_pry_io(InputTester.new(*foo), @str_output) do
|
19
|
-
Pry.start
|
20
|
-
end
|
21
|
-
|
22
|
-
@str_output.string.should.not =~ /SyntaxError/
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
[
|
27
|
-
["end"],
|
28
|
-
["puts )("],
|
29
|
-
["1 1"],
|
30
|
-
["puts :"]
|
31
|
-
] + (Pry::Helpers::BaseHelpers.rbx? ? [] : [
|
32
|
-
["def", "method(1"], # in this case the syntax error is "expecting ')'".
|
33
|
-
["o = Object.new.tap{ def o.render;","'MEH'", "}"] # in this case the syntax error is "expecting keyword_end".
|
34
|
-
]).compact.each do |foo|
|
35
|
-
it "should raise an error on invalid syntax like #{foo.inspect}" do
|
36
|
-
redirect_pry_io(InputTester.new(*foo), @str_output) do
|
37
|
-
Pry.start
|
38
|
-
end
|
39
|
-
|
40
|
-
@str_output.string.should =~ /SyntaxError/
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should not intefere with syntax errors explicitly raised" do
|
45
|
-
redirect_pry_io(InputTester.new(%q{raise SyntaxError, "unexpected $end"}), @str_output) do
|
46
|
-
Pry.start
|
47
|
-
end
|
48
|
-
|
49
|
-
@str_output.string.should =~ /SyntaxError/
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should allow trailing , to continue the line" do
|
53
|
-
pry = Pry.new
|
54
|
-
Pry::Code.complete_expression?("puts 1, 2,").should == false
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should complete an expression that contains a line ending with a ," do
|
58
|
-
pry = Pry.new
|
59
|
-
Pry::Code.complete_expression?("puts 1, 2,\n3").should == true
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should not suppress the error output if the line ends in ;" do
|
63
|
-
mock_pry("raise RuntimeError, 'foo';").should =~ /RuntimeError/
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should not clobber _ex_ on a SyntaxError in the repl" do
|
67
|
-
mock_pry("raise RuntimeError, 'foo'", "puts foo)", "_ex_.is_a?(RuntimeError)").should =~ /^RuntimeError.*\nSyntaxError.*\n=> true/m
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should allow whitespace delimeted strings" do
|
71
|
-
mock_pry('"%s" %% foo ').should =~ /"foo"/
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should allow newline delimeted strings" do
|
75
|
-
mock_pry('"%s" %%','foo').should =~ /"foo"/
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should allow whitespace delimeted strings ending on the first char of a line" do
|
79
|
-
mock_pry('"%s" %% ', ' #done!').should =~ /"\\n"/
|
80
|
-
end
|
81
|
-
end
|
data/spec/wrapped_module_spec.rb
DELETED
@@ -1,261 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Pry::WrappedModule do
|
4
|
-
|
5
|
-
describe "#initialize" do
|
6
|
-
it "should raise an exception when a non-module is passed" do
|
7
|
-
lambda{ Pry::WrappedModule.new(nil) }.should.raise ArgumentError
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "candidates" do
|
12
|
-
before do
|
13
|
-
class Host
|
14
|
-
%w(spec/fixtures/candidate_helper1.rb
|
15
|
-
spec/fixtures/candidate_helper2.rb).each do |file|
|
16
|
-
binding.eval File.read(file), file, 1
|
17
|
-
end
|
18
|
-
|
19
|
-
# rank 2
|
20
|
-
class CandidateTest
|
21
|
-
def test6
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class ForeverAlone
|
26
|
-
class DoublyNested
|
27
|
-
# nested docs
|
28
|
-
class TriplyNested
|
29
|
-
def nested_method
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "number_of_candidates" do
|
38
|
-
it 'should return the correct number of candidates' do
|
39
|
-
Pry::WrappedModule(Host::CandidateTest).number_of_candidates.should == 3
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should return 0 candidates for a class with no methods and no other definitions' do
|
43
|
-
Pry::WrappedModule(Host::ForeverAlone).number_of_candidates.should == 0
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "ordering of candidates" do
|
48
|
-
it 'should return class with largest number of methods as primary candidate' do
|
49
|
-
Pry::WrappedModule(Host::CandidateTest).candidate(0).file.should =~ /helper1/
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should return class with second largest number of methods as second ranked candidate' do
|
53
|
-
Pry::WrappedModule(Host::CandidateTest).candidate(1).file.should =~ /helper2/
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should return class with third largest number of methods as third ranked candidate' do
|
57
|
-
Pry::WrappedModule(Host::CandidateTest).candidate(2).file.should =~ /#{__FILE__}/
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should raise when trying to access non-existent candidate' do
|
61
|
-
lambda { Pry::WrappedModule(Host::CandidateTest).candidate(3) }.should.raise Pry::CommandError
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "source_location" do
|
66
|
-
it 'should return primary candidates source_location by default' do
|
67
|
-
wm = Pry::WrappedModule(Host::CandidateTest)
|
68
|
-
wm.source_location.should == wm.candidate(0).source_location
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should return nil if no source_location can be found' do
|
72
|
-
Pry::WrappedModule(Host::ForeverAlone).source_location.should == nil
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "source" do
|
77
|
-
it 'should return primary candidates source by default' do
|
78
|
-
wm = Pry::WrappedModule(Host::CandidateTest)
|
79
|
-
wm.source.should == wm.candidate(0).source
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should return source for highest ranked candidate' do
|
83
|
-
Pry::WrappedModule(Host::CandidateTest).candidate(0).source.should =~ /test1/
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should return source for second ranked candidate' do
|
87
|
-
Pry::WrappedModule(Host::CandidateTest).candidate(1).source.should =~ /test4/
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should return source for third ranked candidate' do
|
91
|
-
Pry::WrappedModule(Host::CandidateTest).candidate(2).source.should =~ /test6/
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should return source for deeply nested class' do
|
95
|
-
Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source.should =~ /nested_method/
|
96
|
-
Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source.lines.count.should == 4
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "doc" do
|
101
|
-
it 'should return primary candidates doc by default' do
|
102
|
-
wm = Pry::WrappedModule(Host::CandidateTest)
|
103
|
-
wm.doc.should == wm.candidate(0).doc
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'should return doc for highest ranked candidate' do
|
107
|
-
Pry::WrappedModule(Host::CandidateTest).candidate(0).doc.should =~ /rank 0/
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should return doc for second ranked candidate' do
|
111
|
-
Pry::WrappedModule(Host::CandidateTest).candidate(1).doc.should =~ /rank 1/
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'should return doc for third ranked candidate' do
|
115
|
-
Pry::WrappedModule(Host::CandidateTest).candidate(2).doc.should =~ /rank 2/
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'should return docs for deeply nested class' do
|
119
|
-
Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).doc.should =~ /nested docs/
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
after do
|
124
|
-
Object.remove_const(:Host)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe ".method_prefix" do
|
129
|
-
before do
|
130
|
-
Foo = Class.new
|
131
|
-
@foo = Foo.new
|
132
|
-
end
|
133
|
-
|
134
|
-
after do
|
135
|
-
Object.remove_const(:Foo)
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should return Foo# for normal classes" do
|
139
|
-
Pry::WrappedModule.new(Foo).method_prefix.should == "Foo#"
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should return Bar# for modules" do
|
143
|
-
Pry::WrappedModule.new(Kernel).method_prefix.should == "Kernel#"
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should return Foo. for singleton classes of classes" do
|
147
|
-
Pry::WrappedModule.new(class << Foo; self; end).method_prefix.should == "Foo."
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "of singleton classes of objects" do
|
151
|
-
Pry::WrappedModule.new(class << @foo; self; end).method_prefix.should == "self."
|
152
|
-
end
|
153
|
-
|
154
|
-
describe "of anonymous classes should not be empty" do
|
155
|
-
Pry::WrappedModule.new(Class.new).method_prefix.should =~ /#<Class:.*>#/
|
156
|
-
end
|
157
|
-
|
158
|
-
describe "of singleton classes of anonymous classes should not be empty" do
|
159
|
-
Pry::WrappedModule.new(class << Class.new; self; end).method_prefix.should =~ /#<Class:.*>./
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe ".singleton_class?" do
|
164
|
-
it "should be true for singleton classes" do
|
165
|
-
Pry::WrappedModule.new(class << ""; self; end).singleton_class?.should == true
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should be false for normal classes" do
|
169
|
-
Pry::WrappedModule.new(Class.new).singleton_class?.should == false
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should be false for modules" do
|
173
|
-
Pry::WrappedModule.new(Module.new).singleton_class?.should == false
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
describe ".singleton_instance" do
|
178
|
-
it "should raise an exception when called on a non-singleton-class" do
|
179
|
-
lambda{ Pry::WrappedModule.new(Class).singleton_instance }.should.raise ArgumentError
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should return the attached object" do
|
183
|
-
Pry::WrappedModule.new(class << "hi"; self; end).singleton_instance.should == "hi"
|
184
|
-
Pry::WrappedModule.new(class << Object; self; end).singleton_instance.should.equal?(Object)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe ".super" do
|
189
|
-
describe "receiver is a class" do
|
190
|
-
before do
|
191
|
-
@a = Class.new
|
192
|
-
@m = Module.new
|
193
|
-
@b = Class.new(@a)
|
194
|
-
@b.send(:include, @m)
|
195
|
-
@c = Class.new(@b)
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'should return superclass for a wrapped class' do
|
199
|
-
Pry::WrappedModule(@c).super.wrapped.should == @b
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'should return nth superclass for a wrapped class' do
|
203
|
-
d = Class.new(@c)
|
204
|
-
Pry::WrappedModule(d).super(2).wrapped.should == @b
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'should ignore modules when retrieving nth superclass' do
|
208
|
-
Pry::WrappedModule(@c).super(2).wrapped.should == @a
|
209
|
-
end
|
210
|
-
|
211
|
-
it 'should return nil when no nth superclass exists' do
|
212
|
-
Pry::WrappedModule(@c).super(10).should == nil
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'should return self when .super(0) is used' do
|
216
|
-
c = Pry::WrappedModule(@c)
|
217
|
-
c.super(0).should == c
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
describe "receiver is a module" do
|
222
|
-
before do
|
223
|
-
@m1 = Module.new
|
224
|
-
@m2 = Module.new.tap { |v| v.send(:include, @m1) }
|
225
|
-
@m3 = Module.new.tap { |v| v.send(:include, @m2) }
|
226
|
-
end
|
227
|
-
|
228
|
-
it 'should not ignore modules when retrieving supers' do
|
229
|
-
Pry::WrappedModule(@m3).super.wrapped.should == @m2
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'should retrieve nth super' do
|
233
|
-
Pry::WrappedModule(@m3).super(2).wrapped.should == @m1
|
234
|
-
end
|
235
|
-
|
236
|
-
it 'should return self when .super(0) is used' do
|
237
|
-
m = Pry::WrappedModule(@m1)
|
238
|
-
m.super(0).should == m
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
describe ".from_str" do
|
244
|
-
it 'should lookup a constant' do
|
245
|
-
m = Pry::WrappedModule.from_str("Host::CandidateTest", binding)
|
246
|
-
m.wrapped.should == Host::CandidateTest
|
247
|
-
end
|
248
|
-
|
249
|
-
it 'should lookup a local' do
|
250
|
-
local = Host::CandidateTest
|
251
|
-
m = Pry::WrappedModule.from_str("local", binding)
|
252
|
-
m.wrapped.should == Host::CandidateTest
|
253
|
-
end
|
254
|
-
|
255
|
-
it 'should lookup an ivar' do
|
256
|
-
@ivar = Host::CandidateTest
|
257
|
-
m = Pry::WrappedModule.from_str("@ivar", binding)
|
258
|
-
m.wrapped.should == Host::CandidateTest
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|