Skip to content

Commit a2293e0

Browse files
committed
Convert message to string
Before trying to check for a trailing newline, and add a test
1 parent 21f91d4 commit a2293e0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/thor/shell/basic.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def ask(statement, *args)
7777
# say("I know you knew that.")
7878
#
7979
def say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/))
80-
buffer = prepare_message(message.to_s, *color)
81-
buffer << "\n" if force_new_line && !message.end_with?("\n")
80+
buffer = prepare_message(message, *color)
81+
buffer << "\n" if force_new_line && !message.to_s.end_with?("\n")
8282

8383
stdout.print(buffer)
8484
stdout.flush

spec/shell/basic_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ def shell
119119
expect($stdout).to receive(:print).with("Running...")
120120
shell.say("Running...", nil, false)
121121
end
122+
123+
it "coerces everything to a string before printing" do
124+
expect($stdout).to receive(:print).with("this_is_not_a_string\n")
125+
shell.say(:this_is_not_a_string, nil, true)
126+
end
122127
end
123128

124129
describe "#say_status" do

0 commit comments

Comments
 (0)