diff --git a/lib/foreman/cli.rb b/lib/foreman/cli.rb index f64940a..ed67df8 100644 --- a/lib/foreman/cli.rb +++ b/lib/foreman/cli.rb @@ -86,6 +86,7 @@ class Foreman::CLI < Thor end end Process.wait(pid) + exit $?.exitstatus end desc "version", "Display Foreman gem version" diff --git a/spec/foreman/cli_spec.rb b/spec/foreman/cli_spec.rb index 6246b41..595da0e 100644 --- a/spec/foreman/cli_spec.rb +++ b/spec/foreman/cli_spec.rb @@ -72,6 +72,11 @@ describe "Foreman::CLI", :fakefs do it "includes the environment" do forked_foreman("run #{resource_path("bin/env FOO")} -e #{resource_path(".env")}").should == "bar\n" end + + it "exits with the same exit code as the command" do + fork_and_get_exitstatus("run echo 1").should == 0 + fork_and_get_exitstatus("run date 'invalid_date'").should == 1 + end end describe "version" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 419ddc9..9c0628c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -58,6 +58,12 @@ def fork_and_capture(&blk) end end +def fork_and_get_exitstatus(args) + pid = Process.spawn("bundle exec bin/foreman #{args}", :out => "/dev/null", :err => "/dev/null") + Process.wait(pid) + $?.exitstatus +end + def mock_exit(&block) block.should raise_error(SystemExit) end