Skip to content

Commit df6663e

Browse files
authored
Merge pull request #729 from jonathanhefner/say-obey-quiet
Obey mute and options[:quiet] in Shell#say
2 parents 34df888 + 80fd49c commit df6663e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/thor/shell/basic.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def ask(statement, *args)
9494
# say("I know you knew that.")
9595
#
9696
def say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/))
97+
return if quiet?
98+
9799
buffer = prepare_message(message, *color)
98100
buffer << "\n" if force_new_line && !message.to_s.end_with?("\n")
99101

spec/shell/basic_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ def shell
173173
expect($stdout).to receive(:print).with("this_is_not_a_string\n")
174174
shell.say(:this_is_not_a_string, nil, true)
175175
end
176+
177+
it "does not print a message if muted" do
178+
expect($stdout).not_to receive(:print)
179+
shell.mute do
180+
shell.say("Running...")
181+
end
182+
end
183+
184+
it "does not print a message if base is set to quiet" do
185+
shell.base = MyCounter.new [1, 2]
186+
expect(shell.base).to receive(:options).and_return(:quiet => true)
187+
188+
expect($stdout).not_to receive(:print)
189+
shell.say("Running...")
190+
end
176191
end
177192

178193
describe "#print_wrapped" do

0 commit comments

Comments
 (0)