diff options
Diffstat (limited to 'spec/ruby/core/kernel/system_spec.rb')
| -rw-r--r-- | spec/ruby/core/kernel/system_spec.rb | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/spec/ruby/core/kernel/system_spec.rb b/spec/ruby/core/kernel/system_spec.rb index 6a4ba6283d..9bc03924dd 100644 --- a/spec/ruby/core/kernel/system_spec.rb +++ b/spec/ruby/core/kernel/system_spec.rb @@ -3,17 +3,17 @@ require_relative 'fixtures/classes' describe :kernel_system, shared: true do it "executes the specified command in a subprocess" do - lambda { @object.system("echo a") }.should output_to_fd("a\n") + -> { @object.system("echo a") }.should output_to_fd("a\n") $?.should be_an_instance_of Process::Status - $?.success?.should == true + $?.should.success? end it "returns true when the command exits with a zero exit status" do @object.system(ruby_cmd('exit 0')).should == true $?.should be_an_instance_of Process::Status - $?.success?.should == true + $?.should.success? $?.exitstatus.should == 0 end @@ -21,18 +21,16 @@ describe :kernel_system, shared: true do @object.system(ruby_cmd('exit 1')).should == false $?.should be_an_instance_of Process::Status - $?.success?.should == false + $?.should_not.success? $?.exitstatus.should == 1 end - ruby_version_is "2.6" do - it "raises RuntimeError when `exception: true` is given and the command exits with a non-zero exit status" do - lambda { @object.system(ruby_cmd('exit 1'), exception: true) }.should raise_error(RuntimeError) - end + it "raises RuntimeError when `exception: true` is given and the command exits with a non-zero exit status" do + -> { @object.system(ruby_cmd('exit 1'), exception: true) }.should raise_error(RuntimeError) + end - it "raises Errno::ENOENT when `exception: true` is given and the specified command does not exist" do - lambda { @object.system('feature_14386', exception: true) }.should raise_error(Errno::ENOENT) - end + it "raises Errno::ENOENT when `exception: true` is given and the specified command does not exist" do + -> { @object.system('feature_14386', exception: true) }.should raise_error(Errno::ENOENT) end it "returns nil when command execution fails" do @@ -40,11 +38,11 @@ describe :kernel_system, shared: true do $?.should be_an_instance_of Process::Status $?.pid.should be_kind_of(Integer) - $?.exitstatus.should == 127 + $?.should_not.success? end it "does not write to stderr when command execution fails" do - lambda { @object.system("sad") }.should output_to_fd("", STDERR) + -> { @object.system("sad") }.should output_to_fd("", STDERR) end platform_is_not :windows do @@ -57,12 +55,29 @@ describe :kernel_system, shared: true do end it "executes with `sh` if the command contains shell characters" do - lambda { @object.system("echo $0") }.should output_to_fd("sh\n") + -> { @object.system("echo $0") }.should output_to_fd("sh\n") end it "ignores SHELL env var and always uses `sh`" do ENV['SHELL'] = "/bin/fakeshell" - lambda { @object.system("echo $0") }.should output_to_fd("sh\n") + -> { @object.system("echo $0") }.should output_to_fd("sh\n") + end + end + + platform_is_not :windows do + before :each do + require 'tmpdir' + @shell_command = File.join(Dir.mktmpdir, "noshebang.cmd") + File.write(@shell_command, %[echo "$PATH"\n], perm: 0o700) + end + + after :each do + File.unlink(@shell_command) + Dir.rmdir(File.dirname(@shell_command)) + end + + it "executes with `sh` if the command is executable but not binary and there is no shebang" do + -> { @object.system(@shell_command) }.should output_to_fd(ENV['PATH'] + "\n") end end @@ -79,19 +94,19 @@ describe :kernel_system, shared: true do end it "expands shell variables when given a single string argument" do - lambda { @object.system("echo #{@shell_var}") }.should output_to_fd("foo\n") + -> { @object.system("echo #{@shell_var}") }.should output_to_fd("foo\n") end platform_is_not :windows do it "does not expand shell variables when given multiples arguments" do - lambda { @object.system("echo", @shell_var) }.should output_to_fd("#{@shell_var}\n") + -> { @object.system("echo", @shell_var) }.should output_to_fd("#{@shell_var}\n") end end platform_is :windows do it "does expand shell variables when given multiples arguments" do # See https://bugs.ruby-lang.org/issues/12231 - lambda { @object.system("echo", @shell_var) }.should output_to_fd("foo\n") + -> { @object.system("echo", @shell_var) }.should output_to_fd("foo\n") end end |
