-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #642 from alessio-signorini/allow-to-override-comm…
…ands-sorting Allow to Override Order of Commands in Help
- Loading branch information
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require "helper" | ||
|
||
describe Thor do | ||
def shell | ||
@shell ||= Thor::Base.shell.new | ||
end | ||
|
||
describe "#sort - default" do | ||
my_script = Class.new(Thor) do | ||
desc "a", "First Command" | ||
def a; end | ||
|
||
desc "z", "Last Command" | ||
def z; end | ||
end | ||
|
||
before do | ||
@content = capture(:stdout) { my_script.help(shell) } | ||
end | ||
|
||
it "sorts them lexicographillay" do | ||
expect(@content).to match(/:a.+:help.+:z/m) | ||
end | ||
end | ||
|
||
|
||
describe "#sort - simple override" do | ||
my_script = Class.new(Thor) do | ||
desc "a", "First Command" | ||
def a; end | ||
|
||
desc "z", "Last Command" | ||
def z; end | ||
|
||
def self.sort_commands!(list) | ||
list.sort! | ||
list.reverse! | ||
end | ||
|
||
end | ||
|
||
before do | ||
@content = capture(:stdout) { my_script.help(shell) } | ||
end | ||
|
||
it "sorts them in reverse" do | ||
expect(@content).to match(/:z.+:help.+:a/m) | ||
end | ||
end | ||
|
||
|
||
describe "#sort - simple override" do | ||
my_script = Class.new(Thor) do | ||
desc "a", "First Command" | ||
def a; end | ||
|
||
desc "z", "Last Command" | ||
def z; end | ||
|
||
def self.sort_commands!(list) | ||
list.sort_by! do |a,b| | ||
a[0] == :help ? -1 : a[0] <=> b[0] | ||
end | ||
end | ||
end | ||
|
||
before do | ||
@content = capture(:stdout) { my_script.help(shell) } | ||
end | ||
|
||
it "puts help first then sorts them lexicographillay" do | ||
expect(@content).to match(/:help.+:a.+:z/m) | ||
end | ||
end | ||
end |