mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Ensure nil doesn't freak out #find_command
When you pass `nil` to `BaseHelpers#find_command` and a command in `set` doesn't have the `:listing` option (for example, when your command is a regular Ruby class), `#find_command` will return that command (even if it doesn't match at all). command.options[:listing] #=> nil name = nil command.options[:listing] == name #=> true Add tests to "code_object_spec.rb", because that's how I found this shortage and it seems to be a natural test. Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
This commit is contained in:
parent
0241d230c5
commit
73820fa08a
2 changed files with 27 additions and 16 deletions
|
@ -26,7 +26,7 @@ class Pry
|
||||||
|
|
||||||
def find_command(name, set = Pry::Commands)
|
def find_command(name, set = Pry::Commands)
|
||||||
command_match = set.find do |_, command|
|
command_match = set.find do |_, command|
|
||||||
command.options[:listing] == name
|
(listing = command.options[:listing]) == name && listing != nil
|
||||||
end
|
end
|
||||||
command_match.last if command_match
|
command_match.last if command_match
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,8 @@ describe Pry::CodeObject do
|
||||||
m.source.should =~ /hello/
|
m.source.should =~ /hello/
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should lookup commands' do
|
describe 'commands lookup' do
|
||||||
|
it 'works' do
|
||||||
p = Pry.new
|
p = Pry.new
|
||||||
p.commands.command "jeremy-jones" do
|
p.commands.command "jeremy-jones" do
|
||||||
"lobster"
|
"lobster"
|
||||||
|
@ -48,7 +49,7 @@ describe Pry::CodeObject do
|
||||||
m.source.should =~ /lobster/
|
m.source.should =~ /lobster/
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should lookup commands by :listing name as well' do
|
it 'looks up commands by :listing name as well' do
|
||||||
p = Pry.new
|
p = Pry.new
|
||||||
p.commands.command /jeremy-.*/, "", :listing => "jeremy-baby" do
|
p.commands.command /jeremy-.*/, "", :listing => "jeremy-baby" do
|
||||||
"lobster"
|
"lobster"
|
||||||
|
@ -58,6 +59,16 @@ describe Pry::CodeObject do
|
||||||
m.source.should =~ /lobster/
|
m.source.should =~ /lobster/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'finds nothing when passing nil as the first argument' do
|
||||||
|
p = Pry.new
|
||||||
|
p.commands.command /kierkegaard-.*/, '', :listing => 'kierkegaard-baby' do
|
||||||
|
"lobster"
|
||||||
|
end
|
||||||
|
Pry::CodeObject.lookup(nil, binding, p).should == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
it 'should lookup instance methods defined on classes accessed via local variable' do
|
it 'should lookup instance methods defined on classes accessed via local variable' do
|
||||||
o = Class.new do
|
o = Class.new do
|
||||||
def princess_bubblegum
|
def princess_bubblegum
|
||||||
|
|
Loading…
Reference in a new issue