diff --git a/test/test_command_set.rb b/test/test_command_set.rb index 88636c25..fec2f795 100644 --- a/test/test_command_set.rb +++ b/test/test_command_set.rb @@ -252,26 +252,6 @@ describe Pry::CommandSet do }.should.not.raise end - it "should sort the output of the 'help' command" do - @set.command 'foo', "Fooerizes" do; end - @set.command 'goo', "Gooerizes" do; end - @set.command 'moo', "Mooerizes" do; end - @set.command 'boo', "Booerizes" do; end - - @ctx[:command_set] = @set - @ctx[:output] = StringIO.new - - @set.run_command(@ctx, 'help') - - doc = @ctx[:output].string - - order = [doc.index("boo"), - doc.index("foo"), - doc.index("goo"), - doc.index("moo")] - - order.should == order.sort - end describe "renaming a command" do it 'should be able to rename and run a command' do @@ -300,7 +280,6 @@ describe Pry::CommandSet do lambda { @set.run_command(@ctx, 'foo') }.should.raise Pry::NoCommandError end - it 'should be able to pass in options when renaming command' do desc = "hello" listing = "bing" diff --git a/test/test_default_commands.rb b/test/test_default_commands.rb deleted file mode 100644 index 671876f1..00000000 --- a/test/test_default_commands.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'helper' - -describe "Pry::Commands" do - before do - @set = Pry::CommandSet.new do - import Pry::DefaultCommands::Help - end - end - - describe "help" do - it 'should display help for a specific command' do - str_output = StringIO.new - redirect_pry_io(InputTester.new("help ls", "exit-all"), str_output) do - pry - end - str_output.string.should =~ /Usage: ls/ - end - - it 'should display help for a regex command with a "listing"' do - @set.command /bar(.*)/, "Test listing", :listing => "foo" do; end - - str_output = StringIO.new - redirect_pry_io(InputTester.new("help foo"), str_output) do - Pry.new(:commands => @set).rep - end - str_output.string.each_line.count.should == 1 - str_output.string.should =~ /Test listing/ - end - - it 'should display help for a command with a spaces in its name' do - @set.command "command with spaces", "description of a command with spaces" do; end - - str_output = StringIO.new - redirect_pry_io(InputTester.new("help \"command with spaces\""), str_output) do - Pry.new(:commands => @set).rep - end - str_output.string.each_line.count.should == 1 - str_output.string.should =~ /description of a command with spaces/ - end - - it 'should display help for all commands with a description' do - @set.instance_eval do - command /bar(.*)/, "Test listing", :listing => "foo" do; end - command "b", "description for b", :listing => "foo" do; end - command "c" do;end - command "d", "" do;end - end - - str_output = StringIO.new - redirect_pry_io(InputTester.new("help"), str_output) do - Pry.new(:commands => @set).rep - end - str_output.string.should =~ /Test listing/ - str_output.string.should =~ /description for b/ - str_output.string.should =~ /No description/ - end - end -end diff --git a/test/test_default_commands/test_help.rb b/test/test_default_commands/test_help.rb new file mode 100644 index 00000000..a19788d2 --- /dev/null +++ b/test/test_default_commands/test_help.rb @@ -0,0 +1,57 @@ +require 'helper' + +describe "'help' command" do + before do + @oldset = Pry.config.commands + @set = Pry.config.commands = Pry::CommandSet.new do + import Pry::DefaultCommands::Help + import Pry::DefaultCommands::Ls + end + end + + after do + Pry.config.commands = @oldset + end + + it 'should display help for a specific command' do + mock_pry('help ls').should =~ /Usage: ls/ + end + + it 'should display help for a regex command with a "listing"' do + @set.command /bar(.*)/, "Test listing", :listing => "foo" do; end + mock_pry('help foo').should =~ /Test listing/ + end + + it 'should display help for a command with a spaces in its name' do + @set.command "command with spaces", "description of a command with spaces" do; end + mock_pry('help "command with spaces"').should =~ /description of a command with spaces/ + end + + it 'should display help for all commands with a description' do + @set.command /bar(.*)/, "Test listing", :listing => "foo" do; end + @set.command "b", "description for b", :listing => "foo" do; end + @set.command "c" do;end + @set.command "d", "" do;end + + output = mock_pry('help') + output.should =~ /Test listing/ + output.should =~ /description for b/ + output.should =~ /No description/ + end + + it "should sort the output of the 'help' command" do + @set.command 'foo', "Fooerizes" do; end + @set.command 'goo', "Gooerizes" do; end + @set.command 'moo', "Mooerizes" do; end + @set.command 'boo', "Booerizes" do; end + + doc = mock_pry('help') + + order = [doc.index("boo"), + doc.index("foo"), + doc.index("goo"), + doc.index("moo")] + + order.should == order.sort + end +end