1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Move and update "help" specs a bit

This commit is contained in:
Conrad Irwin 2012-02-22 23:56:25 -08:00
parent 656b1fc9aa
commit 127015d723
3 changed files with 57 additions and 79 deletions

View file

@ -252,26 +252,6 @@ describe Pry::CommandSet do
}.should.not.raise }.should.not.raise
end 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 describe "renaming a command" do
it 'should be able to rename and run 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 lambda { @set.run_command(@ctx, 'foo') }.should.raise Pry::NoCommandError
end end
it 'should be able to pass in options when renaming command' do it 'should be able to pass in options when renaming command' do
desc = "hello" desc = "hello"
listing = "bing" listing = "bing"

View file

@ -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

View file

@ -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