Sha256: c816bb4bf383ce57053ba8007d8f5b8c78912d74af49672adf9886e7d77fe935

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

require 'spec_helper'

describe ConfigCurator::PackageLookup do

  subject(:lookup) { ConfigCurator::PackageLookup.new }

  describe ".new" do

    it "sets the package tool" do
      lookup = ConfigCurator::PackageLookup.new tool: :dpkg
      expect(lookup.tool).to eq :dpkg
    end
  end

  describe "#tools" do

    it "uses the default list of tools" do
      expect(lookup.tools).to eq ConfigCurator::PackageLookup::TOOLS
    end
  end

  describe "#tool" do

    context "when tool is set" do

      it "returns the tool" do
        lookup.tool = :pacman
        expect(lookup.tool).to eq :pacman
      end
    end

    context "when tool not set" do

      it "returns the first avaible tool" do
        allow(lookup).to receive(:command?).with(:dpkg).and_return(true)
        lookup.tools = %i(dpkg pacman)
        expect(lookup.tool).to eq :dpkg
      end
    end
  end

  describe "#installed?" do

    it "calls the corresponding private lookup method" do
      lookup.tool = :dpkg
      expect(lookup).to receive(:dpkg).with('rsync')
      lookup.installed? 'rsync'
    end

    context "when no package tool found" do

      it "fails" do
        lookup.tools = %i(dpkg)
        allow(lookup).to receive(:command?).with(:dpkg).and_return(false)
        expect { lookup.installed? 'rsync' }.to raise_error ConfigCurator::PackageLookup::LookupFailed
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
config_curator-0.0.2 spec/package_lookup_spec.rb
config_curator-0.0.1 spec/package_lookup_spec.rb