Sha256: a80b56c33d1ff469011ac60384bd06cad8085c6ef07de19a3423f3355361824a

Contents?: true

Size: 1.46 KB

Versions: 11

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

describe LitmusPaper::Dependency::Script do
  describe "#available?" do
    it "is true when the script returns 0" do
      check = LitmusPaper::Dependency::Script.new("true")
      check.should be_available
    end

    it "is false when the script returns 1" do
      check = LitmusPaper::Dependency::Script.new("false")
      check.should_not be_available
    end

    it "is false when the script exceeds the timeout" do
      check = LitmusPaper::Dependency::Script.new("sleep 10", :timeout => 1)
      check.should_not be_available
    end

    it "kills the child process when script check exceeds timeout" do
      check = LitmusPaper::Dependency::Script.new("sleep 50", :timeout => 1)
      check.should_not be_available
      expect { Process.kill(0, check.script_pid) }.to raise_error(Errno::ESRCH)
    end

    it "can handle pipes" do
      check = LitmusPaper::Dependency::Script.new("ls | grep lib")
      check.should be_available

      check = LitmusPaper::Dependency::Script.new("ls | grep missing")
      check.should_not be_available
    end

    it "logs exceptions and returns false" do
      check = LitmusPaper::Dependency::Script.new("command_not_found")
      LitmusPaper.logger.should_receive(:info)
      check.should_not be_available
    end
  end

  describe "to_s" do
    it "returns the command" do
      check = LitmusPaper::Dependency::Script.new("sleep 10")
      check.to_s.should == "Dependency::Script(sleep 10)"
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
litmus_paper-0.9.6 spec/litmus_paper/dependency/script_spec.rb
litmus_paper-0.9.5 spec/litmus_paper/dependency/script_spec.rb
litmus_paper-0.9.4 spec/litmus_paper/dependency/script_spec.rb
litmus_paper-0.9.3 spec/litmus_paper/dependency/script_spec.rb
litmus_paper-0.9.2 spec/litmus_paper/dependency/script_spec.rb
litmus_paper-0.9.1 spec/litmus_paper/dependency/script_spec.rb
litmus_paper-0.9.0 spec/litmus_paper/dependency/script_spec.rb
litmus_paper-0.8.9 spec/litmus_paper/dependency/script_spec.rb
litmus_paper-0.8.8 spec/litmus_paper/dependency/script_spec.rb
litmus_paper-0.8.7 spec/litmus_paper/dependency/script_spec.rb
litmus_paper-0.8.6 spec/litmus_paper/dependency/script_spec.rb