summaryrefslogtreecommitdiff
path: root/spec/mspec/spec
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2021-06-02 14:34:01 +0200
committerBenoit Daloze <eregontp@gmail.com>2021-06-02 14:34:01 +0200
commita4fbc7e2884ba694278adea3b32ddb8c2ac10efe (patch)
tree3062a3c0bf1e644ff6d9f4ff9ecec6299f12f025 /spec/mspec/spec
parent2048dfc5d37eecb6f1ae18e9d1770a71b46a40b9 (diff)
Update to ruby/mspec@0091e8a
Diffstat (limited to 'spec/mspec/spec')
-rw-r--r--spec/mspec/spec/helpers/ruby_exe_spec.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/mspec/spec/helpers/ruby_exe_spec.rb b/spec/mspec/spec/helpers/ruby_exe_spec.rb
index 32b3818853..8f14f63a32 100644
--- a/spec/mspec/spec/helpers/ruby_exe_spec.rb
+++ b/spec/mspec/spec/helpers/ruby_exe_spec.rb
@@ -146,6 +146,18 @@ RSpec.describe Object, "#ruby_exe" do
@script = RubyExeSpecs.new
allow(@script).to receive(:`)
+
+ status_successful = double(Process::Status, exitstatus: 0)
+ allow(Process).to receive(:last_status).and_return(status_successful)
+ end
+
+ it "returns command STDOUT when given command" do
+ code = "code"
+ options = {}
+ output = "output"
+ allow(@script).to receive(:`).and_return(output)
+
+ expect(@script.ruby_exe(code, options)).to eq output
end
it "returns an Array containing the interpreter executable and flags when given no arguments" do
@@ -160,6 +172,30 @@ RSpec.describe Object, "#ruby_exe" do
@script.ruby_exe(code, options)
end
+ it "raises exception when command exit status is not successful" do
+ code = "code"
+ options = {}
+
+ status_failed = double(Process::Status, exitstatus: 4)
+ allow(Process).to receive(:last_status).and_return(status_failed)
+
+ expect {
+ @script.ruby_exe(code, options)
+ }.to raise_error(%r{Expected exit status is 0 but actual is 4 for command ruby_exe\(.+\)})
+ end
+
+ it "shows in the exception message if exitstatus is nil (e.g., signal)" do
+ code = "code"
+ options = {}
+
+ status_failed = double(Process::Status, exitstatus: nil)
+ allow(Process).to receive(:last_status).and_return(status_failed)
+
+ expect {
+ @script.ruby_exe(code, options)
+ }.to raise_error(%r{Expected exit status is 0 but actual is nil for command ruby_exe\(.+\)})
+ end
+
describe "with :dir option" do
it "is deprecated" do
expect {
@@ -197,4 +233,24 @@ RSpec.describe Object, "#ruby_exe" do
end.to raise_error(Exception)
end
end
+
+ describe "with :exit_status option" do
+ before do
+ status_failed = double(Process::Status, exitstatus: 4)
+ allow(Process).to receive(:last_status).and_return(status_failed)
+ end
+
+ it "raises exception when command ends with not expected status" do
+ expect {
+ @script.ruby_exe("path", exit_status: 1)
+ }.to raise_error(%r{Expected exit status is 1 but actual is 4 for command ruby_exe\(.+\)})
+ end
+
+ it "does not raise exception when command ends with expected status" do
+ output = "output"
+ allow(@script).to receive(:`).and_return(output)
+
+ expect(@script.ruby_exe("path", exit_status: 4)).to eq output
+ end
+ end
end