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,24 +38,35 @@ describe Pry::CodeObject do
|
||||||
m.source.should =~ /hello/
|
m.source.should =~ /hello/
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should lookup commands' do
|
describe 'commands lookup' do
|
||||||
p = Pry.new
|
it 'works' do
|
||||||
p.commands.command "jeremy-jones" do
|
p = Pry.new
|
||||||
"lobster"
|
p.commands.command "jeremy-jones" do
|
||||||
|
"lobster"
|
||||||
|
end
|
||||||
|
m = Pry::CodeObject.lookup("jeremy-jones", binding, p)
|
||||||
|
(m <= Pry::Command).should == true
|
||||||
|
m.source.should =~ /lobster/
|
||||||
end
|
end
|
||||||
m = Pry::CodeObject.lookup("jeremy-jones", binding, p)
|
|
||||||
(m <= Pry::Command).should == true
|
|
||||||
m.source.should =~ /lobster/
|
|
||||||
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"
|
||||||
|
end
|
||||||
|
m = Pry::CodeObject.lookup("jeremy-baby", binding, p)
|
||||||
|
(m <= Pry::Command).should == true
|
||||||
|
m.source.should =~ /lobster/
|
||||||
end
|
end
|
||||||
m = Pry::CodeObject.lookup("jeremy-baby", binding, p)
|
|
||||||
(m <= Pry::Command).should == true
|
it 'finds nothing when passing nil as the first argument' do
|
||||||
m.source.should =~ /lobster/
|
p = Pry.new
|
||||||
|
p.commands.command /kierkegaard-.*/, '', :listing => 'kierkegaard-baby' do
|
||||||
|
"lobster"
|
||||||
|
end
|
||||||
|
Pry::CodeObject.lookup(nil, binding, p).should == nil
|
||||||
|
end
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue