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)
|
||||
command_match = set.find do |_, command|
|
||||
command.options[:listing] == name
|
||||
(listing = command.options[:listing]) == name && listing != nil
|
||||
end
|
||||
command_match.last if command_match
|
||||
end
|
||||
|
|
|
@ -38,24 +38,35 @@ describe Pry::CodeObject do
|
|||
m.source.should =~ /hello/
|
||||
end
|
||||
|
||||
it 'should lookup commands' do
|
||||
p = Pry.new
|
||||
p.commands.command "jeremy-jones" do
|
||||
"lobster"
|
||||
describe 'commands lookup' do
|
||||
it 'works' do
|
||||
p = Pry.new
|
||||
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
|
||||
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
|
||||
p = Pry.new
|
||||
p.commands.command /jeremy-.*/, "", :listing => "jeremy-baby" do
|
||||
"lobster"
|
||||
it 'looks up commands by :listing name as well' do
|
||||
p = Pry.new
|
||||
p.commands.command /jeremy-.*/, "", :listing => "jeremy-baby" do
|
||||
"lobster"
|
||||
end
|
||||
m = Pry::CodeObject.lookup("jeremy-baby", binding, p)
|
||||
(m <= Pry::Command).should == true
|
||||
m.source.should =~ /lobster/
|
||||
end
|
||||
m = Pry::CodeObject.lookup("jeremy-baby", binding, p)
|
||||
(m <= Pry::Command).should == true
|
||||
m.source.should =~ /lobster/
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue