-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use package name as basename for Thor classes (#223)
- Loading branch information
Showing
3 changed files
with
57 additions
and
19 deletions.
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
class Thor | ||
# Fix for https://github.com/erikhuda/thor/issues/398 | ||
# Copied from https://github.com/rails/thor/issues/398#issuecomment-622988390 | ||
module Shell | ||
class Basic | ||
def print_wrapped(message, options = {}) | ||
indent = (options[:indent] || 0).to_i | ||
if indent.zero? | ||
stdout.puts(message) | ||
else | ||
message.each_line do |message_line| | ||
stdout.print(" " * indent) | ||
stdout.puts(message_line.chomp) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
# Fix for https://github.com/rails/thor/issues/742 | ||
def self.basename | ||
@package_name || super | ||
end | ||
end |
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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require "thor" | ||
require "patches/thor" | ||
|
||
describe Thor do | ||
describe ".basename" do | ||
subject(:basename) { klass.send(:basename) } | ||
|
||
context "when class has defined package name" do | ||
let(:klass) do | ||
Class.new(described_class) do | ||
package_name "test_package_name" | ||
end | ||
end | ||
|
||
it "returns package name" do | ||
expect(basename).to eq("test_package_name") | ||
end | ||
end | ||
|
||
context "when class doesn't have defined package name" do | ||
let(:klass) { Class.new(described_class) } | ||
|
||
it "returns basename of program invoking the class" do | ||
expect(basename).to eq("rspec") | ||
end | ||
end | ||
end | ||
end |