Skip to content

Commit

Permalink
Merge pull request #719 from sergio-bobillier/master
Browse files Browse the repository at this point in the history
馃寛 Fixes a bug in the calculation of the print_wrapped method
  • Loading branch information
rafaelfranca committed Mar 13, 2020
2 parents 0e5efb8 + 46075de commit 34df888
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/thor/shell/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ def print_wrapped(message, options = {})
paras = message.split("\n\n")

paras.map! do |unwrapped|
counter = 0
unwrapped.split(" ").inject do |memo, word|
words = unwrapped.split(" ")
counter = words.first.length
words.inject do |memo, word|
word = word.gsub(/\n\005/, "\n").gsub(/\005/, "\n")
counter = 0 if word.include? "\n"
if (counter + word.length + 1) < width
Expand Down
40 changes: 40 additions & 0 deletions spec/shell/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,46 @@ def shell
end
end

describe "#print_wrapped" do
let(:message) do
"Creates a back-up of the given folder by compressing it in a .tar.gz\n"\
"file and then uploading it to the configured Amazon S3 Bucket.\n\n"\
"It does not verify the integrity of the generated back-up."
end

before do
allow(ENV).to receive(:[]).with("THOR_COLUMNS").and_return(80)
end

context "without indentation" do
subject(:wrap_text) { described_class.new.print_wrapped(message) }

let(:expected_output) do
"Creates a back-up of the given folder by compressing it in a .tar.gz file and\n"\
"then uploading it to the configured Amazon S3 Bucket.\n\n"\
"It does not verify the integrity of the generated back-up.\n"
end

it "properly wraps the text around the 80th column" do
expect { wrap_text }.to output(expected_output).to_stdout
end
end

context "with indentation" do
subject(:wrap_text) { described_class.new.print_wrapped(message, :indent => 4) }

let(:expected_output) do
" Creates a back-up of the given folder by compressing it in a .tar.gz file\n"\
" and then uploading it to the configured Amazon S3 Bucket.\n\n"\
" It does not verify the integrity of the generated back-up.\n"
end

it "properly wraps the text around the 80th column" do
expect { wrap_text }.to output(expected_output).to_stdout
end
end
end

describe "#say_status" do
it "prints a message to the user with status" do
expect($stdout).to receive(:print).with(" create ~/.thor/command.thor\n")
Expand Down

0 comments on commit 34df888

Please sign in to comment.