Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for #755 #756

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ tmtags
tramp
.rbx
b/
.DS_Store
2 changes: 1 addition & 1 deletion lib/thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable Me
#
def banner(command, namespace = nil, subcommand = false)
command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |formatted_usage|
"#{basename} #{formatted_usage}"
"#{formatted_usage}"
end.join("\n")
end

Expand Down
2 changes: 1 addition & 1 deletion spec/register_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def with_args(*args)
begin
$thor_runner = false
help_output = capture(:stdout) { BoringVendorProvidedCLI.start(%w(exciting)) }
expect(help_output).to include("thor exciting fireworks")
expect(help_output).to include("exciting fireworks")
ensure
$thor_runner = true
end
Expand Down
4 changes: 2 additions & 2 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def when_no_thorfiles_exist
ARGV.replace %w(my_script:animal)
content = capture(:stderr) { Thor::Runner.start }
expect(content.strip).to eq('ERROR: "thor animal" was called with no arguments
Usage: "thor my_script:animal TYPE"')
Usage: "my_script:animal TYPE"')
end
end

Expand Down Expand Up @@ -171,7 +171,7 @@ def when_no_thorfiles_exist

it "presents commands in the default namespace with an empty namespace" do
ARGV.replace %w(list)
expect(capture(:stdout) { Thor::Runner.start }).to match(/^thor :cow\s+# prints 'moo'/m)
expect(capture(:stdout) { Thor::Runner.start }).to match(/^:cow\s+# prints 'moo'/m)
end

it "runs commands with an empty namespace from the default namespace" do
Expand Down
2 changes: 1 addition & 1 deletion spec/subcommand_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def self.exit_on_failure?

it "shows subcommand name and method name" do
sub_help = capture(:stderr) { SubcommandTest1::Parent.start(%w(child1 foo)) }
expect(sub_help).to eq ['ERROR: "thor child1 foo" was called with no arguments', 'Usage: "thor child1 foo NAME"', ""].join("\n")
expect(sub_help).to eq ['ERROR: "thor child1 foo" was called with no arguments', 'Usage: "child1 foo NAME"', ""].join("\n")
end
end
end
30 changes: 15 additions & 15 deletions spec/thor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,14 @@ def self.exit_on_failure?
describe "#desc" do
it "provides description for a command" do
content = capture(:stdout) { MyScript.start(%w(help)) }
expect(content).to match(/thor my_script:zoo\s+# zoo around/m)
expect(content).to match(/my_script:zoo\s+# zoo around/m)
end

it "provides no namespace if $thor_runner is false" do
begin
$thor_runner = false
content = capture(:stdout) { MyScript.start(%w(help)) }
expect(content).to match(/thor zoo\s+# zoo around/m)
expect(content).to match(/zoo\s+# zoo around/m)
ensure
$thor_runner = true
end
Expand Down Expand Up @@ -441,20 +441,20 @@ def self.exit_on_failure?
expect(stderr.strip).to eq(msg)
end
arity_asserter.call %w(zero_args one), 'ERROR: "thor zero_args" was called with arguments ["one"]
Usage: "thor scripts:arities:zero_args"'
Usage: "scripts:arities:zero_args"'
arity_asserter.call %w(one_arg), 'ERROR: "thor one_arg" was called with no arguments
Usage: "thor scripts:arities:one_arg ARG"'
Usage: "scripts:arities:one_arg ARG"'
arity_asserter.call %w(one_arg one two), 'ERROR: "thor one_arg" was called with arguments ["one", "two"]
Usage: "thor scripts:arities:one_arg ARG"'
Usage: "scripts:arities:one_arg ARG"'
arity_asserter.call %w(one_arg one two), 'ERROR: "thor one_arg" was called with arguments ["one", "two"]
Usage: "thor scripts:arities:one_arg ARG"'
Usage: "scripts:arities:one_arg ARG"'
arity_asserter.call %w(two_args one), 'ERROR: "thor two_args" was called with arguments ["one"]
Usage: "thor scripts:arities:two_args ARG1 ARG2"'
Usage: "scripts:arities:two_args ARG1 ARG2"'
arity_asserter.call %w(optional_arg one two), 'ERROR: "thor optional_arg" was called with arguments ["one", "two"]
Usage: "thor scripts:arities:optional_arg [ARG]"'
Usage: "scripts:arities:optional_arg [ARG]"'
arity_asserter.call %w(multiple_usages), 'ERROR: "thor multiple_usages" was called with no arguments
Usage: "thor scripts:arities:multiple_usages ARG --foo"
"thor scripts:arities:multiple_usages ARG --bar"'
Usage: "scripts:arities:multiple_usages ARG --foo"
"scripts:arities:multiple_usages ARG --bar"'
end

it "raises an error if the invoked command does not exist" do
Expand Down Expand Up @@ -556,7 +556,7 @@ def shell
it "provides full help info when talking about a specific command" do
expect(capture(:stdout) { MyScript.command_help(shell, "foo") }).to eq(<<-END)
Usage:
thor my_script:foo BAR
my_script:foo BAR

Options:
[--force] # Force to do some fooing
Expand All @@ -570,8 +570,8 @@ def shell
it "provides full help info when talking about a specific command with multiple usages" do
expect(capture(:stdout) { MyScript.command_help(shell, "baz") }).to eq(<<-END)
Usage:
thor my_script:baz THING
thor my_script:baz --all
my_script:baz THING
my_script:baz --all

Options:
[--all=ALL] # Do bazing for all the things
Expand All @@ -587,13 +587,13 @@ def shell
end

it "normalizes names before claiming they don't exist" do
expect(capture(:stdout) { MyScript.command_help(shell, "name-with-dashes") }).to match(/thor my_script:name-with-dashes/)
expect(capture(:stdout) { MyScript.command_help(shell, "name-with-dashes") }).to match(/my_script:name-with-dashes/)
end

it "uses the long description if it exists" do
expect(capture(:stdout) { MyScript.command_help(shell, "long_description") }).to eq(<<-HELP)
Usage:
thor my_script:long_description
my_script:long_description

Description:
This is a really really really long description. Here you go. So very long.
Expand Down