Sha256: 2e04c3f75d22f2a73c3b75660d891f36ffad1eede9eed0d6924798de0aeab824

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

describe LinuxAdmin::Service do
  context ".service_type" do
    it "on systemctl systems" do
      stub_to_service_type(:systemd_service)
      expect(described_class.service_type).to eq(LinuxAdmin::SystemdService)
    end

    it "on sysv systems" do
      stub_to_service_type(:sys_v_init_service)
      expect(described_class.service_type).to eq(LinuxAdmin::SysVInitService)
    end

    it "should memoize results" do
      expect(described_class).to receive(:service_type_uncached).once.and_return("anything_non_nil")
      described_class.service_type
      described_class.service_type
    end

    it "with reload should refresh results" do
      expect(described_class).to receive(:service_type_uncached).twice.and_return("anything_non_nil")
      described_class.service_type
      described_class.service_type(true)
    end
  end

  context ".new" do
    it "on systemctl systems" do
      stub_to_service_type(:systemd_service)
      expect(described_class.new("xxx")).to be_kind_of(LinuxAdmin::SystemdService)
    end

    it "on sysv systems" do
      stub_to_service_type(:sys_v_init_service)
      expect(described_class.new("xxx")).to be_kind_of(LinuxAdmin::SysVInitService)
    end
  end

  it "#id / #id=" do
    s = described_class.new("xxx")
    expect(s.id).to eq("xxx")

    s.id = "yyy"
    expect(s.id).to eq("yyy")
    expect(s.name).to eq("yyy")

    s.name = "zzz"
    expect(s.id).to eq("zzz")
    expect(s.name).to eq("zzz")
  end

  def stub_to_service_type(system)
    allow(LinuxAdmin::Service).to receive(:cmd?).with(:systemctl).and_return(system == :systemd_service)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
linux_admin-0.14.0 spec/service_spec.rb
linux_admin-0.13.0 spec/service_spec.rb
linux_admin-0.12.1 spec/service_spec.rb
linux_admin-0.12.0 spec/service_spec.rb
linux_admin-0.11.1 spec/service_spec.rb
linux_admin-0.11.0 spec/service_spec.rb