Sha256: 9951d41a0754bbd31d6c69bb602b7fec9e07a85566656cc32f5e0a083b5cd9e5

Contents?: true

Size: 1.57 KB

Versions: 16

Compression:

Stored size: 1.57 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::Common).to receive(:cmd?).with(:systemctl).and_return(system == :systemd_service)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
linux_admin-1.2.4 spec/service_spec.rb
linux_admin-1.2.3 spec/service_spec.rb
linux_admin-1.2.2 spec/service_spec.rb
linux_admin-1.2.1 spec/service_spec.rb
linux_admin-1.0.1 spec/service_spec.rb
linux_admin-1.2.0 spec/service_spec.rb
linux_admin-1.1.0 spec/service_spec.rb
linux_admin-1.0.0 spec/service_spec.rb
linux_admin-0.20.2 spec/service_spec.rb
linux_admin-0.20.1 spec/service_spec.rb
linux_admin-0.20.0 spec/service_spec.rb
linux_admin-0.19.0 spec/service_spec.rb
linux_admin-0.18.0 spec/service_spec.rb
linux_admin-0.17.0 spec/service_spec.rb
linux_admin-0.16.0 spec/service_spec.rb
linux_admin-0.15.0 spec/service_spec.rb