Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/thor/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,16 @@ def run(command, config = {})

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

unless options[:pretend]
config[:capture] ? `#{command}` : system(command.to_s)
return if options[:pretend]

result = config[:capture] ? `#{command}` : system(command.to_s)

if config[:abort_on_failure]
success = config[:capture] ? $?.success? : result
abort unless success
end

result
end

# Executes a ruby script (taking into account WIN32 platform quirks).
Expand Down
18 changes: 18 additions & 0 deletions spec/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,24 @@ def file
end
end

describe "aborting on failure" do
it "aborts when abort_on_failure is given and command fails" do
expect { action :run, "false", :abort_on_failure => true }.to raise_error(SystemExit)
end

it "suceeds when abort_on_failure is given and command succeeds" do
expect { action :run, "true", :abort_on_failure => true }.not_to raise_error
end

it "aborts when abort_on_failure is given, capture is given and command fails" do
expect { action :run, "false", :abort_on_failure => true, :capture => true }.to raise_error(SystemExit)
end

it "suceeds when abort_on_failure is given and command succeeds" do
expect { action :run, "true", :abort_on_failure => true, :capture => true }.not_to raise_error
end
end

describe "when pretending" do
it "doesn't execute the command" do
runner = MyCounter.new([1], %w(--pretend))
Expand Down
6 changes: 0 additions & 6 deletions spec/fixtures/bundle/execute.rb

This file was deleted.

1 change: 0 additions & 1 deletion spec/fixtures/bundle/main.thor

This file was deleted.