@@ -909,43 +909,44 @@ def expect_cwd_to_be(cwd)
909909
910910 describe "#execpipe" do
911911 it "should execute a string as a string" do
912- expect ( Puppet :: Util :: Execution ) . to receive ( :open ) . with ( '| echo hello 2>&1' ) . and_return ( 'hello' )
912+ expect ( IO ) . to receive ( :popen ) . with ( { 'LANG' => 'C' , 'LC_ALL' => 'C' } , 'echo hello' , err : :out ) . and_return ( 'hello' )
913913 expect ( Puppet ::Util ::Execution ) . to receive ( :exitstatus ) . and_return ( 0 )
914914 expect ( Puppet ::Util ::Execution . execpipe ( 'echo hello' ) ) . to eq ( 'hello' )
915915 end
916916
917917 it "should print meaningful debug message for string argument" do
918918 Puppet [ :log_level ] = 'debug'
919- expect ( Puppet ) . to receive ( :send_log ) . with ( :debug , " Executing ' echo hello'" )
920- expect ( Puppet :: Util :: Execution ) . to receive ( :open ) . with ( '| echo hello 2>&1' ) . and_return ( 'hello' )
919+ expect ( Puppet ) . to receive ( :send_log ) . with ( :debug , ' Executing " echo hello"' )
920+ expect ( IO ) . to receive ( :popen ) . with ( { 'LANG' => 'C' , 'LC_ALL' => 'C' } , 'echo hello' , err : :out ) . and_return ( 'hello' )
921921 expect ( Puppet ::Util ::Execution ) . to receive ( :exitstatus ) . and_return ( 0 )
922922 Puppet ::Util ::Execution . execpipe ( 'echo hello' )
923923 end
924924
925925 it "should print meaningful debug message for array argument" do
926926 Puppet [ :log_level ] = 'debug'
927- expect ( Puppet ) . to receive ( :send_log ) . with ( :debug , " Executing ' echo hello'" )
928- expect ( Puppet :: Util :: Execution ) . to receive ( :open ) . with ( '| echo hello 2>&1' ) . and_return ( 'hello' )
927+ expect ( Puppet ) . to receive ( :send_log ) . with ( :debug , ' Executing [" echo", " hello"]' )
928+ expect ( IO ) . to receive ( :popen ) . with ( { 'LANG' => 'C' , 'LC_ALL' => 'C' } , [ 'echo' , 'hello' ] , err : :out ) . and_return ( 'hello' )
929929 expect ( Puppet ::Util ::Execution ) . to receive ( :exitstatus ) . and_return ( 0 )
930930 Puppet ::Util ::Execution . execpipe ( [ 'echo' , 'hello' ] )
931931 end
932932
933- it "should execute an array by pasting together with spaces " do
934- expect ( Puppet :: Util :: Execution ) . to receive ( :open ) . with ( '| echo hello 2>&1' ) . and_return ( 'hello' )
933+ it "should execute an array" do
934+ expect ( IO ) . to receive ( :popen ) . with ( { 'LANG' => 'C' , 'LC_ALL' => 'C' } , [ 'echo' , 'hello' ] , err : :out ) . and_return ( 'hello' )
935935 expect ( Puppet ::Util ::Execution ) . to receive ( :exitstatus ) . and_return ( 0 )
936936 expect ( Puppet ::Util ::Execution . execpipe ( [ 'echo' , 'hello' ] ) ) . to eq ( 'hello' )
937937 end
938938
939939 it "should fail if asked to fail, and the child does" do
940- allow ( Puppet :: Util :: Execution ) . to receive ( :open ) . with ( '| echo hello 2>&1' ) . and_return ( 'error message' )
940+ expect ( IO ) . to receive ( :popen ) . with ( { 'LANG' => 'C' , 'LC_ALL' => 'C' } , [ 'echo' , 'hello' ] , err : :out ) . and_return ( 'error message' )
941941 expect ( Puppet ::Util ::Execution ) . to receive ( :exitstatus ) . and_return ( 1 )
942942 expect {
943943 Puppet ::Util ::Execution . execpipe ( 'echo hello' )
944944 } . to raise_error Puppet ::ExecutionFailure , /error message/
945945 end
946946
947947 it "should not fail if asked not to fail, and the child does" do
948- allow ( Puppet ::Util ::Execution ) . to receive ( :open ) . and_return ( 'error message' )
948+ expect ( IO ) . to receive ( :popen ) . with ( { 'LANG' => 'C' , 'LC_ALL' => 'C' } , 'echo hello' , err : :out ) . and_return ( 'error message' )
949+ expect ( Puppet ::Util ::Execution ) . not_to receive ( :exitstatus )
949950 expect ( Puppet ::Util ::Execution . execpipe ( 'echo hello' , false ) ) . to eq ( 'error message' )
950951 end
951952 end
0 commit comments