Skip to content

Commit 665b4d3

Browse files
committed
Use #inspect to show the exitstatus even if it is nil
1 parent 837e295 commit 665b4d3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/mspec/helpers/ruby_exe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def ruby_exe(code = :not_given, opts = {})
144144

145145
last_status = Process.last_status
146146
if last_status.exitstatus != expected_exit_status
147-
raise "Expected exit status is #{expected_exit_status} but actual is #{last_status.exitstatus}. Command ruby_exe(#{command})"
147+
raise "Expected exit status is #{expected_exit_status.inspect} but actual is #{last_status.exitstatus.inspect} for command ruby_exe(#{command.inspect})"
148148
end
149149

150150
output

spec/helpers/ruby_exe_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,19 @@ class RubyExeSpecs
181181

182182
expect {
183183
@script.ruby_exe(code, options)
184-
}.to raise_error(%r{Expected exit status is 0 but actual is 4. Command ruby_exe\(.+\)})
184+
}.to raise_error(%r{Expected exit status is 0 but actual is 4 for command ruby_exe\(.+\)})
185+
end
186+
187+
it "shows in the exception message if exitstatus is nil (e.g., signal)" do
188+
code = "code"
189+
options = {}
190+
191+
status_failed = double(Process::Status, exitstatus: nil)
192+
allow(Process).to receive(:last_status).and_return(status_failed)
193+
194+
expect {
195+
@script.ruby_exe(code, options)
196+
}.to raise_error(%r{Expected exit status is 0 but actual is nil for command ruby_exe\(.+\)})
185197
end
186198

187199
describe "with :dir option" do
@@ -231,7 +243,7 @@ class RubyExeSpecs
231243
it "raises exception when command ends with not expected status" do
232244
expect {
233245
@script.ruby_exe("path", exit_status: 1)
234-
}.to raise_error(%r{Expected exit status is 1 but actual is 4. Command ruby_exe\(.+\)})
246+
}.to raise_error(%r{Expected exit status is 1 but actual is 4 for command ruby_exe\(.+\)})
235247
end
236248

237249
it "does not raise exception when command ends with expected status" do

0 commit comments

Comments
 (0)