diff --git a/lib/rubyshell/error.rb b/lib/rubyshell/error.rb index 1ae8128..5f6120e 100644 --- a/lib/rubyshell/error.rb +++ b/lib/rubyshell/error.rb @@ -2,6 +2,8 @@ module RubyShell class CommandError < StandardError + attr_reader :command, :status + def initialize(command:, stdout: "", stderr: "", status: "", message: nil) @command = command @stdout = stdout diff --git a/spec/command_error_spec.rb b/spec/command_error_spec.rb new file mode 100755 index 0000000..a32f033 --- /dev/null +++ b/spec/command_error_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +RSpec.describe RubyShell::CommandError do + let(:cmd) { "false" } + let(:error_instance) do + sh.send(cmd.to_sym) + raise "sh.#{cmd} did not raise RubyShell::CommandError as expected" + rescue described_class => e + e + end + + describe "Error object API" do + it "stores the command, stderr, and status" do + expect(error_instance.command).to eq("false") + expect(error_instance.status.to_s).to match(/exit 1/) + end + end +end