Fix wrong command groups

Fix issue #631 (In `help` output: aliases are no longer grouped under
Aliases heading but under (other))

Forbid redefining a group of a command once it is initialized. Also, add
some unit tests, checking for that, so we won't miss this if it happens
next time.

Reported-by: John Mair <jrmair@gmail.com>
Cc: Rob Gleeson <rob@flowof.info>
Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
This commit is contained in:
Kyrylo Silin 2012-07-05 23:31:03 +03:00
parent 6a54e34dad
commit e0fdf24461
2 changed files with 29 additions and 13 deletions

View File

@ -143,21 +143,21 @@ class Pry
# This is usually auto-generated from directory naming, but it can be
# manually overridden if necessary.
def group(name=nil)
@group = if name
name
else
case Pry::Method(block).source_file
when %r{/pry/.*_commands/(.*).rb}
$1.capitalize.gsub(/_/, " ")
when %r{(pry-\w+)-([\d\.]+([\w\d\.]+)?)}
name, version = $1, $2
"#{name.to_s} (v#{version.to_s})"
when /pryrc/
"~/.pryrc"
@group ||= if name
name
else
"(other)"
case Pry::Method(block).source_file
when %r{/pry/.*_commands/(.*).rb}
$1.capitalize.gsub(/_/, " ")
when %r{(pry-\w+)-([\d\.]+([\w\d\.]+)?)}
name, version = $1, $2
"#{name.to_s} (v#{version.to_s})"
when /pryrc/
"~/.pryrc"
else
"(other)"
end
end
end
end
end

View File

@ -693,4 +693,20 @@ describe "Pry::Command" do
instance.command_state[/[Hh]ello-world/].my_state.should == 4
end
end
describe 'group' do
before do
@set.import Pry::DefaultCommands::Cd
end
it 'should not change once it is initialized' do
@set.commands["cd"].group("-==CD COMMAND==-")
@set.commands["cd"].group.should == "Context"
end
it 'should be correct for default commands' do
@set.commands["cd"].group.should == "Context"
@set.commands["help"].group.should == "Help"
end
end
end