From 5cb356f7319638334a5f61cf97dd8097b5590ce2 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Tue, 25 Dec 2012 21:31:57 +0200 Subject: [PATCH] Refactor 'command_lookup' Thanks to Bacon we can use `before` method to simplify our life. And, blimey, I accidentally left some unwanted code after myself! Signed-off-by: Kyrylo Silin --- spec/code_object_spec.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/spec/code_object_spec.rb b/spec/code_object_spec.rb index 5e7b33ab..62ed62e0 100644 --- a/spec/code_object_spec.rb +++ b/spec/code_object_spec.rb @@ -39,32 +39,30 @@ describe Pry::CodeObject do end describe 'commands lookup' do + before do + @p = Pry.new + end + it 'works' do - p = Pry.new - p.commands.command "jeremy-jones" do + @p.commands.command "jeremy-jones" do "lobster" end - m = Pry::CodeObject.lookup("jeremy-jones", binding, p) + m = Pry::CodeObject.lookup("jeremy-jones", binding, @p) (m <= Pry::Command).should == true m.source.should =~ /lobster/ end it 'looks up commands by :listing name as well' do - p = Pry.new - p.commands.command /jeremy-.*/, "", :listing => "jeremy-baby" do + @p.commands.command /jeremy-.*/, "", :listing => "jeremy-baby" do "lobster" end - m = Pry::CodeObject.lookup("jeremy-baby", binding, p) + m = Pry::CodeObject.lookup("jeremy-baby", binding, @p) (m <= Pry::Command).should == true m.source.should =~ /lobster/ 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 + Pry::CodeObject.lookup(nil, binding, @p).should == nil end end