Skip to content

Commit a42496f

Browse files
committed
Fix commands running even with pretend enabled
1 parent b91a08e commit a42496f

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

lib/thor/actions.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ def run(command, config = {})
251251

252252
say_status :run, desc, config.fetch(:verbose, true)
253253

254-
!options[:pretend] && config[:capture] ? `#{command}` : system(command.to_s)
254+
unless options[:pretend]
255+
config[:capture] ? `#{command}` : system(command.to_s)
256+
end
255257
end
256258

257259
# Executes a ruby script (taking into account WIN32 platform quirks).

spec/actions_spec.rb

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -253,25 +253,35 @@ def file
253253
end
254254

255255
describe "#run" do
256-
before do
257-
expect(runner).to receive(:system).with("ls")
258-
end
256+
describe "when not pretending" do
257+
before do
258+
expect(runner).to receive(:system).with("ls")
259+
end
259260

260-
it "executes the command given" do
261-
action :run, "ls"
262-
end
261+
it "executes the command given" do
262+
action :run, "ls"
263+
end
263264

264-
it "logs status" do
265-
expect(action(:run, "ls")).to eq(" run ls from \".\"\n")
266-
end
265+
it "logs status" do
266+
expect(action(:run, "ls")).to eq(" run ls from \".\"\n")
267+
end
267268

268-
it "does not log status if required" do
269-
expect(action(:run, "ls", :verbose => false)).to be_empty
269+
it "does not log status if required" do
270+
expect(action(:run, "ls", :verbose => false)).to be_empty
271+
end
272+
273+
it "accepts a color as status" do
274+
expect(runner.shell).to receive(:say_status).with(:run, 'ls from "."', :yellow)
275+
action :run, "ls", :verbose => :yellow
276+
end
270277
end
271278

272-
it "accepts a color as status" do
273-
expect(runner.shell).to receive(:say_status).with(:run, 'ls from "."', :yellow)
274-
action :run, "ls", :verbose => :yellow
279+
describe "when pretending" do
280+
it "doesn't execute the command" do
281+
runner = MyCounter.new([1], %w(--pretend))
282+
expect(runner).not_to receive(:system)
283+
runner.run("ls", :verbose => false)
284+
end
275285
end
276286
end
277287

0 commit comments

Comments
 (0)