Sha256: 94148768bb524a7d708c525ec1782e5567d8211fd1151a87263421005ce9d45e

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'

describe LinuxAdmin::Service do
  before(:each) do
    # stub distro.local to return test distro for command lookup
    LinuxAdmin::Distro.stub(:local).
                       and_return(LinuxAdmin::Distros::Test.new)

    @service = LinuxAdmin::Service.new 'foo'
  end

  describe "#running?" do
    it "checks service" do
      @service.should_receive(:run).
         with(@service.cmd(:service),
              :params => { nil => ['foo', 'status']},
              :return_exitstatus => true)
      @service.running?
    end

    context "service is running" do
      it "returns true" do
        @service = LinuxAdmin::Service.new :id => :foo
        @service.should_receive(:run).and_return(0)
        @service.should be_running
     end
    end

    context "service is not running" do
      it "returns false" do
        @service = LinuxAdmin::Service.new :id => :foo
        @service.should_receive(:run).and_return(1)
        @service.should_not be_running
      end
    end
  end

  describe "#enable" do
    it "enables service" do
      @service.should_receive(:run).
         with(@service.cmd(:systemctl),
              :params => { nil => [ 'enable', 'foo.service']})
      @service.enable
    end
  end

  describe "#disable" do
    it "disable service" do
      @service.should_receive(:run).
         with(@service.cmd(:systemctl),
              :params => { nil => [ 'disable', 'foo.service']})
      @service.disable
    end
  end

  describe "#start" do
    it "starts service" do
      @service.should_receive(:run).
         with(@service.cmd(:service),
              :params => { nil => [ 'foo', 'start']})
      @service.start
    end
  end

  describe "#stop" do
    it "stops service" do
      @service.should_receive(:run).
         with(@service.cmd(:service),
              :params => { nil => [ 'foo', 'stop']})
      @service.stop
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linux_admin-0.1.1 spec/service_spec.rb