pry 0.9.12.6-i386-mswin32 → 0.10.0-i386-mswin32
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 +19 -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 +6 -7
- data/lib/pry/commands/cat/file_formatter.rb +15 -32
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- 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 +193 -48
- 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 +62 -225
- 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/pry.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/pry/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name = "pry"
|
6
|
-
s.version = Pry::VERSION
|
7
|
-
|
8
|
-
s.authors = ["John Mair (banisterfiend)", "Conrad Irwin", "Ryan Fitzgerald"]
|
9
|
-
s.email = ["jrmair@gmail.com", "conrad.irwin@gmail.com", "rwfitzge@gmail.com"]
|
10
|
-
s.summary = "An IRB alternative and runtime developer console"
|
11
|
-
s.description = s.summary
|
12
|
-
s.homepage = "http://pry.github.com"
|
13
|
-
|
14
|
-
s.executables = ["pry"]
|
15
|
-
s.require_paths = ["lib"]
|
16
|
-
s.files = `git ls-files`.split("\n")
|
17
|
-
s.test_files = `git ls-files -- spec/*`.split("\n")
|
18
|
-
|
19
|
-
s.add_dependency 'coderay', '~> 1.0'
|
20
|
-
s.add_dependency 'slop', '~> 3.4'
|
21
|
-
s.add_dependency 'method_source', '~> 0.8'
|
22
|
-
|
23
|
-
s.add_development_dependency 'bacon', '~> 1.2'
|
24
|
-
s.add_development_dependency 'open4', '~> 1.3'
|
25
|
-
s.add_development_dependency 'rake', '~> 0.9'
|
26
|
-
s.add_development_dependency 'mocha', '~> 0.13.1'
|
27
|
-
# TODO: make this a plain dependency:
|
28
|
-
s.add_development_dependency 'bond', '~> 0.4.2'
|
29
|
-
end
|
data/spec/Procfile
DELETED
data/spec/cli_spec.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Pry::Hooks do
|
4
|
-
before do
|
5
|
-
Pry::CLI.reset
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "parsing options" do
|
9
|
-
it 'should raise if no options defined' do
|
10
|
-
lambda { Pry::CLI.parse_options(["--nothing"]) }.should.raise Pry::CLI::NoOptionsError
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "adding options" do
|
15
|
-
it "should be able to add an option" do
|
16
|
-
run = false
|
17
|
-
|
18
|
-
Pry::CLI.add_options do
|
19
|
-
on :optiontest, "A test option" do
|
20
|
-
run = true
|
21
|
-
end
|
22
|
-
end.parse_options(["--optiontest"])
|
23
|
-
|
24
|
-
run.should == true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should be able to add multiple options" do
|
28
|
-
run = false
|
29
|
-
run2 = false
|
30
|
-
|
31
|
-
Pry::CLI.add_options do
|
32
|
-
on :optiontest, "A test option" do
|
33
|
-
run = true
|
34
|
-
end
|
35
|
-
end.add_options do
|
36
|
-
on :optiontest2, "Another test option" do
|
37
|
-
run2 = true
|
38
|
-
end
|
39
|
-
end.parse_options(["--optiontest", "--optiontest2"])
|
40
|
-
|
41
|
-
run.should == true
|
42
|
-
run2.should == true
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "processing options" do
|
48
|
-
it "should be able to process an option" do
|
49
|
-
run = false
|
50
|
-
|
51
|
-
Pry::CLI.add_options do
|
52
|
-
on :optiontest, "A test option"
|
53
|
-
end.process_options do |opts|
|
54
|
-
run = true if opts.present?(:optiontest)
|
55
|
-
end.parse_options(["--optiontest"])
|
56
|
-
|
57
|
-
run.should == true
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should be able to process multiple options" do
|
61
|
-
run = false
|
62
|
-
run2 = false
|
63
|
-
|
64
|
-
Pry::CLI.add_options do
|
65
|
-
on :optiontest, "A test option"
|
66
|
-
on :optiontest2, "Another test option"
|
67
|
-
end.process_options do |opts|
|
68
|
-
run = true if opts.present?(:optiontest)
|
69
|
-
end.process_options do |opts|
|
70
|
-
run2 = true if opts.present?(:optiontest2)
|
71
|
-
end.parse_options(["--optiontest", "--optiontest2"])
|
72
|
-
|
73
|
-
run.should == true
|
74
|
-
run2.should == true
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
data/spec/code_object_spec.rb
DELETED
@@ -1,277 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Pry::CodeObject do
|
4
|
-
describe "basic lookups" do
|
5
|
-
before do
|
6
|
-
@obj = Object.new
|
7
|
-
def @obj.ziggy
|
8
|
-
"a flight of scarlet pigeons thunders round my thoughts"
|
9
|
-
end
|
10
|
-
|
11
|
-
class ClassyWassy
|
12
|
-
def piggy
|
13
|
-
binding
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
@p = Pry.new
|
18
|
-
@p.binding_stack = [binding]
|
19
|
-
end
|
20
|
-
|
21
|
-
after do
|
22
|
-
Object.remove_const(:ClassyWassy)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should lookup methods' do
|
26
|
-
m = Pry::CodeObject.lookup("@obj.ziggy", @p)
|
27
|
-
m.is_a?(Pry::Method).should == true
|
28
|
-
m.name.to_sym.should == :ziggy
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should lookup modules' do
|
32
|
-
m = Pry::CodeObject.lookup("ClassyWassy", @p)
|
33
|
-
m.is_a?(Pry::WrappedModule).should == true
|
34
|
-
m.source.should =~ /piggy/
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should lookup procs' do
|
38
|
-
my_proc = proc { :hello }
|
39
|
-
@p.binding_stack = [binding]
|
40
|
-
m = Pry::CodeObject.lookup("my_proc", @p)
|
41
|
-
m.is_a?(Pry::Method).should == true
|
42
|
-
m.source.should =~ /hello/
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'commands lookup' do
|
46
|
-
before do
|
47
|
-
@p = Pry.new
|
48
|
-
@p.binding_stack = [binding]
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should return command class' do
|
52
|
-
@p.commands.command "jeremy-jones" do
|
53
|
-
"lobster"
|
54
|
-
end
|
55
|
-
m = Pry::CodeObject.lookup("jeremy-jones", @p)
|
56
|
-
(m <= Pry::Command).should == true
|
57
|
-
m.source.should =~ /lobster/
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "class commands" do
|
61
|
-
before do
|
62
|
-
class LobsterLady < Pry::ClassCommand
|
63
|
-
match "lobster-lady"
|
64
|
-
description "nada."
|
65
|
-
def process
|
66
|
-
"lobster"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
after do
|
72
|
-
Object.remove_const(:LobsterLady)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'should return Pry::ClassCommand class when looking up class command' do
|
76
|
-
Pry.commands.add_command(LobsterLady)
|
77
|
-
m = Pry::CodeObject.lookup("lobster-lady", @p)
|
78
|
-
(m <= Pry::ClassCommand).should == true
|
79
|
-
m.source.should =~ /class LobsterLady/
|
80
|
-
Pry.commands.delete("lobster-lady")
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should return Pry::WrappedModule when looking up command class directly (as a class, not as a command)' do
|
84
|
-
Pry.commands.add_command(LobsterLady)
|
85
|
-
m = Pry::CodeObject.lookup("LobsterLady", @p)
|
86
|
-
m.is_a?(Pry::WrappedModule).should == true
|
87
|
-
m.source.should =~ /class LobsterLady/
|
88
|
-
Pry.commands.delete("lobster-lady")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'looks up commands by :listing name as well' do
|
93
|
-
@p.commands.command /jeremy-.*/, "", :listing => "jeremy-baby" do
|
94
|
-
"lobster"
|
95
|
-
end
|
96
|
-
m = Pry::CodeObject.lookup("jeremy-baby", @p)
|
97
|
-
(m <= Pry::Command).should == true
|
98
|
-
m.source.should =~ /lobster/
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'finds nothing when passing nil as the first argument' do
|
102
|
-
Pry::CodeObject.lookup(nil, @p).should == nil
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'should lookup instance methods defined on classes accessed via local variable' do
|
108
|
-
o = Class.new do
|
109
|
-
def princess_bubblegum
|
110
|
-
"mathematic!"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
@p.binding_stack = [binding]
|
115
|
-
m = Pry::CodeObject.lookup("o#princess_bubblegum", @p)
|
116
|
-
m.is_a?(Pry::Method).should == true
|
117
|
-
m.source.should =~ /mathematic!/
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'should lookup class methods defined on classes accessed via local variable' do
|
121
|
-
o = Class.new do
|
122
|
-
def self.finn
|
123
|
-
"4 realzies"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
@p.binding_stack = [binding]
|
127
|
-
m = Pry::CodeObject.lookup("o.finn", @p)
|
128
|
-
m.is_a?(Pry::Method).should == true
|
129
|
-
m.source.should =~ /4 realzies/
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'should lookup the class of an object (when given a variable)' do
|
133
|
-
moddy = ClassyWassy.new
|
134
|
-
@p.binding_stack = [binding]
|
135
|
-
m = Pry::CodeObject.lookup("moddy", @p)
|
136
|
-
m.is_a?(Pry::WrappedModule).should == true
|
137
|
-
m.source.should =~ /piggy/
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "inferring object from binding when lookup str is empty/nil" do
|
141
|
-
before do
|
142
|
-
@b1 = Pry.binding_for(ClassyWassy)
|
143
|
-
@b2 = Pry.binding_for(ClassyWassy.new)
|
144
|
-
end
|
145
|
-
|
146
|
-
describe "infer module objects" do
|
147
|
-
it 'should infer module object when binding self is a module' do
|
148
|
-
["", nil].each do |v|
|
149
|
-
@p.binding_stack = [@b1]
|
150
|
-
m = Pry::CodeObject.lookup(v, @p)
|
151
|
-
m.is_a?(Pry::WrappedModule).should == true
|
152
|
-
m.name.should =~ /ClassyWassy/
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'should infer module object when binding self is an instance' do
|
157
|
-
["", nil].each do |v|
|
158
|
-
@p.binding_stack = [@b2]
|
159
|
-
m = Pry::CodeObject.lookup(v, @p)
|
160
|
-
m.is_a?(Pry::WrappedModule).should == true
|
161
|
-
m.name.should =~ /ClassyWassy/
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe "infer method objects" do
|
167
|
-
it 'should infer method object from binding when inside method context' do
|
168
|
-
b = ClassyWassy.new.piggy
|
169
|
-
|
170
|
-
["", nil].each do |v|
|
171
|
-
@p.binding_stack = [b]
|
172
|
-
m = Pry::CodeObject.lookup(v, @p)
|
173
|
-
m.is_a?(Pry::Method).should == true
|
174
|
-
m.name.should =~ /piggy/
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
describe "lookups with :super" do
|
182
|
-
before do
|
183
|
-
class MyClassyWassy; end
|
184
|
-
class CuteSubclass < MyClassyWassy; end
|
185
|
-
@p = Pry.new
|
186
|
-
@p.binding_stack = [binding]
|
187
|
-
end
|
188
|
-
|
189
|
-
after do
|
190
|
-
Object.remove_const(:MyClassyWassy)
|
191
|
-
Object.remove_const(:CuteSubclass)
|
192
|
-
end
|
193
|
-
|
194
|
-
it 'should lookup original class with :super => 0' do
|
195
|
-
m = Pry::CodeObject.lookup("CuteSubclass", @p, :super => 0)
|
196
|
-
m.is_a?(Pry::WrappedModule).should == true
|
197
|
-
m.wrapped.should == CuteSubclass
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'should lookup immediate super class with :super => 1' do
|
201
|
-
m = Pry::CodeObject.lookup("CuteSubclass", @p, :super => 1)
|
202
|
-
m.is_a?(Pry::WrappedModule).should == true
|
203
|
-
m.wrapped.should == MyClassyWassy
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'should ignore :super parameter for commands' do
|
207
|
-
p = Pry.new
|
208
|
-
p.commands.command "jeremy-jones" do
|
209
|
-
"lobster"
|
210
|
-
end
|
211
|
-
p.binding_stack = [binding]
|
212
|
-
m = Pry::CodeObject.lookup("jeremy-jones", p, :super => 10)
|
213
|
-
m.source.should =~ /lobster/
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
describe "precedence" do
|
218
|
-
before do
|
219
|
-
class ClassyWassy
|
220
|
-
class Puff
|
221
|
-
def tiggy
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def Puff
|
226
|
-
end
|
227
|
-
|
228
|
-
def piggy
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
Object.class_eval do
|
233
|
-
def ClassyWassy
|
234
|
-
:ducky
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
@p = Pry.new
|
239
|
-
@p.binding_stack = [binding]
|
240
|
-
end
|
241
|
-
|
242
|
-
after do
|
243
|
-
Object.remove_const(:ClassyWassy)
|
244
|
-
Object.remove_method(:ClassyWassy)
|
245
|
-
end
|
246
|
-
|
247
|
-
it 'should look up methods before classes (at top-level)' do
|
248
|
-
m = Pry::CodeObject.lookup("ClassyWassy", @p)
|
249
|
-
m.is_a?(Pry::Method).should == true
|
250
|
-
m.source.should =~ /ducky/
|
251
|
-
end
|
252
|
-
|
253
|
-
it 'should look up classes before methods when namespaced' do
|
254
|
-
m = Pry::CodeObject.lookup("ClassyWassy::Puff", @p)
|
255
|
-
m.is_a?(Pry::WrappedModule).should == true
|
256
|
-
m.source.should =~ /tiggy/
|
257
|
-
end
|
258
|
-
|
259
|
-
it 'should look up locals before methods' do
|
260
|
-
b = Pry.binding_for(ClassyWassy)
|
261
|
-
b.eval("piggy = Puff.new")
|
262
|
-
@p.binding_stack = [b]
|
263
|
-
o = Pry::CodeObject.lookup("piggy", @p)
|
264
|
-
o.is_a?(Pry::WrappedModule).should == true
|
265
|
-
end
|
266
|
-
|
267
|
-
# actually locals are never looked up (via co.default_lookup) when they're classes, it
|
268
|
-
# just falls through to co.method_or_class
|
269
|
-
it 'should look up classes before locals' do
|
270
|
-
c = ClassyWassy
|
271
|
-
@p.binding_stack = [binding]
|
272
|
-
o = Pry::CodeObject.lookup("c", @p)
|
273
|
-
o.is_a?(Pry::WrappedModule).should == true
|
274
|
-
o.wrapped.should == ClassyWassy
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
data/spec/code_spec.rb
DELETED
@@ -1,219 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Pry::Code do
|
4
|
-
describe '.from_file' do
|
5
|
-
should 'read lines from a file on disk' do
|
6
|
-
Pry::Code.from_file('lib/pry.rb').length.should > 0
|
7
|
-
end
|
8
|
-
|
9
|
-
should 'read lines from Pry\'s line buffer' do
|
10
|
-
pry_eval ':hay_guys'
|
11
|
-
Pry::Code.from_file('(pry)').grep(/:hay_guys/).length.should == 1
|
12
|
-
end
|
13
|
-
|
14
|
-
should 'default to Ruby' do
|
15
|
-
temp_file('') do |f|
|
16
|
-
Pry::Code.from_file(f.path).code_type.should == :ruby
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
should 'check the extension' do
|
21
|
-
temp_file('.c') do |f|
|
22
|
-
Pry::Code.from_file(f.path).code_type.should == :c
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
should 'use the provided extension' do
|
27
|
-
temp_file('.c') do |f|
|
28
|
-
Pry::Code.from_file(f.path, :ruby).code_type.should == :ruby
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
should 'raise an error if the file doesn\'t exist' do
|
33
|
-
proc do
|
34
|
-
Pry::Code.from_file('/knalkjsdnalsd/alkjdlkq')
|
35
|
-
end.should.raise(MethodSource::SourceNotFoundError)
|
36
|
-
end
|
37
|
-
|
38
|
-
should 'check for files relative to origin pwd' do
|
39
|
-
Dir.chdir('spec') do |f|
|
40
|
-
Pry::Code.from_file('spec/' + File.basename(__FILE__)).code_type.should == :ruby
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
should 'find files that are relative to the current working directory' do
|
45
|
-
Dir.chdir('spec') do |f|
|
46
|
-
Pry::Code.from_file(File.basename(__FILE__)).code_type.should == :ruby
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '.from_method' do
|
52
|
-
should 'read lines from a method\'s definition' do
|
53
|
-
m = Pry::Method.from_obj(Pry, :load_history)
|
54
|
-
Pry::Code.from_method(m).length.should > 0
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#initialize' do
|
59
|
-
before do
|
60
|
-
@str = Pry::Helpers::CommandHelpers.unindent <<-CODE
|
61
|
-
def hay
|
62
|
-
:guys
|
63
|
-
end
|
64
|
-
CODE
|
65
|
-
|
66
|
-
@array = ['def hay', ' :guys', 'end']
|
67
|
-
end
|
68
|
-
|
69
|
-
should 'break a string into lines' do
|
70
|
-
Pry::Code.new(@str).length.should == 3
|
71
|
-
end
|
72
|
-
|
73
|
-
should 'accept an array' do
|
74
|
-
Pry::Code.new(@array).length.should == 3
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'an array or string should produce an equivalent object' do
|
78
|
-
Pry::Code.new(@str).should == Pry::Code.new(@array)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe 'filters and formatters' do
|
83
|
-
before do
|
84
|
-
@code = Pry::Code(Pry::Helpers::CommandHelpers.unindent <<-STR)
|
85
|
-
class MyProgram
|
86
|
-
def self.main
|
87
|
-
puts 'Hello, world!'
|
88
|
-
end
|
89
|
-
end
|
90
|
-
STR
|
91
|
-
end
|
92
|
-
|
93
|
-
describe 'filters' do
|
94
|
-
describe '#between' do
|
95
|
-
should 'work with an inclusive range' do
|
96
|
-
@code = @code.between(1..3)
|
97
|
-
@code.length.should == 3
|
98
|
-
@code.should =~ /\Aclass MyProgram/
|
99
|
-
@code.should =~ /world!'\Z/
|
100
|
-
end
|
101
|
-
|
102
|
-
should 'default to an inclusive range' do
|
103
|
-
@code = @code.between(3, 5)
|
104
|
-
@code.length.should == 3
|
105
|
-
end
|
106
|
-
|
107
|
-
should 'work with an exclusive range' do
|
108
|
-
@code = @code.between(2...4)
|
109
|
-
@code.length.should == 2
|
110
|
-
@code.should =~ /\A def self/
|
111
|
-
@code.should =~ /world!'\Z/
|
112
|
-
end
|
113
|
-
|
114
|
-
should 'use real line numbers for positive indices' do
|
115
|
-
@code = @code.after(3, 3)
|
116
|
-
@code = @code.between(4, 4)
|
117
|
-
@code.length.should == 1
|
118
|
-
@code.should =~ /\A end\Z/
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe '#before' do
|
123
|
-
should 'work' do
|
124
|
-
@code = @code.before(3, 1)
|
125
|
-
@code.should =~ /\A def self\.main\Z/
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe '#around' do
|
130
|
-
should 'work' do
|
131
|
-
@code = @code.around(3, 1)
|
132
|
-
@code.length.should == 3
|
133
|
-
@code.should =~ /\A def self/
|
134
|
-
@code.should =~ / end\Z/
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe '#after' do
|
139
|
-
should 'work' do
|
140
|
-
@code = @code.after(3, 1)
|
141
|
-
@code.should =~ /\A end\Z/
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe '#grep' do
|
146
|
-
should 'work' do
|
147
|
-
@code = @code.grep(/end/)
|
148
|
-
@code.length.should == 2
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe 'formatters' do
|
154
|
-
describe '#with_line_numbers' do
|
155
|
-
should 'show line numbers' do
|
156
|
-
@code = @code.with_line_numbers
|
157
|
-
@code.should =~ /1:/
|
158
|
-
end
|
159
|
-
|
160
|
-
should 'disable line numbers when falsy' do
|
161
|
-
@code = @code.with_line_numbers
|
162
|
-
@code = @code.with_line_numbers(false)
|
163
|
-
@code.should.not =~ /1:/
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe '#with_marker' do
|
168
|
-
should 'show a marker in the right place' do
|
169
|
-
@code = @code.with_marker(2)
|
170
|
-
@code.should =~ /^ => def self/
|
171
|
-
end
|
172
|
-
|
173
|
-
should 'disable the marker when falsy' do
|
174
|
-
@code = @code.with_marker(2)
|
175
|
-
@code = @code.with_marker(false)
|
176
|
-
@code.should =~ /^ def self/
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
describe '#with_indentation' do
|
181
|
-
should 'indent the text' do
|
182
|
-
@code = @code.with_indentation(2)
|
183
|
-
@code.should =~ /^ def self/
|
184
|
-
end
|
185
|
-
|
186
|
-
should 'disable the indentation when falsy' do
|
187
|
-
@code = @code.with_indentation(2)
|
188
|
-
@code = @code.with_indentation(false)
|
189
|
-
@code.should =~ /^ def self/
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
describe 'composition' do
|
195
|
-
describe 'grep and with_line_numbers' do
|
196
|
-
should 'work' do
|
197
|
-
@code = @code.grep(/end/).with_line_numbers
|
198
|
-
@code.should =~ /\A4: end/
|
199
|
-
@code.should =~ /5: end\Z/
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
describe 'grep and before and with_line_numbers' do
|
204
|
-
should 'work' do
|
205
|
-
@code = @code.grep(/e/).before(5, 5).with_line_numbers
|
206
|
-
@code.should =~ /\A2: def self.main\n3:/
|
207
|
-
@code.should =~ /4: end\Z/
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
describe 'before and after' do
|
212
|
-
should 'work' do
|
213
|
-
@code = @code.before(4, 2).after(2)
|
214
|
-
@code.should == " puts 'Hello, world!'"
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|