spec/common_spec.rb in linux_admin-0.2.1 vs spec/common_spec.rb in linux_admin-0.2.2

- old
+ new

@@ -35,11 +35,11 @@ subject.cmd(:sh).should == '/bin/sh' end end shared_examples_for "run" do - context "with params" do + context "paramater and command handling" do before do subject.stub(:exitstatus => 0) end it "sanitizes crazy params" do @@ -47,13 +47,25 @@ subject.send(run_method, "true", :params => modified_params) end it "sanitizes fixnum array params" do subject.should_receive(:launch).once.with("true 1", {}) - subject.send(run_method, "true", :params => { nil => [1]}) + subject.send(run_method, "true", :params => {nil => [1]}) end + it "sanitizes Pathname option value" do + require 'pathname' + subject.should_receive(:launch).once.with("true /usr/bin/ruby", {}) + subject.send(run_method, "true", :params => {nil => [Pathname.new("/usr/bin/ruby")]}) + end + + it "sanitizes Pathname option" do + require 'pathname' + subject.should_receive(:launch).once.with("true /usr/bin/ruby", {}) + subject.send(run_method, "true", :params => {Pathname.new("/usr/bin/ruby") => nil}) + end + it "as empty hash" do subject.should_receive(:launch).once.with("true", {}) subject.send(run_method, "true", :params => {}) end @@ -67,10 +79,20 @@ subject.stub(:launch) subject.send(run_method, "true", :params => params) expect(orig_params).to eq(params) end + it "Pathname command" do + subject.should_receive(:launch).once.with("/usr/bin/ruby", {}) + subject.send(run_method, Pathname.new("/usr/bin/ruby"), {}) + end + + it "Pathname command with params" do + subject.should_receive(:launch).once.with("/usr/bin/ruby -v", {}) + subject.send(run_method, Pathname.new("/usr/bin/ruby"), :params => {"-v" => nil}) + end + it "supports spawn's chdir option" do subject.should_receive(:launch).once.with("true", {:chdir => ".."}) subject.send(run_method, "true", :chdir => "..") end end @@ -98,10 +120,10 @@ expect {subject.send(run_method, "false")}.to_not raise_error end end it "command bad" do - expect {subject.send(run_method, "XXXXX")}.to raise_error(Errno::ENOENT) + expect {subject.send(run_method, "XXXXX --user=bob")}.to raise_error(LinuxAdmin::NoSuchFileError, "No such file or directory - XXXXX") end context "#exit_status" do it "command ok exit ok" do expect(subject.send(run_method, "true").exit_status).to eq(0)