pry 0.9.8pre3 → 0.9.8pre4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pry/cli.rb +1 -1
- data/lib/pry/command.rb +34 -9
- data/lib/pry/command_set.rb +5 -3
- data/lib/pry/default_commands/context.rb +1 -4
- data/lib/pry/default_commands/documentation.rb +15 -10
- data/lib/pry/default_commands/input.rb +1 -1
- data/lib/pry/extended_commands/user_command_api.rb +84 -27
- data/lib/pry/hooks.rb +56 -1
- data/lib/pry/method.rb +12 -0
- data/lib/pry/pry_instance.rb +10 -10
- data/lib/pry/version.rb +1 -1
- data/pry.gemspec +2 -2
- data/test/test_default_commands/test_context.rb +9 -2
- data/test/test_hooks.rb +119 -0
- data/test/test_syntax_checking.rb +11 -0
- metadata +2 -2
data/lib/pry/cli.rb
CHANGED
@@ -14,7 +14,7 @@ class Pry
|
|
14
14
|
# @return [Array] The Procs that process the parsed options.
|
15
15
|
attr_accessor :option_processors
|
16
16
|
|
17
|
-
# Add another set of CLI options
|
17
|
+
# Add another set of CLI options (a Slop block)
|
18
18
|
def add_options(&block)
|
19
19
|
if options
|
20
20
|
old_options = options
|
data/lib/pry/command.rb
CHANGED
@@ -14,12 +14,34 @@ class Pry
|
|
14
14
|
# Properties of the command itself (as passed as arguments to
|
15
15
|
# {CommandSet#command} or {CommandSet#command_class}).
|
16
16
|
class << self
|
17
|
+
attr_accessor :block
|
17
18
|
attr_accessor :name
|
18
19
|
attr_accessor :description
|
19
|
-
attr_accessor :
|
20
|
-
|
20
|
+
attr_accessor :command_options
|
21
|
+
|
22
|
+
# Define or get the command's description
|
23
|
+
def description(arg=nil)
|
24
|
+
@description = arg if arg
|
25
|
+
@description
|
26
|
+
end
|
27
|
+
|
28
|
+
# Define or get the command's options
|
29
|
+
def command_options(arg=nil)
|
30
|
+
@command_options = arg if arg
|
31
|
+
@command_options
|
32
|
+
end
|
33
|
+
# backward compatibility
|
34
|
+
alias_method :options, :command_options
|
35
|
+
alias_method :options=, :command_options=
|
36
|
+
|
37
|
+
# Define or get the command's banner
|
38
|
+
def banner(arg=nil)
|
39
|
+
@banner = arg if arg
|
40
|
+
@banner || description
|
41
|
+
end
|
21
42
|
end
|
22
43
|
|
44
|
+
|
23
45
|
# Make those properties accessible to instances
|
24
46
|
def name; self.class.name; end
|
25
47
|
def description; self.class.description; end
|
@@ -47,7 +69,7 @@ class Pry
|
|
47
69
|
klass.send(:include, helpers)
|
48
70
|
klass.name = name
|
49
71
|
klass.description = description
|
50
|
-
klass.
|
72
|
+
klass.command_options = options
|
51
73
|
klass.block = block
|
52
74
|
klass
|
53
75
|
end
|
@@ -276,10 +298,19 @@ class Pry
|
|
276
298
|
# backwards compatibility
|
277
299
|
alias_method :opts, :context
|
278
300
|
|
301
|
+
# Call the block that was registered with this command.
|
302
|
+
#
|
303
|
+
# @param *String the arguments passed
|
304
|
+
# @return Object the return value of the block
|
279
305
|
def call(*args)
|
280
306
|
instance_exec(*correct_arg_arity(block.arity, args), &block)
|
281
307
|
end
|
282
308
|
|
309
|
+
# Fix the number of arguments we pass to a block to avoid arity warnings.
|
310
|
+
#
|
311
|
+
# @param Number the arity of the block
|
312
|
+
# @param Array the arguments to pass
|
313
|
+
# @return Array a (possibly shorter) array of the arguments to pass
|
283
314
|
def correct_arg_arity(arity, args)
|
284
315
|
case
|
285
316
|
when arity < 0
|
@@ -304,12 +335,6 @@ class Pry
|
|
304
335
|
# necessary, you can also override {setup} which will be called before {options}, for example to
|
305
336
|
# require any gems your command needs to run, or to set up state.
|
306
337
|
class ClassCommand < Command
|
307
|
-
class << self
|
308
|
-
def banner(arg=nil)
|
309
|
-
@banner = arg if arg
|
310
|
-
@banner || description
|
311
|
-
end
|
312
|
-
end
|
313
338
|
|
314
339
|
attr_accessor :opts
|
315
340
|
attr_accessor :args
|
data/lib/pry/command_set.rb
CHANGED
@@ -81,11 +81,12 @@ class Pry
|
|
81
81
|
# # hello john, nice number: 10
|
82
82
|
# # pry(main)> help number
|
83
83
|
# # number-N regex command
|
84
|
-
def
|
84
|
+
def block_command(name, description="No description.", options={}, &block)
|
85
85
|
options = default_options(name).merge!(options)
|
86
86
|
|
87
87
|
commands[name] = Pry::BlockCommand.subclass(name, description, options, helper_module, &block)
|
88
88
|
end
|
89
|
+
alias_method :command, :block_command
|
89
90
|
|
90
91
|
# Defines a new Pry command class.
|
91
92
|
#
|
@@ -96,7 +97,7 @@ class Pry
|
|
96
97
|
# @param &Block The class body's definition.
|
97
98
|
#
|
98
99
|
# @example
|
99
|
-
# Pry::Commands.
|
100
|
+
# Pry::Commands.create_command "echo", "echo's the input", :shellwords => false do
|
100
101
|
# def options(opt)
|
101
102
|
# opt.banner "Usage: echo [-u | -d] <string to echo>"
|
102
103
|
# opt.on :u, :upcase, "ensure the output is all upper-case"
|
@@ -112,13 +113,14 @@ class Pry
|
|
112
113
|
# end
|
113
114
|
# end
|
114
115
|
#
|
115
|
-
def
|
116
|
+
def create_command(name, description="No description.", options={}, &block)
|
116
117
|
options = default_options(name).merge!(options)
|
117
118
|
|
118
119
|
commands[name] = Pry::ClassCommand.subclass(name, description, options, helper_module, &block)
|
119
120
|
commands[name].class_eval(&block)
|
120
121
|
commands[name]
|
121
122
|
end
|
123
|
+
alias_method :command_class, :create_command
|
122
124
|
|
123
125
|
# Execute a block of code before a command is invoked. The block also
|
124
126
|
# gets access to parameters that will be passed to the command and
|
@@ -97,18 +97,24 @@ USAGE
|
|
97
97
|
opt.on :l, :lines, "Only gist a subset of lines (only works with -m and -f)", :optional => true, :as => Range, :default => 1..-1
|
98
98
|
opt.on :i, :in, "Gist entries from Pry's input expression history. Takes an index or range.", :optional => true,
|
99
99
|
:as => Range, :default => -5..-1 do |range|
|
100
|
+
self.input_ranges ||= []
|
100
101
|
input_ranges << absolute_index_range(range, _pry_.input_array.length)
|
101
102
|
end
|
102
103
|
end
|
103
104
|
|
104
105
|
def process
|
106
|
+
self.content = ""
|
107
|
+
|
105
108
|
if opts.present?(:in)
|
106
109
|
in_option
|
107
|
-
|
110
|
+
end
|
111
|
+
if opts.present?(:file)
|
108
112
|
file_option
|
109
|
-
|
113
|
+
end
|
114
|
+
if opts.present?(:doc)
|
110
115
|
doc_option
|
111
|
-
|
116
|
+
end
|
117
|
+
if opts.present?(:method)
|
112
118
|
method_option
|
113
119
|
end
|
114
120
|
|
@@ -117,7 +123,6 @@ USAGE
|
|
117
123
|
|
118
124
|
def in_option
|
119
125
|
self.code_type = :ruby
|
120
|
-
self.content = ""
|
121
126
|
|
122
127
|
input_ranges.each do |range|
|
123
128
|
input_expressions = _pry_.input_array[range] || []
|
@@ -136,19 +141,19 @@ USAGE
|
|
136
141
|
def file_option
|
137
142
|
whole_file = File.read(File.expand_path(opts[:f]))
|
138
143
|
if opts.present?(:lines)
|
139
|
-
self.content
|
144
|
+
self.content << restrict_to_lines(whole_file, opts[:l])
|
140
145
|
else
|
141
|
-
self.content
|
146
|
+
self.content << whole_file
|
142
147
|
end
|
143
148
|
end
|
144
149
|
|
145
150
|
def doc_option
|
146
151
|
meth = get_method_or_raise(opts[:d], target, {})
|
147
|
-
self.content
|
152
|
+
self.content << meth.doc
|
148
153
|
self.code_type = meth.source_type
|
149
154
|
|
150
155
|
text.no_color do
|
151
|
-
self.content
|
156
|
+
self.content << process_comment_markup(self.content, self.code_type)
|
152
157
|
end
|
153
158
|
self.code_type = :plain
|
154
159
|
end
|
@@ -157,9 +162,9 @@ USAGE
|
|
157
162
|
meth = get_method_or_raise(opts[:m], target, {})
|
158
163
|
method_source = meth.source
|
159
164
|
if opts.present?(:lines)
|
160
|
-
self.content
|
165
|
+
self.content << restrict_to_lines(method_source, opts[:l])
|
161
166
|
else
|
162
|
-
self.content
|
167
|
+
self.content << method_source
|
163
168
|
end
|
164
169
|
|
165
170
|
self.code_type = meth.source_type
|
@@ -9,7 +9,7 @@ class Pry
|
|
9
9
|
end
|
10
10
|
|
11
11
|
command "show-input", "Show the contents of the input buffer for the current multi-line expression." do
|
12
|
-
render_output(false, 1,
|
12
|
+
render_output(false, 1, colorize_code(eval_string))
|
13
13
|
end
|
14
14
|
|
15
15
|
command(/amend-line(?: (-?\d+)(?:\.\.(-?\d+))?)?/, "Amend a line of input in multi-line mode. Type `amend-line --help` for more information. Aliases %",
|
@@ -19,45 +19,102 @@ class Pry
|
|
19
19
|
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
command_class "reload-command", "Reload a Pry command." do
|
23
|
+
banner <<-BANNER
|
24
|
+
Usage: reload-command command
|
25
|
+
Reload a Pry command.
|
26
|
+
BANNER
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def process
|
29
|
+
command = _pry_.commands.find_command(args.first)
|
30
|
+
|
31
|
+
if command.nil?
|
32
|
+
raise Pry::CommandError, 'No command found.'
|
33
|
+
end
|
30
34
|
|
31
|
-
|
32
|
-
|
35
|
+
source_code = command.block.source
|
36
|
+
file, lineno = command.block.source_location
|
33
37
|
|
34
|
-
|
35
|
-
|
38
|
+
set = Pry::CommandSet.new do
|
39
|
+
eval(source_code, binding, file, lineno)
|
40
|
+
end
|
41
|
+
|
42
|
+
_pry_.commands.delete(command.name)
|
43
|
+
_pry_.commands.import(set)
|
36
44
|
end
|
37
|
-
Pry.config.commands.import target.eval(set_name)
|
38
|
-
_pry_.commands.import target.eval(set_name)
|
39
|
-
set_file_and_dir_locals(file_name)
|
40
45
|
end
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
|
47
|
+
command_class "edit-command", "Edit a Pry command." do
|
48
|
+
banner <<-BANNER
|
49
|
+
Usage: edit-command [options] command
|
50
|
+
Edit a Pry command.
|
51
|
+
BANNER
|
52
|
+
|
53
|
+
def initialize env
|
54
|
+
@pry = env[:pry_instance]
|
55
|
+
@command = nil
|
56
|
+
super(env)
|
45
57
|
end
|
46
58
|
|
47
|
-
|
48
|
-
|
59
|
+
def options(opt)
|
60
|
+
opt.on :p, :patch, 'Perform a in-memory edit of a command'
|
61
|
+
end
|
62
|
+
|
63
|
+
def process
|
64
|
+
@command = @pry.commands.find_command(args.first)
|
65
|
+
|
66
|
+
if @command.nil?
|
67
|
+
raise Pry::CommandError, 'Command not found.'
|
68
|
+
end
|
69
|
+
|
70
|
+
case
|
71
|
+
when opts.present?(:patch)
|
72
|
+
edit_temporarily
|
73
|
+
else
|
74
|
+
edit_permanently
|
75
|
+
end
|
49
76
|
end
|
50
77
|
|
51
|
-
|
52
|
-
|
78
|
+
def edit_permanently
|
79
|
+
file, lineno = @command.block.source_location
|
80
|
+
invoke_editor(file, lineno)
|
81
|
+
|
82
|
+
command_set = silence_warnings do
|
83
|
+
eval File.read(file), TOPLEVEL_BINDING, file, 1
|
84
|
+
end
|
85
|
+
|
86
|
+
unless command_set.is_a?(Pry::CommandSet)
|
87
|
+
raise Pry::CommandError,
|
88
|
+
"Expected file '#{file}' to return a CommandSet"
|
89
|
+
end
|
90
|
+
|
91
|
+
@pry.commands.delete(@command.name)
|
92
|
+
@pry.commands.import(command_set)
|
93
|
+
set_file_and_dir_locals(file)
|
94
|
+
end
|
95
|
+
|
96
|
+
def edit_temporarily
|
97
|
+
source_code = Pry::Method(@command.block).source
|
98
|
+
modified_code = nil
|
99
|
+
|
100
|
+
temp_file do |f|
|
101
|
+
f.write(source_code)
|
102
|
+
f.flush
|
103
|
+
|
104
|
+
invoke_editor(f.path, 1)
|
105
|
+
modified_code = File.read(f.path)
|
106
|
+
end
|
107
|
+
|
108
|
+
command_set = CommandSet.new do
|
109
|
+
silence_warnings do
|
110
|
+
pry = Pry.new :input => StringIO.new(modified_code)
|
111
|
+
pry.rep(binding)
|
112
|
+
end
|
113
|
+
end
|
53
114
|
|
54
|
-
|
55
|
-
|
56
|
-
load file_name
|
115
|
+
@pry.commands.delete(@command.name)
|
116
|
+
@pry.commands.import(command_set)
|
57
117
|
end
|
58
|
-
Pry.config.commands.import target.eval(set_name)
|
59
|
-
_pry_.commands.import target.eval(set_name)
|
60
|
-
set_file_and_dir_locals(file_name)
|
61
118
|
end
|
62
119
|
|
63
120
|
end
|
data/lib/pry/hooks.rb
CHANGED
@@ -5,6 +5,59 @@ class Pry
|
|
5
5
|
@hooks = {}
|
6
6
|
end
|
7
7
|
|
8
|
+
# Ensure that duplicates have their @hooks object
|
9
|
+
def initialize_copy(orig)
|
10
|
+
hooks_dup = @hooks.dup
|
11
|
+
@hooks.each do |k, v|
|
12
|
+
hooks_dup[k] = v.dup
|
13
|
+
end
|
14
|
+
|
15
|
+
@hooks = hooks_dup
|
16
|
+
end
|
17
|
+
|
18
|
+
def hooks
|
19
|
+
@hooks
|
20
|
+
end
|
21
|
+
protected :hooks
|
22
|
+
|
23
|
+
# Destructively merge the contents of two `Pry:Hooks` instances.
|
24
|
+
# @param [Pry::Hooks] other The `Pry::Hooks` instance to merge
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
# TODO: implement by iterating over parameter and only overwriting
|
29
|
+
# elements in receiver if they exist in parameter, and adding
|
30
|
+
# other paramater elements to the end of the original's array
|
31
|
+
def merge!(other)
|
32
|
+
@hooks.merge!(other.dup.hooks) do |key, v1, v2|
|
33
|
+
merge_arrays(v1, v2)
|
34
|
+
end
|
35
|
+
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def merge_arrays(array1, array2)
|
40
|
+
keys = array1.map {|(k,v)| k}
|
41
|
+
hash = {}
|
42
|
+
array1.each{|(k,v)| hash[k]=v}
|
43
|
+
keys.push(*array2.map {|(k,v)| k})
|
44
|
+
array2.each{|(k,v)| hash[k]=v}
|
45
|
+
result = []
|
46
|
+
keys.uniq!
|
47
|
+
keys.each{|k| result.push([k,hash[k]]) }
|
48
|
+
result
|
49
|
+
end
|
50
|
+
private :merge_arrays
|
51
|
+
|
52
|
+
# Return a new `Pry::Hooks` instance containing a merge of the contents of two `Pry:Hooks` instances,
|
53
|
+
# @param [Pry::Hooks] other The `Pry::Hooks` instance to merge
|
54
|
+
# @return [Pry::Hooks] The new hash.
|
55
|
+
def merge(other)
|
56
|
+
self.dup.tap do |v|
|
57
|
+
v.merge!(other)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
8
61
|
# Add a new hook to be executed for the `name` even.
|
9
62
|
# @param [Symbol] event_name The name of the event.
|
10
63
|
# @param [Symbol] hook_name The name of the hook.
|
@@ -91,10 +144,12 @@ class Pry
|
|
91
144
|
|
92
145
|
# Clear all hooks functions for a given event.
|
93
146
|
# @param [String] event_name The name of the event.
|
94
|
-
def
|
147
|
+
def delete_hooks(event_name)
|
95
148
|
@hooks[event_name] = []
|
96
149
|
end
|
97
150
|
|
151
|
+
alias_method :clear, :delete_hooks
|
152
|
+
|
98
153
|
# @param [Symbol] event_name Name of the event.
|
99
154
|
# @param [Symbol] hook_name Name of the hook.
|
100
155
|
# @return [Boolean] Whether the hook by the name `hook_name`
|
data/lib/pry/method.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
class Pry
|
3
|
+
class << self
|
4
|
+
# If the given object is a `Pry::Method`, return it unaltered. If it's
|
5
|
+
# anything else, return it wrapped in a `Pry::Method` instance.
|
6
|
+
def Method(obj)
|
7
|
+
if obj.is_a? Pry::Method
|
8
|
+
obj
|
9
|
+
else
|
10
|
+
Pry::Method.new(obj)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
3
15
|
class Method
|
4
16
|
include RbxMethod if Helpers::BaseHelpers.rbx?
|
5
17
|
|
data/lib/pry/pry_instance.rb
CHANGED
@@ -111,9 +111,9 @@ class Pry
|
|
111
111
|
inject_local("_in_", @input_array, target)
|
112
112
|
inject_local("_out_", @output_array, target)
|
113
113
|
inject_local("_pry_", self, target)
|
114
|
-
inject_local("_ex_",
|
115
|
-
inject_local("_file_",
|
116
|
-
inject_local("_dir_",
|
114
|
+
inject_local("_ex_", last_exception, target)
|
115
|
+
inject_local("_file_", last_file, target)
|
116
|
+
inject_local("_dir_", last_dir, target)
|
117
117
|
|
118
118
|
# without this line we get 1 test failure, ask Mon_Ouie
|
119
119
|
set_last_result(nil, target)
|
@@ -129,13 +129,13 @@ class Pry
|
|
129
129
|
|
130
130
|
def special_locals
|
131
131
|
{
|
132
|
-
:_in_
|
133
|
-
:_out_
|
134
|
-
:_pry_
|
135
|
-
:_ex_
|
132
|
+
:_in_ => @input_array,
|
133
|
+
:_out_ => @output_array,
|
134
|
+
:_pry_ => self,
|
135
|
+
:_ex_ => last_exception,
|
136
136
|
:_file_ => last_file,
|
137
|
-
:_dir_
|
138
|
-
:_
|
137
|
+
:_dir_ => last_dir,
|
138
|
+
:_ => last_result
|
139
139
|
}
|
140
140
|
end
|
141
141
|
|
@@ -566,7 +566,7 @@ class Pry
|
|
566
566
|
end
|
567
567
|
|
568
568
|
# Assert that a line which ends with a , or a \ is incomplete.
|
569
|
-
str !~ /[,\\]
|
569
|
+
str !~ /[,\\]\z/
|
570
570
|
rescue SyntaxError => e
|
571
571
|
if incomplete_user_input_exception?(e)
|
572
572
|
false
|
data/lib/pry/version.rb
CHANGED
data/pry.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "pry"
|
5
|
-
s.version = "0.9.
|
5
|
+
s.version = "0.9.8pre4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["John Mair (banisterfiend)"]
|
9
|
-
s.date = "2012-01-
|
9
|
+
s.date = "2012-01-12"
|
10
10
|
s.description = "An IRB alternative and runtime developer console"
|
11
11
|
s.email = "jrmair@gmail.com"
|
12
12
|
s.executables = ["pry"]
|
@@ -141,8 +141,15 @@ describe "Pry::DefaultCommands::Context" do
|
|
141
141
|
$outer.should == :outer
|
142
142
|
end
|
143
143
|
|
144
|
-
it
|
145
|
-
Pry.
|
144
|
+
it "should not leave the REPL session when given 'cd ..'" do
|
145
|
+
b = Pry.binding_for(Object.new)
|
146
|
+
input = InputTester.new "cd ..", "$obj = self", "exit-all"
|
147
|
+
|
148
|
+
redirect_pry_io(input, StringIO.new) do
|
149
|
+
b.pry
|
150
|
+
end
|
151
|
+
|
152
|
+
$obj.should == b.eval("self")
|
146
153
|
end
|
147
154
|
|
148
155
|
it 'should break out to outer-most session with cd /' do
|
data/test/test_hooks.rb
CHANGED
@@ -53,6 +53,125 @@ describe Pry::Hooks do
|
|
53
53
|
end
|
54
54
|
end
|
55
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
|
+
|
56
175
|
describe "getting hooks" do
|
57
176
|
describe "get_hook" do
|
58
177
|
it 'should return the correct requested hook' do
|
@@ -44,4 +44,15 @@ describe Pry do
|
|
44
44
|
end
|
45
45
|
output.string.should =~ /SyntaxError/
|
46
46
|
end
|
47
|
+
|
48
|
+
it "should allow trailing , to continue the line" do
|
49
|
+
pry = Pry.new
|
50
|
+
|
51
|
+
pry.complete_expression?("puts 1, 2,").should == false
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should complete an expression that contains a line ending with a ," do
|
55
|
+
pry = Pry.new
|
56
|
+
pry.complete_expression?("puts 1, 2,\n3").should == true
|
57
|
+
end
|
47
58
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: pry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 5
|
5
|
-
version: 0.9.
|
5
|
+
version: 0.9.8pre4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- John Mair (banisterfiend)
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-01-
|
13
|
+
date: 2012-01-12 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: coderay
|